Public
Like
2
GitHub-PR-Automation
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v22View latest version
This Val Town project sends notifications to Slack when a GitHub pull request is approved, with an optional merge button that appears when all required checks are passing.
-
Create a GitHub Personal Access Token (PAT):
- Go to GitHub → Settings → Developer settings → Personal access tokens → Fine-grained tokens
- Create a new token with these permissions:
- Repository access: Select repositories you want to monitor
- Permissions:
- Pull requests: Read and Write
- Contents: Read and Write (for merging)
- Metadata: Read-only
- Save the token for the next step
-
Set up a GitHub Webhook:
- Go to your repository → Settings → Webhooks → Add webhook
- Payload URL: The URL of this Val (copy after deployment)
- Content type:
application/json - Select "Let me select individual events"
- Check only "Pull request reviews"
- Ensure "Active" is checked
- Click "Add webhook"
-
Create a Slack App:
- Go to Slack API Apps → Create New App → From scratch
- Name your app and select your workspace
- Click "Create App"
-
Enable Interactivity:
- In your Slack app settings, go to "Interactivity & Shortcuts"
- Toggle "Interactivity" to On
- Set the Request URL to the URL of this Val (same as GitHub webhook URL)
- Save Changes
-
Create an Incoming Webhook:
- In your Slack app settings, go to "Incoming Webhooks"
- Toggle "Activate Incoming Webhooks" to On
- Click "Add New Webhook to Workspace"
- Select the channel where notifications should be posted
- Copy the Webhook URL for the next step
-
Add Environment Variables:
- In Val Town, add these environment variables:
GITHUB_TOKEN: Your GitHub Personal Access TokenSLACK_WEBHOOK_URL: Your Slack Incoming Webhook URL
- In Val Town, add these environment variables:
-
Deploy the Val:
- The Val is now ready to use
- Copy the Val's URL to use in the GitHub webhook and Slack interactivity settings
- GitHub sends a webhook event when a PR is reviewed
- This Val filters for approval events
- When an approval is detected, it:
- Fetches detailed PR information
- Checks if the PR is mergeable and all required checks are passing
- Sends a formatted message to Slack
- Includes a merge button if the PR can be merged
- If the merge button is clicked, the Val:
- Receives the interaction from Slack
- Uses the GitHub API to merge the PR
- Sends a confirmation message back to Slack
- No notifications in Slack: Check that the GitHub webhook is properly configured and sending events
- Merge button not appearing: The PR might have failing checks or merge conflicts
- Merge fails: Ensure your GitHub token has sufficient permissions for the repository