Skip to content

Commit

Permalink
feat(github): support star.created event
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Aug 31, 2020
1 parent feb6698 commit d5bd9bd
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 3 deletions.
8 changes: 6 additions & 2 deletions packages/plugin-github/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)`]
})
}
138 changes: 138 additions & 0 deletions packages/plugin-github/tests/fixtures/star.created.json
Original file line number Diff line number Diff line change
@@ -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
}
}
5 changes: 4 additions & 1 deletion packages/plugin-github/tests/index.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)`

0 comments on commit d5bd9bd

Please sign in to comment.