From cf0071345a338fcd56a780bca0938e8ca9001a22 Mon Sep 17 00:00:00 2001 From: Shigma <1700011071@pku.edu.cn> Date: Wed, 9 Sep 2020 21:16:34 +0800 Subject: [PATCH] fix(github): fix wrong implementation of bot check --- packages/plugin-github/src/events.ts | 12 +- .../fixtures/issue_comment.created.3.json | 225 ++++++++++++++++++ .../{push.commit.json => push.1.json} | 0 .../{push.delete.json => push.2.json} | 0 .../fixtures/{push.tag.json => push.3.json} | 0 packages/plugin-github/tests/index.snap.js | 4 +- 6 files changed, 233 insertions(+), 8 deletions(-) create mode 100644 packages/plugin-github/tests/fixtures/issue_comment.created.3.json rename packages/plugin-github/tests/fixtures/{push.commit.json => push.1.json} (100%) rename packages/plugin-github/tests/fixtures/{push.delete.json => push.2.json} (100%) rename packages/plugin-github/tests/fixtures/{push.tag.json => push.3.json} (100%) diff --git a/packages/plugin-github/src/events.ts b/packages/plugin-github/src/events.ts index 1b9f3aebeb..c1ce74d6d2 100644 --- a/packages/plugin-github/src/events.ts +++ b/packages/plugin-github/src/events.ts @@ -115,7 +115,7 @@ export function addListeners(on: (event: T, handler: E function onComment(event: E, handler: CommandHandler) { on(event as CommentEvent, (payload) => { const { user, body, html_url, url } = payload.comment - if (user.type === 'bot') return + if (user.type === 'Bot') return const [target, replies] = handler(payload) if (payload.action === 'deleted') { @@ -157,7 +157,7 @@ export function addListeners(on: (event: T, handler: E on('issues.opened', ({ repository, issue }) => { const { full_name } = repository const { user, url, html_url, comments_url, title, body, number } = issue - if (user.type === 'bot') return + if (user.type === 'Bot') return return [[ `[GitHub] ${user.login} opened an issue ${full_name}#${number}`, @@ -173,7 +173,7 @@ export function addListeners(on: (event: T, handler: E on('issues.closed', ({ repository, issue }) => { const { full_name } = repository const { user, url, html_url, comments_url, title, number } = issue - if (user.type === 'bot') return + if (user.type === 'Bot') return return [`[GitHub] ${user.login} closed issue ${full_name}#${number}\n${title}`, { link: html_url, @@ -196,7 +196,7 @@ export function addListeners(on: (event: T, handler: E const { full_name } = repository const { number, comments_url } = pull_request const { user, html_url, body } = review - if (user.type === 'bot') return + if (user.type === 'Bot') return return [[ `[GitHub] ${user.login} reviewed pull request ${full_name}#${number}`, @@ -207,7 +207,7 @@ export function addListeners(on: (event: T, handler: E on('pull_request.closed', ({ repository, pull_request }) => { const { full_name } = repository const { user, html_url, issue_url, comments_url, title, number } = pull_request - if (user.type === 'bot') return + if (user.type === 'Bot') return return [`[GitHub] ${user.login} closed pull request ${full_name}#${number}\n${title}`, { link: html_url, @@ -219,7 +219,7 @@ export function addListeners(on: (event: T, handler: E on('pull_request.opened', ({ repository, pull_request }) => { const { full_name, owner } = repository const { user, html_url, issue_url, comments_url, title, base, head, body, number } = pull_request - if (user.type === 'bot') return + if (user.type === 'Bot') return const prefix = new RegExp(`^${owner.login}:`) const baseLabel = base.label.replace(prefix, '') diff --git a/packages/plugin-github/tests/fixtures/issue_comment.created.3.json b/packages/plugin-github/tests/fixtures/issue_comment.created.3.json new file mode 100644 index 0000000000..e125bd761f --- /dev/null +++ b/packages/plugin-github/tests/fixtures/issue_comment.created.3.json @@ -0,0 +1,225 @@ +{ + "action": "created", + "issue": { + "url": "https://api.github.com/repos/koishijs/koishi/issues/101", + "repository_url": "https://api.github.com/repos/koishijs/koishi", + "labels_url": "https://api.github.com/repos/koishijs/koishi/issues/101/labels{/name}", + "comments_url": "https://api.github.com/repos/koishijs/koishi/issues/101/comments", + "events_url": "https://api.github.com/repos/koishijs/koishi/issues/101/events", + "html_url": "https://github.com/koishijs/koishi/pull/101", + "id": 696725360, + "node_id": "MDExOlB1bGxSZXF1ZXN0NDgyNzY4OTA2", + "number": 101, + "title": "来壮大列表了(不是", + "user": { + "login": "arily", + "id": 10007589, + "node_id": "MDQ6VXNlcjEwMDA3NTg5", + "avatar_url": "https://avatars1.githubusercontent.com/u/10007589?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/arily", + "html_url": "https://github.com/arily", + "followers_url": "https://api.github.com/users/arily/followers", + "following_url": "https://api.github.com/users/arily/following{/other_user}", + "gists_url": "https://api.github.com/users/arily/gists{/gist_id}", + "starred_url": "https://api.github.com/users/arily/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/arily/subscriptions", + "organizations_url": "https://api.github.com/users/arily/orgs", + "repos_url": "https://api.github.com/users/arily/repos", + "events_url": "https://api.github.com/users/arily/events{/privacy}", + "received_events_url": "https://api.github.com/users/arily/received_events", + "type": "User", + "site_admin": false + }, + "labels": [ + + ], + "state": "open", + "locked": false, + "assignee": null, + "assignees": [ + + ], + "milestone": null, + "comments": 1, + "created_at": "2020-09-09T11:18:01Z", + "updated_at": "2020-09-09T11:19:48Z", + "closed_at": null, + "author_association": "NONE", + "active_lock_reason": null, + "pull_request": { + "url": "https://api.github.com/repos/koishijs/koishi/pulls/101", + "html_url": "https://github.com/koishijs/koishi/pull/101", + "diff_url": "https://github.com/koishijs/koishi/pull/101.diff", + "patch_url": "https://github.com/koishijs/koishi/pull/101.patch" + }, + "body": "套壳框架xd", + "performed_via_github_app": null + }, + "comment": { + "url": "https://api.github.com/repos/koishijs/koishi/issues/comments/689496545", + "html_url": "https://github.com/koishijs/koishi/pull/101#issuecomment-689496545", + "issue_url": "https://api.github.com/repos/koishijs/koishi/issues/101", + "id": 689496545, + "node_id": "MDEyOklzc3VlQ29tbWVudDY4OTQ5NjU0NQ==", + "user": { + "login": "codecov[bot]", + "id": 22429695, + "node_id": "MDM6Qm90MjI0Mjk2OTU=", + "avatar_url": "https://avatars2.githubusercontent.com/in/254?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/codecov%5Bbot%5D", + "html_url": "https://github.com/apps/codecov", + "followers_url": "https://api.github.com/users/codecov%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/codecov%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/codecov%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/codecov%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/codecov%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/codecov%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/codecov%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/codecov%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/codecov%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + }, + "created_at": "2020-09-09T11:19:48Z", + "updated_at": "2020-09-09T11:19:48Z", + "author_association": "NONE", + "body": "# [Codecov](https://codecov.io/gh/koishijs/koishi/pull/101?src=pr&el=h1) Report\n> Merging [#101](https://codecov.io/gh/koishijs/koishi/pull/101?src=pr&el=desc) into [master](https://codecov.io/gh/koishijs/koishi/commit/572d976eb27790d1e8e3eddecc6a901cd9476905?el=desc) will **not change** coverage.\n> The diff coverage is `n/a`.\n\n[![Impacted file tree graph](https://codecov.io/gh/koishijs/koishi/pull/101/graphs/tree.svg?width=650&height=150&src=pr&token=ENpAXNOUwW)](https://codecov.io/gh/koishijs/koishi/pull/101?src=pr&el=tree)\n\n```diff\n@@ Coverage Diff @@\n## master #101 +/- ##\n=======================================\n Coverage 92.60% 92.60% \n=======================================\n Files 52 52 \n Lines 8015 8015 \n Branches 1720 1720 \n=======================================\n Hits 7422 7422 \n Misses 593 593 \n```\n\n\n\n------\n\n[Continue to review full report at Codecov](https://codecov.io/gh/koishijs/koishi/pull/101?src=pr&el=continue).\n> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)\n> `Δ = absolute (impact)`, `ø = not affected`, `? = missing data`\n> Powered by [Codecov](https://codecov.io/gh/koishijs/koishi/pull/101?src=pr&el=footer). Last update [572d976...38261a3](https://codecov.io/gh/koishijs/koishi/pull/101?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).\n", + "performed_via_github_app": null + }, + "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-09-06T15:08:28Z", + "pushed_at": "2020-09-09T11:18:02Z", + "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": 193, + "watchers_count": 193, + "language": "TypeScript", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": false, + "has_pages": false, + "forks_count": 14, + "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": 14, + "open_issues": 7, + "watchers": 193, + "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": "codecov[bot]", + "id": 22429695, + "node_id": "MDM6Qm90MjI0Mjk2OTU=", + "avatar_url": "https://avatars2.githubusercontent.com/in/254?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/codecov%5Bbot%5D", + "html_url": "https://github.com/apps/codecov", + "followers_url": "https://api.github.com/users/codecov%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/codecov%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/codecov%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/codecov%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/codecov%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/codecov%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/codecov%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/codecov%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/codecov%5Bbot%5D/received_events", + "type": "Bot", + "site_admin": false + } +} \ No newline at end of file diff --git a/packages/plugin-github/tests/fixtures/push.commit.json b/packages/plugin-github/tests/fixtures/push.1.json similarity index 100% rename from packages/plugin-github/tests/fixtures/push.commit.json rename to packages/plugin-github/tests/fixtures/push.1.json diff --git a/packages/plugin-github/tests/fixtures/push.delete.json b/packages/plugin-github/tests/fixtures/push.2.json similarity index 100% rename from packages/plugin-github/tests/fixtures/push.delete.json rename to packages/plugin-github/tests/fixtures/push.2.json diff --git a/packages/plugin-github/tests/fixtures/push.tag.json b/packages/plugin-github/tests/fixtures/push.3.json similarity index 100% rename from packages/plugin-github/tests/fixtures/push.tag.json rename to packages/plugin-github/tests/fixtures/push.3.json diff --git a/packages/plugin-github/tests/index.snap.js b/packages/plugin-github/tests/index.snap.js index f2bb53587a..a18fa6e851 100644 --- a/packages/plugin-github/tests/index.snap.js +++ b/packages/plugin-github/tests/index.snap.js @@ -55,12 +55,12 @@ Path: packages/test-utils/src/mocks.ts Naming is so hard......` // URL: https://github.com/koishijs/koishi/compare/976c6e8f09a4...3ae7e7044d06 -module.exports[`push.commit`] = ` +module.exports[`push.1`] = ` [GitHub] Shigma pushed to koishijs/koishi:develop [d7ff34] chore: adjust [3ae7e7] fix(core): create major context at demand` -module.exports[`push.tag`] = ` +module.exports[`push.3`] = ` [GitHub] Shigma published tag koishijs/koishi@1.5.0` module.exports[`star.created`] = `