Skip to main content

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.

Download the Workflow
Get the ready-to-use workflow from our n8n Workflow Gallery.

Prerequisites
#

  • An n8n instance with a public webhook URL
  • GitHub Personal Access Token with repo scope
  • Slack workspace with permission to create slash commands
  • A repository you want to create PRs for

Workflow Overview
#

1
Slack Slash Command → n8n Webhook → Parse Command → Create GitHub PR → Respond to Slack

Step-by-Step Setup
#

Step 1: Create the n8n Webhook
#

  1. Add a Webhook node to your canvas
  2. Set HTTP Method to POST
  3. Set path to slack-pr-create
  4. Set Response Mode to Respond to Webhook
  5. Copy the webhook URL - you’ll need it for Slack

Step 2: Create Slack Slash Command
#

  1. Go to api.slack.com/apps
  2. Create a new app or select existing
  3. Go to Slash CommandsCreate New Command
  4. Configure:
    • Command: /createpr
    • Request URL: Your n8n webhook URL
    • Description: “Create a GitHub PR”
    • Usage Hint: [branch] [title]
  5. Install the app to your workspace

Step 3: Parse the Slack Command
#

Add a Set node to parse the incoming Slack payload:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
// 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:

1
https://api.github.com/repos/YOUR_ORG/YOUR_REPO/pulls

Method: POST

Headers:

1
2
Authorization: Bearer YOUR_GITHUB_TOKEN
Accept: application/vnd.github.v3+json

Body:

1
2
3
4
5
6
{
  "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:

1
2
3
4
{
  "response_type": "in_channel",
  "text": "✅ PR Created: {{ $json.html_url }}"
}

Usage
#

In any Slack channel:

1
/createpr feature-login Add user authentication

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:

1
/createpr myorg/myrepo feature-branch PR Title

Add PR Labels
#

Include labels in the GitHub API call:

1
2
3
4
{
  "title": "{{ $json.title }}",
  "labels": ["from-slack", "needs-review"]
}

Request Reviewers
#

Auto-assign reviewers:

1
2
3
4
{
  "title": "{{ $json.title }}",
  "reviewers": ["teammate1", "teammate2"]
}

Error Handling
#

Add an IF node after the GitHub request to check for errors:

1
2
// Check if PR was created successfully
return $json.html_url ? true : false;

On error, respond with helpful message:

1
2
3
4
{
  "response_type": "ephemeral",
  "text": "❌ Failed to create PR. Check that the branch exists and you have permissions."
}

Security Considerations
#

  1. Validate Slack requests - Verify the request signature
  2. Limit users - Check user_id against an allowed list
  3. Restrict repos - Only allow PRs to specific repositories
  4. 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 repo scope
  • 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.