From d5bd9bd73a3d1c1011b4d1d140973dbe132f333d Mon Sep 17 00:00:00 2001 From: Shigma <1700011071@pku.edu.cn> Date: Mon, 31 Aug 2020 22:04:39 +0800 Subject: [PATCH] feat(github): support star.created event --- packages/plugin-github/src/index.ts | 8 +- .../tests/fixtures/star.created.json | 138 ++++++++++++++++++ packages/plugin-github/tests/index.snap.js | 5 +- 3 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 packages/plugin-github/tests/fixtures/star.created.json diff --git a/packages/plugin-github/src/index.ts b/packages/plugin-github/src/index.ts index 9b21b817c3..cf3c49398f 100644 --- a/packages/plugin-github/src/index.ts +++ b/packages/plugin-github/src/index.ts @@ -169,6 +169,10 @@ export function apply(ctx: Context, config: Config = {}) { ].join('\n')] }) + registerHandler('fork', ({ repository, sender, forkee }) => { + return [`[GitHub] ${sender.login} forked ${repository.full_name} to ${forkee.full_name} (total ${repository.forks_count} forks)`] + }) + const checkToken: Middleware = async (session, next) => { const user = await session.$observeUser(['githubToken']) if (!user.githubToken) { @@ -275,7 +279,7 @@ export function apply(ctx: Context, config: Config = {}) { ].join('\n')] }) - registerHandler('fork', ({ repository, sender, forkee }) => { - return [`[GitHub] ${sender.login} forked ${repository.full_name} to ${forkee.full_name}`] + registerHandler('star.created', ({ repository, sender }) => { + return [`[GitHub] ${sender.login} starred ${repository.full_name} (total ${repository.stargazers_count} stargazers)`] }) } diff --git a/packages/plugin-github/tests/fixtures/star.created.json b/packages/plugin-github/tests/fixtures/star.created.json new file mode 100644 index 0000000000..e2a5ab582e --- /dev/null +++ b/packages/plugin-github/tests/fixtures/star.created.json @@ -0,0 +1,138 @@ +{ + "action": "created", + "starred_at": "2020-08-27T10:21:02Z", + "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-27T10:21:02Z", + "pushed_at": "2020-08-27T08:52:42Z", + "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": 2777, + "stargazers_count": 189, + "watchers_count": 189, + "language": "TypeScript", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": false, + "has_pages": false, + "forks_count": 13, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 5, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "forks": 13, + "open_issues": 5, + "watchers": 189, + "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": "275761919", + "id": 14012127, + "node_id": "MDQ6VXNlcjE0MDEyMTI3", + "avatar_url": "https://avatars0.githubusercontent.com/u/14012127?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/275761919", + "html_url": "https://github.com/275761919", + "followers_url": "https://api.github.com/users/275761919/followers", + "following_url": "https://api.github.com/users/275761919/following{/other_user}", + "gists_url": "https://api.github.com/users/275761919/gists{/gist_id}", + "starred_url": "https://api.github.com/users/275761919/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/275761919/subscriptions", + "organizations_url": "https://api.github.com/users/275761919/orgs", + "repos_url": "https://api.github.com/users/275761919/repos", + "events_url": "https://api.github.com/users/275761919/events{/privacy}", + "received_events_url": "https://api.github.com/users/275761919/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 9c95b5cdc8..5f210bad61 100644 --- a/packages/plugin-github/tests/index.snap.js +++ b/packages/plugin-github/tests/index.snap.js @@ -4,7 +4,7 @@ URL: https://github.com/koishijs/koishi/commit/bff469eabe14d42683a4f7c3ccb659dae This will introduce a failure in test.` module.exports[`fork`] = ` -[GitHub] jjyyxx forked koishijs/koishi to jjyyxx/koishi` +[GitHub] jjyyxx forked koishijs/koishi to jjyyxx/koishi (total 12 forks)` module.exports[`issue_comment.created.1`] = ` [GitHub] simon300000 commented on issue koishijs/koishi#19 @@ -51,3 +51,6 @@ Compare: https://github.com/koishijs/koishi/compare/976c6e8f09a4...3ae7e7044d06 module.exports[`push.tag`] = ` [GitHub] Shigma published tag koishijs/koishi@1.5.0` + +module.exports[`star.created`] = ` +[GitHub] 275761919 starred koishijs/koishi (total 189 stargazers)`