Skip to content

Commit

Permalink
feat(github): support issue/pr close event
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Sep 4, 2020
1 parent 96e5ed0 commit a56c843
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
28 changes: 27 additions & 1 deletion packages/plugin-github/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function addListeners(on: <T extends EventNames.All>(event: T, handler: E
const { full_name } = repository
const { user, url, html_url, commit_id, body, path, position } = comment
if (user.type === 'bot') return

return [[
`[GitHub] ${user.login} commented on commit ${full_name}@${commit_id.slice(0, 6)}`,
`Path: ${path}`,
Expand Down Expand Up @@ -73,6 +74,18 @@ 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

return [`[GitHub] ${user.login} closed issue ${full_name}#${number}\n${title}`, {
link: html_url,
react: url + `/reactions`,
reply: [comments_url],
}]
})

on('pull_request_review_comment.created', ({ repository, comment, pull_request }) => {
const { full_name } = repository
const { number } = pull_request
Expand Down Expand Up @@ -102,16 +115,29 @@ export function addListeners(on: <T extends EventNames.All>(event: T, handler: E
].join('\n'), { link: html_url, reply: [comments_url] }]
})

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

return [`[GitHub] ${user.login} closed pull request ${full_name}#${number}\n${title}`, {
link: html_url,
react: issue_url + '/reactions',
reply: [comments_url],
}]
})

on('pull_request.opened', ({ repository, pull_request }) => {
const { full_name, owner } = repository
const { user, html_url, issue_url, comments_url, base, head, body, number } = pull_request
const { user, html_url, issue_url, comments_url, title, base, head, body, number } = pull_request
if (user.type === 'bot') return

const prefix = new RegExp(`^${owner.login}:`)
const baseLabel = base.label.replace(prefix, '')
const headLabel = head.label.replace(prefix, '')
return [[
`[GitHub] ${user.login} opened a pull request ${full_name}#${number} (${baseLabel} <- ${headLabel})`,
`Title: ${title}`,
formatMarkdown(body),
].join('\n'), {
link: html_url,
Expand Down
10 changes: 10 additions & 0 deletions packages/plugin-github/tests/index.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,30 @@ module.exports[`issue_comment.created.2`] = `
[GitHub] Kouchya commented on pull request koishijs/koishi#20
C'est important!`

module.exports['issues.closed'] = `
[GitHub] simon300000 closed issue koishijs/koishi#19
Wie kann man um das Koishi zu installieren?`

// URL: https://github.com/koishijs/koishi/issues/19
module.exports[`issues.opened`] = `
[GitHub] simon300000 opened an issue koishijs/koishi#19
Title: Wie kann man um das Koishi zu installieren?
Ich verstecke Englisch und Chinesisch nicht! Gab es Personen, die mir helfen kann?`

module.exports['pull_request.closed'] = `
[GitHub] Shigma closed pull request koishijs/koishi#97
Storage API, fix #96`

// URL: https://github.com/koishijs/koishi/pull/20
module.exports[`pull_request.opened.1`] = `
[GitHub] simon300000 opened a pull request koishijs/koishi#20 (develop <- experimental)
Title: test: add experimental shouldMatchSnapshot
Das ist wichtig!`

// URL: https://github.com/koishijs/koishi/pull/90
module.exports[`pull_request.opened.2`] = `
[GitHub] jjyyxx opened a pull request koishijs/koishi#90 (mapping <- jjyyxx:mapping)
Title: test: fix path mapping
According to \`tsconfig-paths\` documentation ...`

// URL: https://github.com/koishijs/koishi/pull/20#pullrequestreview-345349537
Expand Down

0 comments on commit a56c843

Please sign in to comment.