Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/clipcrow/pr2slack
This Bot will notify pull-request events to your Slack channel.
https://github.com/clipcrow/pr2slack
bot deno deno-deploy deno-kv github pull-request slack
Last synced: about 21 hours ago
JSON representation
This Bot will notify pull-request events to your Slack channel.
- Host: GitHub
- URL: https://github.com/clipcrow/pr2slack
- Owner: clipcrow
- License: mit
- Created: 2023-11-05T06:30:14.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-06T02:56:43.000Z (6 months ago)
- Last Synced: 2024-08-06T05:58:32.892Z (6 months ago)
- Topics: bot, deno, deno-deploy, deno-kv, github, pull-request, slack
- Language: TypeScript
- Homepage:
- Size: 117 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Support: supportRouter.ts
Awesome Lists containing this project
README
# pr2slack
This will notify pull-request events to your Slack channel.
## Requirements
Notify the pull request reviewer that a review request is coming, Notify the
pull request author as soon as the reviewer completes the approval.- Post a message to Slack when a particular user is added as a reviewer to a
pull request
- Update messages already posted at the following events
- Yet another specific user is added as a reviewer
- Reviewer completes review
- Pull requests are merged
- The update history is threaded to the message
- Mention the Slack account of the target GitHub user## How to implement
This system is designed to be hosted on Deno Deploy.
Posting to Slack uses the Slack Block API to create a dialog-like appearance.
Use Slack's metadata API to find messages to update. In this way, the channel is
not wasted. Fortunately, pull requests have a unique number, so I can simply use
that as my search key.GraphQL(GitHub v4) was used as the method for acquiring detailed data of pull
request. It was very convenient because it took less effort than the REST
API(GitHub v3).Store the bot token needed to use the Slack API in Deno Deploy Secrets. The
Slack channel ID, Slack and Github account pair, will be stored in Deno KV.Holds a token for operating GitHub in Deno Deploy Secrets too.
- serve.ts: The API server.
- createContext.ts: Adjust the JSON of the received webhook.
- postNotification.ts:
- getActualGraph.ts: GraphQL
- renderer.tsx: [jsx-slack](https://github.com/yhatt/jsx-slack)## handle event of GitHub via webhook
- Event > Activity Type
- **pull_request**
- opened
- Even if a review request is made at the same time as the PR opens, the
events will occur separately.
- **closed**
- When a pull request merges, the `pull_request` is automatically
`closed`.
- with a conditional that checks the `merged` value of the event. also
`merged_by`.
- edited
- reopened
- I don't know...
- **review_requested**
- see `payload.requested_reviewer`.
- **review_request_removed**
- see `payload.requested_reviewer`.
- **pull_request_review**
- **submitted**
- when a pull request has been approved
- check the `payload.review.state`, state == `approved` then PR was
approved.
- dismissed
- Change the state of the review, but not the state of the PR.
- pull_request_review_comment
- created## Call Slack API
- **views.open**, **views.update**
- scope: No scope required
- **chat.postMessage**, **chat.update**
- scope: `chat:write`
- **conversations.history**
- scope: `channels:history`, `groups:history`, `im:history`, `mpim:history`
- Slash command
- scope: `commands`### Deno Deploy Secrets settings
- GITHUB_TOKEN: GitHub personal access token (classic)
- for example, `ghp_abcdefghijklmnopqrstuvwxyz0123456789`
- SLACK_TOKEN: Slack Bot token with scopes as above.
- for example, `xoxb-1234567890123-1234567890123-abcdefghijklmnopqrstuvwx`