From 29b25d7bcf9f9191834efa160d89e70cd8649cd6 Mon Sep 17 00:00:00 2001 From: Pedro Altomar Date: Mon, 22 Jun 2026 12:13:51 +0200 Subject: [PATCH 1/2] Add Slack PR notification workflows --- .github/workflows/pr-closed-notify-slack.yml | 42 ++++++++ .../workflows/pr-in-review-notify-slack.yml | 72 ++++++++++++++ .github/workflows/pr-opened-notify-slack.yml | 96 +++++++++++++++++++ 3 files changed, 210 insertions(+) create mode 100644 .github/workflows/pr-closed-notify-slack.yml create mode 100644 .github/workflows/pr-in-review-notify-slack.yml create mode 100644 .github/workflows/pr-opened-notify-slack.yml diff --git a/.github/workflows/pr-closed-notify-slack.yml b/.github/workflows/pr-closed-notify-slack.yml new file mode 100644 index 0000000..1c136c4 --- /dev/null +++ b/.github/workflows/pr-closed-notify-slack.yml @@ -0,0 +1,42 @@ +name: PR Closed — Notify Slack + +on: + pull_request: + types: [closed] + +permissions: + pull-requests: read + +jobs: + notify: + runs-on: ubuntu-latest + if: | + !contains(github.event.pull_request.labels.*.name, 'dependencies') && + github.event.pull_request.user.type != 'Bot' + + steps: + - name: Post to Slack + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_PR_CLOSED_WEBHOOK_URL }} + PR_URL: ${{ github.event.pull_request.html_url }} + PR_STATUS: ${{ github.event.pull_request.merged == true && 'merged' || 'closed' }} + run: | + PAYLOAD=$(jq -n \ + --arg pr_url "$PR_URL" \ + --arg pr_status "$PR_STATUS" \ + '{ + pr_url: $pr_url, + pr_status: $pr_status, + }') + + HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \ + --connect-timeout 10 \ + --max-time 30 \ + -X POST "$SLACK_WEBHOOK_URL" \ + -H 'Content-Type: application/json' \ + -d "$PAYLOAD") + + if [ "$HTTP_STATUS" != "200" ]; then + echo "::error::Slack webhook failed (HTTP $HTTP_STATUS)" + exit 1 + fi diff --git a/.github/workflows/pr-in-review-notify-slack.yml b/.github/workflows/pr-in-review-notify-slack.yml new file mode 100644 index 0000000..b34a00b --- /dev/null +++ b/.github/workflows/pr-in-review-notify-slack.yml @@ -0,0 +1,72 @@ +name: PR In Review — Notify Slack + +on: + pull_request: + types: [review_requested] + pull_request_review: + types: [submitted] + +permissions: + pull-requests: read + +jobs: + notify: + runs-on: ubuntu-latest + if: | + !github.event.pull_request.draft && + !contains(github.event.pull_request.labels.*.name, 'dependencies') && + github.event.requested_reviewer.type != 'Bot' && + github.event.review.user.type != 'Bot' + + steps: + - name: Resolve PR reviewer → Slack user ID + id: slack + env: + EVENT_NAME: ${{ github.event_name }} + GITHUB_USER_REQUESTED: ${{ github.event.requested_reviewer.login }} + GITHUB_USER_REVIEWED: ${{ github.event.review.user.login }} + GITHUB_TO_SLACK: ${{ vars.SLACK_TO_GITHUB }} + run: | + if [ "$EVENT_NAME" = "pull_request" ]; then + GITHUB_USER="$GITHUB_USER_REQUESTED" + else + GITHUB_USER="$GITHUB_USER_REVIEWED" + fi + + SLACK_ID=$(echo "$GITHUB_TO_SLACK" | jq -r --arg user "$GITHUB_USER" \ + '.[] | select(.github == $user) | .slack') + + if [ -z "$SLACK_ID" ]; then + echo "::warning::GitHub user '$GITHUB_USER' not found in SLACK_TO_GITHUB variable. Posting without Slack mention." + fi + + echo "user_id=$SLACK_ID" >> $GITHUB_OUTPUT + + - name: Post to Slack + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_PR_REVIEW_WEBHOOK_URL }} + PR_URL: ${{ github.event.pull_request.html_url }} + PR_STATUS: ${{ github.event_name == 'pull_request' && 'review_requested' || github.event.review.state }} + SLACK_USER_ID: ${{ steps.slack.outputs.user_id }} + run: | + PAYLOAD=$(jq -n \ + --arg pr_url "$PR_URL" \ + --arg pr_status "$PR_STATUS" \ + --arg pr_reviewer "$SLACK_USER_ID" \ + '{ + pr_url: $pr_url, + pr_status: $pr_status, + pr_reviewer: $pr_reviewer, + }') + + HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \ + --connect-timeout 10 \ + --max-time 30 \ + -X POST "$SLACK_WEBHOOK_URL" \ + -H 'Content-Type: application/json' \ + -d "$PAYLOAD") + + if [ "$HTTP_STATUS" != "200" ]; then + echo "::error::Slack webhook failed (HTTP $HTTP_STATUS)" + exit 1 + fi diff --git a/.github/workflows/pr-opened-notify-slack.yml b/.github/workflows/pr-opened-notify-slack.yml new file mode 100644 index 0000000..417f014 --- /dev/null +++ b/.github/workflows/pr-opened-notify-slack.yml @@ -0,0 +1,96 @@ +name: PR Opened — Notify Slack + +on: + pull_request: + types: [ready_for_review, opened] + +# Minimum permissions needed +permissions: + pull-requests: read + +jobs: + notify: + runs-on: ubuntu-latest + # Skip draft PRs and dependency bumps + if: | + !github.event.pull_request.draft && + !contains(github.event.pull_request.labels.*.name, 'dependencies') && + !contains(github.event.pull_request.labels.*.name, 'ignore-for-release') && + github.event.pull_request.user.type != 'Bot' + + steps: + - name: Extract Jira key + id: jira + env: + BRANCH: ${{ github.event.pull_request.head.ref }} + PR_BODY: ${{ github.event.pull_request.body }} + run: | + # Try branch name first (RACK-XXXX-feature-description) + JIRA_KEY=$(echo "$BRANCH" | grep -oP 'RACK-\d+' | head -1) + + # Fallback: scan PR body (template reminder at the bottom) + if [ -z "$JIRA_KEY" ]; then + JIRA_KEY=$(echo "$PR_BODY" | grep -oP 'RACK-\d+' | head -1) + fi + + echo "key=$JIRA_KEY" >> $GITHUB_OUTPUT + + - name: Resolve PR creator → Slack user ID + id: slack + env: + GITHUB_USER: ${{ github.event.pull_request.user.login }} + GITHUB_TO_SLACK: ${{ vars.SLACK_TO_GITHUB }} + run: | + SLACK_ID=$(echo "$GITHUB_TO_SLACK" | jq -r --arg user "$GITHUB_USER" \ + '.[] | select(.github == $user) | .slack') + + if [ -z "$SLACK_ID" ]; then + echo "::warning::GitHub user '$GITHUB_USER' not found in SLACK_TO_GITHUB variable. Posting without Slack mention." + fi + + echo "user_id=$SLACK_ID" >> $GITHUB_OUTPUT + + - name: Post to Slack + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_PR_OPENED_WEBHOOK_URL }} + REPO_NAME: ${{ github.event.repository.name }} + PR_TITLE: ${{ github.event.pull_request.title }} + PR_BODY: ${{ github.event.pull_request.body }} + PR_NUMBER: ${{ github.event.pull_request.number }} + PR_URL: ${{ github.event.pull_request.html_url }} + SLACK_USER_ID: ${{ steps.slack.outputs.user_id }} + JIRA_KEY: ${{ steps.jira.outputs.key }} + run: | + JIRA_ISSUE_URL="${JIRA_KEY:+https://vismarackbeat.atlassian.net/browse/$JIRA_KEY}" + + PAYLOAD=$(jq -n \ + --arg repo_name "$REPO_NAME" \ + --arg pr_title "$PR_TITLE" \ + --arg pr_body "$PR_BODY" \ + --arg pr_number "$PR_NUMBER" \ + --arg pr_url "$PR_URL" \ + --arg pr_creator "$SLACK_USER_ID" \ + --arg jira_key "$JIRA_KEY" \ + --arg jira_issue_url "$JIRA_ISSUE_URL" \ + '{ + repo_name: $repo_name, + pr_title: $pr_title, + pr_body: $pr_body, + pr_number: $pr_number, + pr_url: $pr_url, + pr_creator: $pr_creator, + jira_key: $jira_key, + jira_issue_url: $jira_issue_url, + }') + + HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \ + --connect-timeout 10 \ + --max-time 30 \ + -X POST "$SLACK_WEBHOOK_URL" \ + -H 'Content-Type: application/json' \ + -d "$PAYLOAD") + + if [ "$HTTP_STATUS" != "200" ]; then + echo "::error::Slack webhook failed (HTTP $HTTP_STATUS)" + exit 1 + fi From 3500a44c557b61c9a5f1e87bce67f266405a158b Mon Sep 17 00:00:00 2001 From: Pedro Altomar Date: Mon, 22 Jun 2026 12:31:13 +0200 Subject: [PATCH 2/2] Add ignore-for-release check to pr-closed and pr-in-review workflows --- .github/workflows/pr-closed-notify-slack.yml | 1 + .github/workflows/pr-in-review-notify-slack.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/pr-closed-notify-slack.yml b/.github/workflows/pr-closed-notify-slack.yml index 1c136c4..3f86e4d 100644 --- a/.github/workflows/pr-closed-notify-slack.yml +++ b/.github/workflows/pr-closed-notify-slack.yml @@ -12,6 +12,7 @@ jobs: runs-on: ubuntu-latest if: | !contains(github.event.pull_request.labels.*.name, 'dependencies') && + !contains(github.event.pull_request.labels.*.name, 'ignore-for-release') && github.event.pull_request.user.type != 'Bot' steps: diff --git a/.github/workflows/pr-in-review-notify-slack.yml b/.github/workflows/pr-in-review-notify-slack.yml index b34a00b..17dc4ca 100644 --- a/.github/workflows/pr-in-review-notify-slack.yml +++ b/.github/workflows/pr-in-review-notify-slack.yml @@ -15,6 +15,7 @@ jobs: if: | !github.event.pull_request.draft && !contains(github.event.pull_request.labels.*.name, 'dependencies') && + !contains(github.event.pull_request.labels.*.name, 'ignore-for-release') && github.event.requested_reviewer.type != 'Bot' && github.event.review.user.type != 'Bot'