From 9998245f8976ab78a6504d874439aa0ca1444bbc Mon Sep 17 00:00:00 2001 From: trumanfolkersTZ Date: Mon, 8 Jun 2026 15:01:32 -0500 Subject: [PATCH 1/4] fix: making shared slack logic (just have to put slack_channel_id as a github var inside repo) --- .github/workflows/shared-slack-logic.yml | 46 ++++++++++++++++++++++++ workflow-templates/slack-react.yml | 40 +++------------------ 2 files changed, 50 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/shared-slack-logic.yml diff --git a/.github/workflows/shared-slack-logic.yml b/.github/workflows/shared-slack-logic.yml new file mode 100644 index 0000000..2cf2d32 --- /dev/null +++ b/.github/workflows/shared-slack-logic.yml @@ -0,0 +1,46 @@ +name: Slack Auto-React (Approval & Merge) + +on: + workflow_call: + pull_request: + types: [closed] + pull_request_review: + types: [submitted] + +jobs: + auto_react: + if: | + (github.event_name == 'pull_request' && github.event.pull_request.merged == true) || + (github.event_name == 'pull_request_review' && github.event.review.state == 'approved') + + runs-on: ubuntu-latest + + steps: + - name: Search and React to Slack Message + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + SLACK_CHANNEL_ID: ${{ vars.SLACK_CHANNEL_ID }} + PR_URL: ${{ github.event.pull_request.html_url }} + EMOJI: ${{ github.event_name == 'pull_request' && 'git-merged' || 'white_check_mark' }} + run: | + HISTORY=$(curl -s -X GET \ + -H "Authorization: Bearer $SLACK_BOT_TOKEN" \ + "https://slack.com/api/conversations.history?channel=$SLACK_CHANNEL_ID&limit=100") + + if [ "$(echo "$HISTORY" | jq -r '.ok')" != "true" ]; then + echo "Slack API Error: $(echo "$HISTORY" | jq -r '.error')" + exit 1 + fi + + TS=$(echo "$HISTORY" | jq -r --arg URL "$PR_URL" '.messages[]? | select(.text | contains($URL)) | .ts' | head -n 1) + + if [ -n "$TS" ] && [ "$TS" != "null" ]; then + echo "Found matching message (TS: $TS). Adding :$EMOJI: reaction..." + curl -s -X POST \ + -H "Authorization: Bearer $SLACK_BOT_TOKEN" \ + -H "Content-Type: application/json; charset=utf-8" \ + -d "{\"channel\":\"$SLACK_CHANNEL_ID\",\"timestamp\":\"$TS\",\"name\":\"$EMOJI\"}" \ + https://slack.com/api/reactions.add > /dev/null + else + echo "No matching Slack message found for PR: $PR_URL" + fi \ No newline at end of file diff --git a/workflow-templates/slack-react.yml b/workflow-templates/slack-react.yml index ffba3b9..a74ef83 100644 --- a/workflow-templates/slack-react.yml +++ b/workflow-templates/slack-react.yml @@ -7,39 +7,7 @@ on: types: [submitted] jobs: - auto_react: - if: | - (github.event_name == 'pull_request' && github.event.pull_request.merged == true) || - (github.event_name == 'pull_request_review' && github.event.review.state == 'approved') - - runs-on: ubuntu-latest - - steps: - - name: Search and React to Slack Message - env: - SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} - SLACK_CHANNEL_ID: "YOUR_SLACK_CHANNEL_ID_HERE" - PR_URL: ${{ github.event.pull_request.html_url }} - EMOJI: ${{ github.event_name == 'pull_request' && 'git-merged' || 'white_check_mark' }} - run: | - HISTORY=$(curl -s -X GET \ - -H "Authorization: Bearer $SLACK_BOT_TOKEN" \ - "https://slack.com/api/conversations.history?channel=$SLACK_CHANNEL_ID&limit=100") - - if [ "$(echo "$HISTORY" | jq -r '.ok')" != "true" ]; then - echo "Slack API Error: $(echo "$HISTORY" | jq -r '.error')" - exit 1 - fi - - TS=$(echo "$HISTORY" | jq -r --arg URL "$PR_URL" '.messages[]? | select(.text | contains($URL)) | .ts' | head -n 1) - - if [ -n "$TS" ] && [ "$TS" != "null" ]; then - echo "Found matching message (TS: $TS). Adding :$EMOJI: reaction..." - curl -s -X POST \ - -H "Authorization: Bearer $SLACK_BOT_TOKEN" \ - -H "Content-Type: application/json; charset=utf-8" \ - -d "{\"channel\":\"$SLACK_CHANNEL_ID\",\"timestamp\":\"$TS\",\"name\":\"$EMOJI\"}" \ - https://slack.com/api/reactions.add > /dev/null - else - echo "No matching Slack message found for PR: $PR_URL" - fi \ No newline at end of file + trigger-slack-reaction: + #pointer to shared logic + uses: tractorzoom/.github/.github/workflows/shared-slack-logic.yml@main + secrets: inherit \ No newline at end of file From 7e24c8b285304f1fbcf22c06c2012df6be31ff97 Mon Sep 17 00:00:00 2001 From: trumanfolkersTZ Date: Tue, 9 Jun 2026 08:15:09 -0500 Subject: [PATCH 2/4] moving logic to shared with input channel id --- .github/workflows/shared-slack-logic.yml | 6 +++++- workflow-templates/slack-react.yml | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/shared-slack-logic.yml b/.github/workflows/shared-slack-logic.yml index 2cf2d32..f6e62bd 100644 --- a/.github/workflows/shared-slack-logic.yml +++ b/.github/workflows/shared-slack-logic.yml @@ -2,6 +2,10 @@ name: Slack Auto-React (Approval & Merge) on: workflow_call: + inputs: + SLACK_CHANNEL_ID: + required: true + type: string pull_request: types: [closed] pull_request_review: @@ -19,7 +23,7 @@ jobs: - name: Search and React to Slack Message env: SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} - SLACK_CHANNEL_ID: ${{ vars.SLACK_CHANNEL_ID }} + SLACK_CHANNEL_ID: ${{ inputs.SLACK_CHANNEL_ID }} PR_URL: ${{ github.event.pull_request.html_url }} EMOJI: ${{ github.event_name == 'pull_request' && 'git-merged' || 'white_check_mark' }} run: | diff --git a/workflow-templates/slack-react.yml b/workflow-templates/slack-react.yml index a74ef83..9739110 100644 --- a/workflow-templates/slack-react.yml +++ b/workflow-templates/slack-react.yml @@ -1,4 +1,4 @@ -name: Slack Auto-React (Approval & Merge) +name: Slack Auto-React on: pull_request: @@ -8,6 +8,7 @@ on: jobs: trigger-slack-reaction: - #pointer to shared logic uses: tractorzoom/.github/.github/workflows/shared-slack-logic.yml@main + with: + SLACK_CHANNEL_ID: "C0906CYECPP" secrets: inherit \ No newline at end of file From 3719bdce21732693388bdd72ed1ff598344f4296 Mon Sep 17 00:00:00 2001 From: trumanfolkersTZ Date: Tue, 9 Jun 2026 08:22:04 -0500 Subject: [PATCH 3/4] taking out trigger logic from shared file --- .github/workflows/shared-slack-logic.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/shared-slack-logic.yml b/.github/workflows/shared-slack-logic.yml index f6e62bd..79fb36c 100644 --- a/.github/workflows/shared-slack-logic.yml +++ b/.github/workflows/shared-slack-logic.yml @@ -6,10 +6,6 @@ on: SLACK_CHANNEL_ID: required: true type: string - pull_request: - types: [closed] - pull_request_review: - types: [submitted] jobs: auto_react: From da8e930d06a16cdbb7e0c7ecb01162c4645c5f99 Mon Sep 17 00:00:00 2001 From: trumanfolkersTZ Date: Tue, 9 Jun 2026 08:26:15 -0500 Subject: [PATCH 4/4] adding filler word --- workflow-templates/slack-react.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workflow-templates/slack-react.yml b/workflow-templates/slack-react.yml index 9739110..9c95978 100644 --- a/workflow-templates/slack-react.yml +++ b/workflow-templates/slack-react.yml @@ -10,5 +10,5 @@ jobs: trigger-slack-reaction: uses: tractorzoom/.github/.github/workflows/shared-slack-logic.yml@main with: - SLACK_CHANNEL_ID: "C0906CYECPP" + SLACK_CHANNEL_ID: "SLACK_CHANNEL_ID_HERE" secrets: inherit \ No newline at end of file