From feb6698693fc66ec00a04342da7b2a72c6326717 Mon Sep 17 00:00:00 2001 From: Shigma <1700011071@pku.edu.cn> Date: Mon, 31 Aug 2020 21:58:08 +0800 Subject: [PATCH] feat(github): support fork event --- packages/plugin-github/src/index.ts | 4 + .../plugin-github/tests/fixtures/fork.json | 237 ++++++++++++++++++ packages/plugin-github/tests/index.snap.js | 3 + 3 files changed, 244 insertions(+) create mode 100644 packages/plugin-github/tests/fixtures/fork.json diff --git a/packages/plugin-github/src/index.ts b/packages/plugin-github/src/index.ts index 2bbfe9aded..9b21b817c3 100644 --- a/packages/plugin-github/src/index.ts +++ b/packages/plugin-github/src/index.ts @@ -274,4 +274,8 @@ export function apply(ctx: Context, config: Config = {}) { ...commits.map(c => `[${c.id.slice(0, 6)}] ${formatMarkdown(c.message)}`), ].join('\n')] }) + + registerHandler('fork', ({ repository, sender, forkee }) => { + return [`[GitHub] ${sender.login} forked ${repository.full_name} to ${forkee.full_name}`] + }) } diff --git a/packages/plugin-github/tests/fixtures/fork.json b/packages/plugin-github/tests/fixtures/fork.json new file mode 100644 index 0000000000..5aba27cde2 --- /dev/null +++ b/packages/plugin-github/tests/fixtures/fork.json @@ -0,0 +1,237 @@ +{ + "forkee": { + "id": 290096040, + "node_id": "MDEwOlJlcG9zaXRvcnkyOTAwOTYwNDA=", + "name": "koishi", + "full_name": "jjyyxx/koishi", + "private": false, + "owner": { + "login": "jjyyxx", + "id": 13808089, + "node_id": "MDQ6VXNlcjEzODA4MDg5", + "avatar_url": "https://avatars3.githubusercontent.com/u/13808089?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/jjyyxx", + "html_url": "https://github.com/jjyyxx", + "followers_url": "https://api.github.com/users/jjyyxx/followers", + "following_url": "https://api.github.com/users/jjyyxx/following{/other_user}", + "gists_url": "https://api.github.com/users/jjyyxx/gists{/gist_id}", + "starred_url": "https://api.github.com/users/jjyyxx/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/jjyyxx/subscriptions", + "organizations_url": "https://api.github.com/users/jjyyxx/orgs", + "repos_url": "https://api.github.com/users/jjyyxx/repos", + "events_url": "https://api.github.com/users/jjyyxx/events{/privacy}", + "received_events_url": "https://api.github.com/users/jjyyxx/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/jjyyxx/koishi", + "description": "QQ bot out of the box", + "fork": true, + "url": "https://api.github.com/repos/jjyyxx/koishi", + "forks_url": "https://api.github.com/repos/jjyyxx/koishi/forks", + "keys_url": "https://api.github.com/repos/jjyyxx/koishi/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/jjyyxx/koishi/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/jjyyxx/koishi/teams", + "hooks_url": "https://api.github.com/repos/jjyyxx/koishi/hooks", + "issue_events_url": "https://api.github.com/repos/jjyyxx/koishi/issues/events{/number}", + "events_url": "https://api.github.com/repos/jjyyxx/koishi/events", + "assignees_url": "https://api.github.com/repos/jjyyxx/koishi/assignees{/user}", + "branches_url": "https://api.github.com/repos/jjyyxx/koishi/branches{/branch}", + "tags_url": "https://api.github.com/repos/jjyyxx/koishi/tags", + "blobs_url": "https://api.github.com/repos/jjyyxx/koishi/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/jjyyxx/koishi/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/jjyyxx/koishi/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/jjyyxx/koishi/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/jjyyxx/koishi/statuses/{sha}", + "languages_url": "https://api.github.com/repos/jjyyxx/koishi/languages", + "stargazers_url": "https://api.github.com/repos/jjyyxx/koishi/stargazers", + "contributors_url": "https://api.github.com/repos/jjyyxx/koishi/contributors", + "subscribers_url": "https://api.github.com/repos/jjyyxx/koishi/subscribers", + "subscription_url": "https://api.github.com/repos/jjyyxx/koishi/subscription", + "commits_url": "https://api.github.com/repos/jjyyxx/koishi/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/jjyyxx/koishi/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/jjyyxx/koishi/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/jjyyxx/koishi/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/jjyyxx/koishi/contents/{+path}", + "compare_url": "https://api.github.com/repos/jjyyxx/koishi/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/jjyyxx/koishi/merges", + "archive_url": "https://api.github.com/repos/jjyyxx/koishi/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/jjyyxx/koishi/downloads", + "issues_url": "https://api.github.com/repos/jjyyxx/koishi/issues{/number}", + "pulls_url": "https://api.github.com/repos/jjyyxx/koishi/pulls{/number}", + "milestones_url": "https://api.github.com/repos/jjyyxx/koishi/milestones{/number}", + "notifications_url": "https://api.github.com/repos/jjyyxx/koishi/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/jjyyxx/koishi/labels{/name}", + "releases_url": "https://api.github.com/repos/jjyyxx/koishi/releases{/id}", + "deployments_url": "https://api.github.com/repos/jjyyxx/koishi/deployments", + "created_at": "2020-08-25T02:51:14Z", + "updated_at": "2020-08-24T19:15:52Z", + "pushed_at": "2020-08-24T18:51:18Z", + "git_url": "git://github.com/jjyyxx/koishi.git", + "ssh_url": "git@github.com:jjyyxx/koishi.git", + "clone_url": "https://github.com/jjyyxx/koishi.git", + "svn_url": "https://github.com/jjyyxx/koishi", + "homepage": "https://koishi.js.org", + "size": 2438, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": false, + "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": 0, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "forks": 0, + "open_issues": 0, + "watchers": 0, + "default_branch": "master", + "public": true + }, + "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-08-24T19:15:52Z", + "pushed_at": "2020-08-24T18:51:18Z", + "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": 2438, + "stargazers_count": 186, + "watchers_count": 186, + "language": "TypeScript", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": false, + "has_pages": false, + "forks_count": 12, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 2, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "forks": 12, + "open_issues": 2, + "watchers": 186, + "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": "jjyyxx", + "id": 13808089, + "node_id": "MDQ6VXNlcjEzODA4MDg5", + "avatar_url": "https://avatars3.githubusercontent.com/u/13808089?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/jjyyxx", + "html_url": "https://github.com/jjyyxx", + "followers_url": "https://api.github.com/users/jjyyxx/followers", + "following_url": "https://api.github.com/users/jjyyxx/following{/other_user}", + "gists_url": "https://api.github.com/users/jjyyxx/gists{/gist_id}", + "starred_url": "https://api.github.com/users/jjyyxx/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/jjyyxx/subscriptions", + "organizations_url": "https://api.github.com/users/jjyyxx/orgs", + "repos_url": "https://api.github.com/users/jjyyxx/repos", + "events_url": "https://api.github.com/users/jjyyxx/events{/privacy}", + "received_events_url": "https://api.github.com/users/jjyyxx/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 90fb64c3bd..9c95b5cdc8 100644 --- a/packages/plugin-github/tests/index.snap.js +++ b/packages/plugin-github/tests/index.snap.js @@ -3,6 +3,9 @@ module.exports[`commit_comment.created`] = ` URL: https://github.com/koishijs/koishi/commit/bff469eabe14d42683a4f7c3ccb659daec5e1c00#commitcomment-36878220 This will introduce a failure in test.` +module.exports[`fork`] = ` +[GitHub] jjyyxx forked koishijs/koishi to jjyyxx/koishi` + module.exports[`issue_comment.created.1`] = ` [GitHub] simon300000 commented on issue koishijs/koishi#19 URL: https://github.com/koishijs/koishi/issues/19#issuecomment-576277946