Contents

Creating GitHub PRs from Slack with n8n

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.
  • 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
Slack Slash Command → n8n Webhook → Parse Command → Create GitHub PR → Respond to Slack
  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
  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

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
};

Add an HTTP Request node to call GitHub’s API:

URL:

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

Method: POST

Headers:

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

Body:

{
  "title": "{{ $json.title }}",
  "body": "Created via Slack by @{{ $json.user }}",
  "head": "{{ $json.branch }}",
  "base": "main"
}

Add a Respond to Webhook node:

{
  "response_type": "in_channel",
  "text": "✅ PR Created: {{ $json.html_url }}"
}

In any Slack channel:

/createpr feature-login Add user authentication

This creates a PR from feature-login branch to main with the title “Add user authentication”.

Parse the repo from the command:

/createpr myorg/myrepo feature-branch PR Title

Include labels in the GitHub API call:

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

Auto-assign reviewers:

{
  "title": "{{ $json.title }}",
  "reviewers": ["teammate1", "teammate2"]
}

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."
}
  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
  • Ensure the branch is pushed to remote
  • Check branch name spelling
  • Slack expects response within 3 seconds
  • Use async processing for slow operations
  • Verify GitHub token has repo scope
  • Check you have write access to the repository

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.