Creating GitHub PRs from Slack with n8n
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
Slack Slash Command → n8n Webhook → Parse Command → Create GitHub PR → Respond to SlackStep-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:
// The text field contains: "feature-branch My PR Title"
const parts = $json.text.split(' ');
const branch = parts[0];
const title = parts.slice(1).join(' ');
return {
branch: branch,
title: title,
user: $json.user_name,
channel: $json.channel_name
};Step 4: Create the Pull Request
Add an HTTP Request node to call GitHub’s API:
URL:
https://api.github.com/repos/YOUR_ORG/YOUR_REPO/pullsMethod: POST
Headers:
Authorization: Bearer YOUR_GITHUB_TOKEN
Accept: application/vnd.github.v3+jsonBody:
{
"title": "{{ $json.title }}",
"body": "Created via Slack by @{{ $json.user }}",
"head": "{{ $json.branch }}",
"base": "main"
}Step 5: Respond to Slack
Add a Respond to Webhook node:
{
"response_type": "in_channel",
"text": "✅ PR Created: {{ $json.html_url }}"
}Usage
In any Slack channel:
/createpr feature-login Add user authenticationThis 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:
/createpr myorg/myrepo feature-branch PR TitleAdd PR Labels
Include labels in the GitHub API call:
{
"title": "{{ $json.title }}",
"labels": ["from-slack", "needs-review"]
}Request Reviewers
Auto-assign reviewers:
{
"title": "{{ $json.title }}",
"reviewers": ["teammate1", "teammate2"]
}Error Handling
Add an IF node after the GitHub request to check for errors:
// Check if PR was created successfully
return $json.html_url ? true : false;On error, respond with helpful message:
{
"response_type": "ephemeral",
"text": "❌ Failed to create PR. Check that the branch exists and you have permissions."
}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.