Skip to content

Instantly share code, notes, and snippets.

@logesh45
Created October 27, 2026 22:12
Show Gist options
  • Select an option

  • Save logesh45/4ebe50e5292a0b4bfa18334dcb63b8a1 to your computer and use it in GitHub Desktop.

Select an option

Save logesh45/4ebe50e5292a0b4bfa18334dcb63b8a1 to your computer and use it in GitHub Desktop.
Custom PR Assigner with Slack Webhook (GitHub Actions)
name: Custom PR Assigner with Slack Webhook
on:
pull_request:
types: [opened, ready_for_review]
jobs:
assign-and-notify:
runs-on: ubuntu-latest
steps:
# Step 1: Check out your repository code
- name: Checkout repository
uses: actions/checkout@v4
# Step 2: Custom JavaScript to select reviewers from pools
- name: Select Reviewers via Script
id: pick_reviewers
uses: actions/github-script@v7
with:
script: |
// 1. Map your team pools (GitHub Handle : Slack Member ID)
const corePool = {
"alice-gh": "U11111111",
"bob-gh": "U22222222",
"charlie-gh": "U33333333"
};
const teamPool = {
"david-gh": "U44444444",
"emma-gh": "U55555555",
"frank-gh": "U66666666"
};
const prAuthor = context.payload.pull_request.user.login;
// 2. Helper function to filter out the PR author and pick a random reviewer
function getRandomReviewer(pool) {
const candidates = Object.keys(pool).filter(user => user !== prAuthor);
if (candidates.length === 0) {
const defaultKey = Object.keys(pool)[0];
return { github: defaultKey, slack: pool[defaultKey] };
}
const chosenGit = candidates[Math.floor(Math.random() * candidates.length)];
return { github: chosenGit, slack: pool[chosenGit] };
}
const chosenCore = getRandomReviewer(corePool);
const chosenTeam = getRandomReviewer(teamPool);
// 3. Call GitHub API to request them as official reviewers
await github.rest.pulls.requestReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
reviewers: [chosenCore.github, chosenTeam.github]
});
// 4. Output the Slack IDs so the Webhook step can read them
core.setOutput('core_slack_id', chosenCore.slack);
core.setOutput('team_slack_id', chosenTeam.slack);
# Step 3: Send Notification using your Slack Webhook URL
- name: Send Slack Webhook Notification
uses: slackapi/slack-github-action@v2.0.0
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
{
"text": "🚀 *New PR:* <${{ github.event.pull_request.html_url }}|${{ github.event.pull_request.title }}> by ${{ github.actor }}\n• Core Reviewer: <@${{ steps.pick_reviewers.outputs.core_slack_id }}>\n• Team Reviewer: <@${{ steps.pick_reviewers.outputs.team_slack_id }}>"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment