Skip to content

Commit

Permalink
fix(github): fix wrong implementation of bot check
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Sep 9, 2020
1 parent 827aa1f commit cf00713
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 8 deletions.
12 changes: 6 additions & 6 deletions packages/plugin-github/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function addListeners(on: <T extends EventNames.All>(event: T, handler: E
function onComment<E extends CommentEvent>(event: E, handler: CommandHandler<E>) {
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') {
Expand Down Expand Up @@ -157,7 +157,7 @@ export function addListeners(on: <T extends EventNames.All>(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}`,
Expand All @@ -173,7 +173,7 @@ export function addListeners(on: <T extends EventNames.All>(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,
Expand All @@ -196,7 +196,7 @@ export function addListeners(on: <T extends EventNames.All>(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}`,
Expand All @@ -207,7 +207,7 @@ export function addListeners(on: <T extends EventNames.All>(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,
Expand All @@ -219,7 +219,7 @@ export function addListeners(on: <T extends EventNames.All>(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, '')
Expand Down
225 changes: 225 additions & 0 deletions packages/plugin-github/tests/fixtures/issue_comment.created.3.json
Original file line number Diff line number Diff line change
@@ -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 <relative> (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
}
}
4 changes: 2 additions & 2 deletions packages/plugin-github/tests/index.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`] = `
Expand Down

0 comments on commit cf00713

Please sign in to comment.