diff --git a/packages/plugin-github/src/events.ts b/packages/plugin-github/src/events.ts index ba351df1b5..a7cfc2e1f2 100644 --- a/packages/plugin-github/src/events.ts +++ b/packages/plugin-github/src/events.ts @@ -16,6 +16,8 @@ interface CommentEventConfig { export interface EventConfig { commitComment?: boolean | CommentEventConfig + create?: boolean + delete?: boolean fork?: boolean issueComment?: boolean | CommentEventConfig issues?: boolean | { @@ -70,7 +72,6 @@ export const defaultEvents: EventConfig = { commitComment: { created: true, }, - fork: true, issueComment: { created: true, }, @@ -88,7 +89,6 @@ export const defaultEvents: EventConfig = { pullRequestReviewComment: { created: true, }, - push: true, star: { created: true, }, @@ -158,6 +158,19 @@ export function addListeners(on: (event: T, handler: Eve }] }) + function onReference(event: T) { + on(event, ({ repository, ref, ref_type, sender }) => { + const ref_name = `${repository.full_name}${ref_type === 'tag' ? '@' : ':'}${ref}` + return { + message: `${sender.login} ${event}d ${ref_type} ${ref_name}`, + } + }) + } + + onReference('create') + + onReference('delete') + on('fork', ({ repository, sender, forkee }) => { const { full_name, forks_count } = repository return { @@ -268,18 +281,11 @@ export function addListeners(on: (event: T, handler: Eve } }) - on('push', ({ compare, pusher, commits, repository, ref, after }) => { + on('push', ({ compare, pusher, commits, repository, ref, before, after }) => { const { full_name } = repository - // do not show pull request merge - if (/^0+$/.test(after)) return - - // use short form for tag releases - if (ref.startsWith('refs/tags')) { - return { - message: `${pusher.name} published tag ${full_name}@${ref.slice(10)}`, - } - } + // do not show branch create / delete + if (/^0+$/.test(before) || /^0+$/.test(after)) return return { message: [ diff --git a/packages/plugin-github/src/index.ts b/packages/plugin-github/src/index.ts index 87c8d54ee5..88a51a329e 100644 --- a/packages/plugin-github/src/index.ts +++ b/packages/plugin-github/src/index.ts @@ -166,17 +166,15 @@ export function apply(ctx: Context, config: Config = {}) { addListeners((event, handler) => { const base = camelize(event.split('.', 1)[0]) - github.on(event, async (callback) => { - const { repository } = callback.payload - + github.on(event, async ({ payload }) => { // step 1: filter repository - const groupIds = config.repos[repository.full_name] + const groupIds = config.repos[payload.repository.full_name] if (!groupIds) return // step 2: filter event const baseConfig = config.events[base] || {} if (baseConfig === false) return - const action = camelize(callback.payload.action) + const action = camelize(payload.action) if (action && baseConfig !== true) { const actionConfig = baseConfig[action] if (actionConfig === false) return @@ -184,7 +182,7 @@ export function apply(ctx: Context, config: Config = {}) { } // step 3: handle event - const result = handler(callback.payload) + const result = handler(payload) if (!result) return // step 4: broadcast message diff --git a/packages/plugin-github/tests/fixtures/create.1.json b/packages/plugin-github/tests/fixtures/create.1.json new file mode 100644 index 0000000000..8c1123e054 --- /dev/null +++ b/packages/plugin-github/tests/fixtures/create.1.json @@ -0,0 +1,141 @@ +{ + "ref": "reply-api", + "ref_type": "branch", + "master_branch": "master", + "description": "QQ bot out of the box", + "pusher_type": "user", + "repository": { + "id": 225572038, + "node_id": "MDEwOlJlcG9zaXRvcnkyMjU1NzIwMzg=", + "name": "koishi", + "full_name": "koishijs/koishi", + "private": false, + "owner": { + "login": "koishijs", + "id": 58179220, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjU4MTc5MjIw", + "avatar_url": "https://avatars3.githubusercontent.com/u/58179220?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/koishijs", + "html_url": "https://github.com/koishijs", + "followers_url": "https://api.github.com/users/koishijs/followers", + "following_url": "https://api.github.com/users/koishijs/following{/other_user}", + "gists_url": "https://api.github.com/users/koishijs/gists{/gist_id}", + "starred_url": "https://api.github.com/users/koishijs/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/koishijs/subscriptions", + "organizations_url": "https://api.github.com/users/koishijs/orgs", + "repos_url": "https://api.github.com/users/koishijs/repos", + "events_url": "https://api.github.com/users/koishijs/events{/privacy}", + "received_events_url": "https://api.github.com/users/koishijs/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/koishijs/koishi", + "description": "QQ bot out of the box", + "fork": false, + "url": "https://api.github.com/repos/koishijs/koishi", + "forks_url": "https://api.github.com/repos/koishijs/koishi/forks", + "keys_url": "https://api.github.com/repos/koishijs/koishi/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/koishijs/koishi/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/koishijs/koishi/teams", + "hooks_url": "https://api.github.com/repos/koishijs/koishi/hooks", + "issue_events_url": "https://api.github.com/repos/koishijs/koishi/issues/events{/number}", + "events_url": "https://api.github.com/repos/koishijs/koishi/events", + "assignees_url": "https://api.github.com/repos/koishijs/koishi/assignees{/user}", + "branches_url": "https://api.github.com/repos/koishijs/koishi/branches{/branch}", + "tags_url": "https://api.github.com/repos/koishijs/koishi/tags", + "blobs_url": "https://api.github.com/repos/koishijs/koishi/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/koishijs/koishi/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/koishijs/koishi/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/koishijs/koishi/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/koishijs/koishi/statuses/{sha}", + "languages_url": "https://api.github.com/repos/koishijs/koishi/languages", + "stargazers_url": "https://api.github.com/repos/koishijs/koishi/stargazers", + "contributors_url": "https://api.github.com/repos/koishijs/koishi/contributors", + "subscribers_url": "https://api.github.com/repos/koishijs/koishi/subscribers", + "subscription_url": "https://api.github.com/repos/koishijs/koishi/subscription", + "commits_url": "https://api.github.com/repos/koishijs/koishi/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/koishijs/koishi/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/koishijs/koishi/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/koishijs/koishi/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/koishijs/koishi/contents/{+path}", + "compare_url": "https://api.github.com/repos/koishijs/koishi/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/koishijs/koishi/merges", + "archive_url": "https://api.github.com/repos/koishijs/koishi/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/koishijs/koishi/downloads", + "issues_url": "https://api.github.com/repos/koishijs/koishi/issues{/number}", + "pulls_url": "https://api.github.com/repos/koishijs/koishi/pulls{/number}", + "milestones_url": "https://api.github.com/repos/koishijs/koishi/milestones{/number}", + "notifications_url": "https://api.github.com/repos/koishijs/koishi/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/koishijs/koishi/labels{/name}", + "releases_url": "https://api.github.com/repos/koishijs/koishi/releases{/id}", + "deployments_url": "https://api.github.com/repos/koishijs/koishi/deployments", + "created_at": "2019-12-03T08:47:29Z", + "updated_at": "2020-10-17T05:26:38Z", + "pushed_at": "2020-10-18T16:20:28Z", + "git_url": "git://github.com/koishijs/koishi.git", + "ssh_url": "git@github.com:koishijs/koishi.git", + "clone_url": "https://github.com/koishijs/koishi.git", + "svn_url": "https://github.com/koishijs/koishi", + "homepage": "https://koishi.js.org", + "size": 2952, + "stargazers_count": 208, + "watchers_count": 208, + "language": "TypeScript", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": false, + "has_pages": false, + "forks_count": 15, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 7, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "forks": 15, + "open_issues": 7, + "watchers": 208, + "default_branch": "master" + }, + "organization": { + "login": "koishijs", + "id": 58179220, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjU4MTc5MjIw", + "url": "https://api.github.com/orgs/koishijs", + "repos_url": "https://api.github.com/orgs/koishijs/repos", + "events_url": "https://api.github.com/orgs/koishijs/events", + "hooks_url": "https://api.github.com/orgs/koishijs/hooks", + "issues_url": "https://api.github.com/orgs/koishijs/issues", + "members_url": "https://api.github.com/orgs/koishijs/members{/member}", + "public_members_url": "https://api.github.com/orgs/koishijs/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/58179220?v=4", + "description": "" + }, + "sender": { + "login": "Shigma", + "id": 33423008, + "node_id": "MDQ6VXNlcjMzNDIzMDA4", + "avatar_url": "https://avatars3.githubusercontent.com/u/33423008?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Shigma", + "html_url": "https://github.com/Shigma", + "followers_url": "https://api.github.com/users/Shigma/followers", + "following_url": "https://api.github.com/users/Shigma/following{/other_user}", + "gists_url": "https://api.github.com/users/Shigma/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Shigma/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Shigma/subscriptions", + "organizations_url": "https://api.github.com/users/Shigma/orgs", + "repos_url": "https://api.github.com/users/Shigma/repos", + "events_url": "https://api.github.com/users/Shigma/events{/privacy}", + "received_events_url": "https://api.github.com/users/Shigma/received_events", + "type": "User", + "site_admin": false + } +} \ No newline at end of file diff --git a/packages/plugin-github/tests/fixtures/create.2.json b/packages/plugin-github/tests/fixtures/create.2.json new file mode 100644 index 0000000000..04a5360436 --- /dev/null +++ b/packages/plugin-github/tests/fixtures/create.2.json @@ -0,0 +1,141 @@ +{ + "ref": "2.3.2", + "ref_type": "tag", + "master_branch": "master", + "description": "QQ bot out of the box", + "pusher_type": "user", + "repository": { + "id": 225572038, + "node_id": "MDEwOlJlcG9zaXRvcnkyMjU1NzIwMzg=", + "name": "koishi", + "full_name": "koishijs/koishi", + "private": false, + "owner": { + "login": "koishijs", + "id": 58179220, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjU4MTc5MjIw", + "avatar_url": "https://avatars3.githubusercontent.com/u/58179220?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/koishijs", + "html_url": "https://github.com/koishijs", + "followers_url": "https://api.github.com/users/koishijs/followers", + "following_url": "https://api.github.com/users/koishijs/following{/other_user}", + "gists_url": "https://api.github.com/users/koishijs/gists{/gist_id}", + "starred_url": "https://api.github.com/users/koishijs/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/koishijs/subscriptions", + "organizations_url": "https://api.github.com/users/koishijs/orgs", + "repos_url": "https://api.github.com/users/koishijs/repos", + "events_url": "https://api.github.com/users/koishijs/events{/privacy}", + "received_events_url": "https://api.github.com/users/koishijs/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/koishijs/koishi", + "description": "QQ bot out of the box", + "fork": false, + "url": "https://api.github.com/repos/koishijs/koishi", + "forks_url": "https://api.github.com/repos/koishijs/koishi/forks", + "keys_url": "https://api.github.com/repos/koishijs/koishi/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/koishijs/koishi/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/koishijs/koishi/teams", + "hooks_url": "https://api.github.com/repos/koishijs/koishi/hooks", + "issue_events_url": "https://api.github.com/repos/koishijs/koishi/issues/events{/number}", + "events_url": "https://api.github.com/repos/koishijs/koishi/events", + "assignees_url": "https://api.github.com/repos/koishijs/koishi/assignees{/user}", + "branches_url": "https://api.github.com/repos/koishijs/koishi/branches{/branch}", + "tags_url": "https://api.github.com/repos/koishijs/koishi/tags", + "blobs_url": "https://api.github.com/repos/koishijs/koishi/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/koishijs/koishi/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/koishijs/koishi/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/koishijs/koishi/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/koishijs/koishi/statuses/{sha}", + "languages_url": "https://api.github.com/repos/koishijs/koishi/languages", + "stargazers_url": "https://api.github.com/repos/koishijs/koishi/stargazers", + "contributors_url": "https://api.github.com/repos/koishijs/koishi/contributors", + "subscribers_url": "https://api.github.com/repos/koishijs/koishi/subscribers", + "subscription_url": "https://api.github.com/repos/koishijs/koishi/subscription", + "commits_url": "https://api.github.com/repos/koishijs/koishi/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/koishijs/koishi/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/koishijs/koishi/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/koishijs/koishi/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/koishijs/koishi/contents/{+path}", + "compare_url": "https://api.github.com/repos/koishijs/koishi/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/koishijs/koishi/merges", + "archive_url": "https://api.github.com/repos/koishijs/koishi/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/koishijs/koishi/downloads", + "issues_url": "https://api.github.com/repos/koishijs/koishi/issues{/number}", + "pulls_url": "https://api.github.com/repos/koishijs/koishi/pulls{/number}", + "milestones_url": "https://api.github.com/repos/koishijs/koishi/milestones{/number}", + "notifications_url": "https://api.github.com/repos/koishijs/koishi/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/koishijs/koishi/labels{/name}", + "releases_url": "https://api.github.com/repos/koishijs/koishi/releases{/id}", + "deployments_url": "https://api.github.com/repos/koishijs/koishi/deployments", + "created_at": "2019-12-03T08:47:29Z", + "updated_at": "2020-10-15T15:42:23Z", + "pushed_at": "2020-10-15T15:43:55Z", + "git_url": "git://github.com/koishijs/koishi.git", + "ssh_url": "git@github.com:koishijs/koishi.git", + "clone_url": "https://github.com/koishijs/koishi.git", + "svn_url": "https://github.com/koishijs/koishi", + "homepage": "https://koishi.js.org", + "size": 2894, + "stargazers_count": 206, + "watchers_count": 206, + "language": "TypeScript", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": false, + "has_pages": false, + "forks_count": 15, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 8, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "forks": 15, + "open_issues": 8, + "watchers": 206, + "default_branch": "master" + }, + "organization": { + "login": "koishijs", + "id": 58179220, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjU4MTc5MjIw", + "url": "https://api.github.com/orgs/koishijs", + "repos_url": "https://api.github.com/orgs/koishijs/repos", + "events_url": "https://api.github.com/orgs/koishijs/events", + "hooks_url": "https://api.github.com/orgs/koishijs/hooks", + "issues_url": "https://api.github.com/orgs/koishijs/issues", + "members_url": "https://api.github.com/orgs/koishijs/members{/member}", + "public_members_url": "https://api.github.com/orgs/koishijs/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/58179220?v=4", + "description": "" + }, + "sender": { + "login": "Shigma", + "id": 33423008, + "node_id": "MDQ6VXNlcjMzNDIzMDA4", + "avatar_url": "https://avatars3.githubusercontent.com/u/33423008?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Shigma", + "html_url": "https://github.com/Shigma", + "followers_url": "https://api.github.com/users/Shigma/followers", + "following_url": "https://api.github.com/users/Shigma/following{/other_user}", + "gists_url": "https://api.github.com/users/Shigma/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Shigma/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Shigma/subscriptions", + "organizations_url": "https://api.github.com/users/Shigma/orgs", + "repos_url": "https://api.github.com/users/Shigma/repos", + "events_url": "https://api.github.com/users/Shigma/events{/privacy}", + "received_events_url": "https://api.github.com/users/Shigma/received_events", + "type": "User", + "site_admin": false + } +} \ No newline at end of file diff --git a/packages/plugin-github/tests/fixtures/delete.1.json b/packages/plugin-github/tests/fixtures/delete.1.json new file mode 100644 index 0000000000..3a9d029a75 --- /dev/null +++ b/packages/plugin-github/tests/fixtures/delete.1.json @@ -0,0 +1,139 @@ +{ + "ref": "reply-api", + "ref_type": "branch", + "pusher_type": "user", + "repository": { + "id": 225572038, + "node_id": "MDEwOlJlcG9zaXRvcnkyMjU1NzIwMzg=", + "name": "koishi", + "full_name": "koishijs/koishi", + "private": false, + "owner": { + "login": "koishijs", + "id": 58179220, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjU4MTc5MjIw", + "avatar_url": "https://avatars3.githubusercontent.com/u/58179220?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/koishijs", + "html_url": "https://github.com/koishijs", + "followers_url": "https://api.github.com/users/koishijs/followers", + "following_url": "https://api.github.com/users/koishijs/following{/other_user}", + "gists_url": "https://api.github.com/users/koishijs/gists{/gist_id}", + "starred_url": "https://api.github.com/users/koishijs/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/koishijs/subscriptions", + "organizations_url": "https://api.github.com/users/koishijs/orgs", + "repos_url": "https://api.github.com/users/koishijs/repos", + "events_url": "https://api.github.com/users/koishijs/events{/privacy}", + "received_events_url": "https://api.github.com/users/koishijs/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/koishijs/koishi", + "description": "QQ bot out of the box", + "fork": false, + "url": "https://api.github.com/repos/koishijs/koishi", + "forks_url": "https://api.github.com/repos/koishijs/koishi/forks", + "keys_url": "https://api.github.com/repos/koishijs/koishi/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/koishijs/koishi/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/koishijs/koishi/teams", + "hooks_url": "https://api.github.com/repos/koishijs/koishi/hooks", + "issue_events_url": "https://api.github.com/repos/koishijs/koishi/issues/events{/number}", + "events_url": "https://api.github.com/repos/koishijs/koishi/events", + "assignees_url": "https://api.github.com/repos/koishijs/koishi/assignees{/user}", + "branches_url": "https://api.github.com/repos/koishijs/koishi/branches{/branch}", + "tags_url": "https://api.github.com/repos/koishijs/koishi/tags", + "blobs_url": "https://api.github.com/repos/koishijs/koishi/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/koishijs/koishi/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/koishijs/koishi/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/koishijs/koishi/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/koishijs/koishi/statuses/{sha}", + "languages_url": "https://api.github.com/repos/koishijs/koishi/languages", + "stargazers_url": "https://api.github.com/repos/koishijs/koishi/stargazers", + "contributors_url": "https://api.github.com/repos/koishijs/koishi/contributors", + "subscribers_url": "https://api.github.com/repos/koishijs/koishi/subscribers", + "subscription_url": "https://api.github.com/repos/koishijs/koishi/subscription", + "commits_url": "https://api.github.com/repos/koishijs/koishi/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/koishijs/koishi/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/koishijs/koishi/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/koishijs/koishi/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/koishijs/koishi/contents/{+path}", + "compare_url": "https://api.github.com/repos/koishijs/koishi/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/koishijs/koishi/merges", + "archive_url": "https://api.github.com/repos/koishijs/koishi/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/koishijs/koishi/downloads", + "issues_url": "https://api.github.com/repos/koishijs/koishi/issues{/number}", + "pulls_url": "https://api.github.com/repos/koishijs/koishi/pulls{/number}", + "milestones_url": "https://api.github.com/repos/koishijs/koishi/milestones{/number}", + "notifications_url": "https://api.github.com/repos/koishijs/koishi/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/koishijs/koishi/labels{/name}", + "releases_url": "https://api.github.com/repos/koishijs/koishi/releases{/id}", + "deployments_url": "https://api.github.com/repos/koishijs/koishi/deployments", + "created_at": "2019-12-03T08:47:29Z", + "updated_at": "2020-10-17T05:26:38Z", + "pushed_at": "2020-10-18T16:40:10Z", + "git_url": "git://github.com/koishijs/koishi.git", + "ssh_url": "git@github.com:koishijs/koishi.git", + "clone_url": "https://github.com/koishijs/koishi.git", + "svn_url": "https://github.com/koishijs/koishi", + "homepage": "https://koishi.js.org", + "size": 2952, + "stargazers_count": 208, + "watchers_count": 208, + "language": "TypeScript", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": false, + "has_pages": false, + "forks_count": 15, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 7, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "forks": 15, + "open_issues": 7, + "watchers": 208, + "default_branch": "master" + }, + "organization": { + "login": "koishijs", + "id": 58179220, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjU4MTc5MjIw", + "url": "https://api.github.com/orgs/koishijs", + "repos_url": "https://api.github.com/orgs/koishijs/repos", + "events_url": "https://api.github.com/orgs/koishijs/events", + "hooks_url": "https://api.github.com/orgs/koishijs/hooks", + "issues_url": "https://api.github.com/orgs/koishijs/issues", + "members_url": "https://api.github.com/orgs/koishijs/members{/member}", + "public_members_url": "https://api.github.com/orgs/koishijs/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/58179220?v=4", + "description": "" + }, + "sender": { + "login": "Shigma", + "id": 33423008, + "node_id": "MDQ6VXNlcjMzNDIzMDA4", + "avatar_url": "https://avatars3.githubusercontent.com/u/33423008?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Shigma", + "html_url": "https://github.com/Shigma", + "followers_url": "https://api.github.com/users/Shigma/followers", + "following_url": "https://api.github.com/users/Shigma/following{/other_user}", + "gists_url": "https://api.github.com/users/Shigma/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Shigma/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Shigma/subscriptions", + "organizations_url": "https://api.github.com/users/Shigma/orgs", + "repos_url": "https://api.github.com/users/Shigma/repos", + "events_url": "https://api.github.com/users/Shigma/events{/privacy}", + "received_events_url": "https://api.github.com/users/Shigma/received_events", + "type": "User", + "site_admin": false + } +} \ No newline at end of file diff --git a/packages/plugin-github/tests/fixtures/delete.2.json b/packages/plugin-github/tests/fixtures/delete.2.json new file mode 100644 index 0000000000..62bbf2af8f --- /dev/null +++ b/packages/plugin-github/tests/fixtures/delete.2.json @@ -0,0 +1,119 @@ +{ + "ref": "0.1", + "ref_type": "tag", + "pusher_type": "user", + "repository": { + "id": 291791662, + "node_id": "MDEwOlJlcG9zaXRvcnkyOTE3OTE2NjI=", + "name": "koishi", + "full_name": "koishijs/koishi", + "private": false, + "owner": { + "login": "Shigma", + "id": 33423008, + "node_id": "MDQ6VXNlcjMzNDIzMDA4", + "avatar_url": "https://avatars3.githubusercontent.com/u/33423008?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Shigma", + "html_url": "https://github.com/Shigma", + "followers_url": "https://api.github.com/users/Shigma/followers", + "following_url": "https://api.github.com/users/Shigma/following{/other_user}", + "gists_url": "https://api.github.com/users/Shigma/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Shigma/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Shigma/subscriptions", + "organizations_url": "https://api.github.com/users/Shigma/orgs", + "repos_url": "https://api.github.com/users/Shigma/repos", + "events_url": "https://api.github.com/users/Shigma/events{/privacy}", + "received_events_url": "https://api.github.com/users/Shigma/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/koishijs/koishi", + "description": null, + "fork": false, + "url": "https://api.github.com/repos/koishijs/koishi", + "forks_url": "https://api.github.com/repos/koishijs/koishi/forks", + "keys_url": "https://api.github.com/repos/koishijs/koishi/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/koishijs/koishi/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/koishijs/koishi/teams", + "hooks_url": "https://api.github.com/repos/koishijs/koishi/hooks", + "issue_events_url": "https://api.github.com/repos/koishijs/koishi/issues/events{/number}", + "events_url": "https://api.github.com/repos/koishijs/koishi/events", + "assignees_url": "https://api.github.com/repos/koishijs/koishi/assignees{/user}", + "branches_url": "https://api.github.com/repos/koishijs/koishi/branches{/branch}", + "tags_url": "https://api.github.com/repos/koishijs/koishi/tags", + "blobs_url": "https://api.github.com/repos/koishijs/koishi/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/koishijs/koishi/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/koishijs/koishi/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/koishijs/koishi/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/koishijs/koishi/statuses/{sha}", + "languages_url": "https://api.github.com/repos/koishijs/koishi/languages", + "stargazers_url": "https://api.github.com/repos/koishijs/koishi/stargazers", + "contributors_url": "https://api.github.com/repos/koishijs/koishi/contributors", + "subscribers_url": "https://api.github.com/repos/koishijs/koishi/subscribers", + "subscription_url": "https://api.github.com/repos/koishijs/koishi/subscription", + "commits_url": "https://api.github.com/repos/koishijs/koishi/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/koishijs/koishi/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/koishijs/koishi/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/koishijs/koishi/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/koishijs/koishi/contents/{+path}", + "compare_url": "https://api.github.com/repos/koishijs/koishi/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/koishijs/koishi/merges", + "archive_url": "https://api.github.com/repos/koishijs/koishi/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/koishijs/koishi/downloads", + "issues_url": "https://api.github.com/repos/koishijs/koishi/issues{/number}", + "pulls_url": "https://api.github.com/repos/koishijs/koishi/pulls{/number}", + "milestones_url": "https://api.github.com/repos/koishijs/koishi/milestones{/number}", + "notifications_url": "https://api.github.com/repos/koishijs/koishi/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/koishijs/koishi/labels{/name}", + "releases_url": "https://api.github.com/repos/koishijs/koishi/releases{/id}", + "deployments_url": "https://api.github.com/repos/koishijs/koishi/deployments", + "created_at": "2020-08-31T18:19:07Z", + "updated_at": "2020-08-31T18:21:42Z", + "pushed_at": "2020-10-18T16:55:05Z", + "git_url": "git://github.com/koishijs/koishi.git", + "ssh_url": "git@github.com:koishijs/koishi.git", + "clone_url": "https://github.com/koishijs/koishi.git", + "svn_url": "https://github.com/koishijs/koishi", + "homepage": null, + "size": 1, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": false, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 5, + "license": null, + "forks": 0, + "open_issues": 5, + "watchers": 0, + "default_branch": "master" + }, + "sender": { + "login": "Shigma", + "id": 33423008, + "node_id": "MDQ6VXNlcjMzNDIzMDA4", + "avatar_url": "https://avatars3.githubusercontent.com/u/33423008?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Shigma", + "html_url": "https://github.com/Shigma", + "followers_url": "https://api.github.com/users/Shigma/followers", + "following_url": "https://api.github.com/users/Shigma/following{/other_user}", + "gists_url": "https://api.github.com/users/Shigma/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Shigma/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Shigma/subscriptions", + "organizations_url": "https://api.github.com/users/Shigma/orgs", + "repos_url": "https://api.github.com/users/Shigma/repos", + "events_url": "https://api.github.com/users/Shigma/events{/privacy}", + "received_events_url": "https://api.github.com/users/Shigma/received_events", + "type": "User", + "site_admin": false + } +} \ No newline at end of file diff --git a/packages/plugin-github/tests/fixtures/release.unpublished.json b/packages/plugin-github/tests/fixtures/release.unpublished.json new file mode 100644 index 0000000000..142c9b6891 --- /dev/null +++ b/packages/plugin-github/tests/fixtures/release.unpublished.json @@ -0,0 +1,158 @@ +{ + "action": "unpublished", + "release": { + "url": "https://api.github.com/repos/Shigma/github-webhook-test/releases/32724119", + "assets_url": "https://api.github.com/repos/Shigma/github-webhook-test/releases/32724119/assets", + "upload_url": "https://uploads.github.com/repos/Shigma/github-webhook-test/releases/32724119/assets{?name,label}", + "html_url": "https://github.com/Shigma/github-webhook-test/releases/tag/untagged-3fb49cc303145a9f734e", + "id": 32724119, + "node_id": "MDc6UmVsZWFzZTMyNzI0MTE5", + "tag_name": "0.1", + "target_commitish": "master", + "name": "test", + "draft": true, + "author": { + "login": "Shigma", + "id": 33423008, + "node_id": "MDQ6VXNlcjMzNDIzMDA4", + "avatar_url": "https://avatars3.githubusercontent.com/u/33423008?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Shigma", + "html_url": "https://github.com/Shigma", + "followers_url": "https://api.github.com/users/Shigma/followers", + "following_url": "https://api.github.com/users/Shigma/following{/other_user}", + "gists_url": "https://api.github.com/users/Shigma/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Shigma/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Shigma/subscriptions", + "organizations_url": "https://api.github.com/users/Shigma/orgs", + "repos_url": "https://api.github.com/users/Shigma/repos", + "events_url": "https://api.github.com/users/Shigma/events{/privacy}", + "received_events_url": "https://api.github.com/users/Shigma/received_events", + "type": "User", + "site_admin": false + }, + "prerelease": false, + "created_at": "2020-08-31T18:19:09Z", + "published_at": null, + "assets": [ + + ], + "tarball_url": null, + "zipball_url": null, + "body": "" + }, + "repository": { + "id": 291791662, + "node_id": "MDEwOlJlcG9zaXRvcnkyOTE3OTE2NjI=", + "name": "github-webhook-test", + "full_name": "Shigma/github-webhook-test", + "private": false, + "owner": { + "login": "Shigma", + "id": 33423008, + "node_id": "MDQ6VXNlcjMzNDIzMDA4", + "avatar_url": "https://avatars3.githubusercontent.com/u/33423008?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Shigma", + "html_url": "https://github.com/Shigma", + "followers_url": "https://api.github.com/users/Shigma/followers", + "following_url": "https://api.github.com/users/Shigma/following{/other_user}", + "gists_url": "https://api.github.com/users/Shigma/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Shigma/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Shigma/subscriptions", + "organizations_url": "https://api.github.com/users/Shigma/orgs", + "repos_url": "https://api.github.com/users/Shigma/repos", + "events_url": "https://api.github.com/users/Shigma/events{/privacy}", + "received_events_url": "https://api.github.com/users/Shigma/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/Shigma/github-webhook-test", + "description": null, + "fork": false, + "url": "https://api.github.com/repos/Shigma/github-webhook-test", + "forks_url": "https://api.github.com/repos/Shigma/github-webhook-test/forks", + "keys_url": "https://api.github.com/repos/Shigma/github-webhook-test/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/Shigma/github-webhook-test/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/Shigma/github-webhook-test/teams", + "hooks_url": "https://api.github.com/repos/Shigma/github-webhook-test/hooks", + "issue_events_url": "https://api.github.com/repos/Shigma/github-webhook-test/issues/events{/number}", + "events_url": "https://api.github.com/repos/Shigma/github-webhook-test/events", + "assignees_url": "https://api.github.com/repos/Shigma/github-webhook-test/assignees{/user}", + "branches_url": "https://api.github.com/repos/Shigma/github-webhook-test/branches{/branch}", + "tags_url": "https://api.github.com/repos/Shigma/github-webhook-test/tags", + "blobs_url": "https://api.github.com/repos/Shigma/github-webhook-test/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/Shigma/github-webhook-test/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/Shigma/github-webhook-test/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/Shigma/github-webhook-test/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/Shigma/github-webhook-test/statuses/{sha}", + "languages_url": "https://api.github.com/repos/Shigma/github-webhook-test/languages", + "stargazers_url": "https://api.github.com/repos/Shigma/github-webhook-test/stargazers", + "contributors_url": "https://api.github.com/repos/Shigma/github-webhook-test/contributors", + "subscribers_url": "https://api.github.com/repos/Shigma/github-webhook-test/subscribers", + "subscription_url": "https://api.github.com/repos/Shigma/github-webhook-test/subscription", + "commits_url": "https://api.github.com/repos/Shigma/github-webhook-test/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/Shigma/github-webhook-test/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/Shigma/github-webhook-test/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/Shigma/github-webhook-test/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/Shigma/github-webhook-test/contents/{+path}", + "compare_url": "https://api.github.com/repos/Shigma/github-webhook-test/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/Shigma/github-webhook-test/merges", + "archive_url": "https://api.github.com/repos/Shigma/github-webhook-test/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/Shigma/github-webhook-test/downloads", + "issues_url": "https://api.github.com/repos/Shigma/github-webhook-test/issues{/number}", + "pulls_url": "https://api.github.com/repos/Shigma/github-webhook-test/pulls{/number}", + "milestones_url": "https://api.github.com/repos/Shigma/github-webhook-test/milestones{/number}", + "notifications_url": "https://api.github.com/repos/Shigma/github-webhook-test/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/Shigma/github-webhook-test/labels{/name}", + "releases_url": "https://api.github.com/repos/Shigma/github-webhook-test/releases{/id}", + "deployments_url": "https://api.github.com/repos/Shigma/github-webhook-test/deployments", + "created_at": "2020-08-31T18:19:07Z", + "updated_at": "2020-08-31T18:21:42Z", + "pushed_at": "2020-10-18T16:55:05Z", + "git_url": "git://github.com/Shigma/github-webhook-test.git", + "ssh_url": "git@github.com:Shigma/github-webhook-test.git", + "clone_url": "https://github.com/Shigma/github-webhook-test.git", + "svn_url": "https://github.com/Shigma/github-webhook-test", + "homepage": null, + "size": 1, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": false, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 5, + "license": null, + "forks": 0, + "open_issues": 5, + "watchers": 0, + "default_branch": "master" + }, + "sender": { + "login": "ghost", + "id": 10137, + "node_id": "MDQ6VXNlcjEwMTM3", + "avatar_url": "https://avatars3.githubusercontent.com/u/10137?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/ghost", + "html_url": "https://github.com/ghost", + "followers_url": "https://api.github.com/users/ghost/followers", + "following_url": "https://api.github.com/users/ghost/following{/other_user}", + "gists_url": "https://api.github.com/users/ghost/gists{/gist_id}", + "starred_url": "https://api.github.com/users/ghost/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/ghost/subscriptions", + "organizations_url": "https://api.github.com/users/ghost/orgs", + "repos_url": "https://api.github.com/users/ghost/repos", + "events_url": "https://api.github.com/users/ghost/events{/privacy}", + "received_events_url": "https://api.github.com/users/ghost/received_events", + "type": "User", + "site_admin": false + } +} \ No newline at end of file diff --git a/packages/plugin-github/tests/index.snap.js b/packages/plugin-github/tests/index.snap.js index f3eb7248a2..375fdf018f 100644 --- a/packages/plugin-github/tests/index.snap.js +++ b/packages/plugin-github/tests/index.snap.js @@ -4,6 +4,18 @@ module.exports[`commit_comment.created`] = ` Path: packages/koishi-core/tests/parser.spec.ts This will introduce a failure in test.` +module.exports[`create.1`] = ` +[GitHub] Shigma created branch koishijs/koishi:reply-api` + +module.exports[`create.2`] = ` +[GitHub] Shigma created tag koishijs/koishi@2.3.2` + +module.exports[`delete.1`] = ` +[GitHub] Shigma deleted branch koishijs/koishi:reply-api` + +module.exports[`delete.2`] = ` +[GitHub] Shigma deleted tag koishijs/koishi@0.1` + module.exports[`fork`] = ` [GitHub] jjyyxx forked koishijs/koishi to jjyyxx/koishi (total 12 forks)` @@ -64,8 +76,5 @@ module.exports[`push.1`] = ` [d7ff34] chore: adjust [3ae7e7] fix(core): create major context at demand` -module.exports[`push.3`] = ` -[GitHub] Shigma published tag koishijs/koishi@1.5.0` - module.exports[`star.created`] = ` [GitHub] 275761919 starred koishijs/koishi (total 189 stargazers)`