Introduction#
Creating Pull Requests often requires context switching - leaving Slack, opening GitHub, navigating to the right repo, and filling out forms. This tutorial shows you how to create PRs directly from Slack using a simple slash command.
Prerequisites#
- An n8n instance with a public webhook URL
- GitHub Personal Access Token with
reposcope - Slack workspace with permission to create slash commands
- A repository you want to create PRs for
Workflow Overview#
| |
Step-by-Step Setup#
Step 1: Create the n8n Webhook#
- Add a Webhook node to your canvas
- Set HTTP Method to
POST - Set path to
slack-pr-create - Set Response Mode to
Respond to Webhook - Copy the webhook URL - you’ll need it for Slack
Step 2: Create Slack Slash Command#
- Go to api.slack.com/apps
- Create a new app or select existing
- Go to Slash Commands → Create New Command
- Configure:
- Command:
/createpr - Request URL: Your n8n webhook URL
- Description: “Create a GitHub PR”
- Usage Hint:
[branch] [title]
- Command:
- Install the app to your workspace
Step 3: Parse the Slack Command#
Add a Set node to parse the incoming Slack payload:
| |
Step 4: Create the Pull Request#
Add an HTTP Request node to call GitHub’s API:
URL:
| |
Method: POST
Headers:
| |
Body:
| |
Step 5: Respond to Slack#
Add a Respond to Webhook node:
| |
Usage#
In any Slack channel:
| |
This creates a PR from feature-login branch to main with the title “Add user authentication”.
Enhanced Features#
Support Multiple Repositories#
Parse the repo from the command:
| |
Add PR Labels#
Include labels in the GitHub API call:
| |
Request Reviewers#
Auto-assign reviewers:
| |
Error Handling#
Add an IF node after the GitHub request to check for errors:
| |
On error, respond with helpful message:
| |
Security Considerations#
- Validate Slack requests - Verify the request signature
- Limit users - Check
user_idagainst an allowed list - Restrict repos - Only allow PRs to specific repositories
- Use environment variables - Never hardcode tokens
Troubleshooting#
“Branch not found” Error#
- Ensure the branch is pushed to remote
- Check branch name spelling
Slack Command Timeout#
- Slack expects response within 3 seconds
- Use async processing for slow operations
Permission Denied#
- Verify GitHub token has
reposcope - Check you have write access to the repository
Conclusion#
Creating PRs from Slack removes friction from your development workflow. Team members can quickly create PRs without context switching, and the conversation stays in Slack for easy reference.
Download the complete workflow from our n8n Workflow Gallery.
