From d22c3074b745a07474a7dc1e06dd58908994bf37 Mon Sep 17 00:00:00 2001 From: Dan Finn Date: Tue, 27 Jan 2026 11:31:37 -0500 Subject: [PATCH 1/7] clean up merge reaction --- .github/workflows/slack-merge-reaction.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/slack-merge-reaction.yml diff --git a/.github/workflows/slack-merge-reaction.yml b/.github/workflows/slack-merge-reaction.yml new file mode 100644 index 0000000..8c71d8b --- /dev/null +++ b/.github/workflows/slack-merge-reaction.yml @@ -0,0 +1,18 @@ +name: Add Slack Merge Reaction + +on: + pull_request: + types: [closed] + +jobs: + add-merge-reaction: + if: github.event.pull_request.merged == true + uses: digitalocean/docs-automation/.github/workflows/slack-merge-reaction.yml@main + with: + pr_url: ${{ github.event.pull_request.html_url }} + pr_number: ${{ github.event.pull_request.number }} + merged_by: ${{ github.event.pull_request.merged_by.login }} + merge_commit_sha: ${{ github.event.pull_request.merge_commit_sha }} + secrets: + SLACK_BOT_TOKEN: ${{ secrets.PDOCS_SLACK_BOT_TOKEN }} + SLACK_CHANNEL_ID: ${{ secrets.PDOCS_SLACK_CHANNEL_ID }} From 9833157fa320f85b275f2c265b515a4c7cfeda35 Mon Sep 17 00:00:00 2001 From: Dan Finn Date: Wed, 28 Jan 2026 13:55:38 -0500 Subject: [PATCH 2/7] more debugging --- .github/workflows/debug-docs-automation-access.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/debug-docs-automation-access.yml b/.github/workflows/debug-docs-automation-access.yml index 4e6b833..fac9a9e 100644 --- a/.github/workflows/debug-docs-automation-access.yml +++ b/.github/workflows/debug-docs-automation-access.yml @@ -12,8 +12,14 @@ jobs: - name: Check access to docs-automation workflow file env: TARGET_URL: https://api.github.com/repos/digitalocean/docs-automation/contents/.github/workflows/slack-merge-reaction.yml?ref=main + GITHUB_TOKEN: ${{ github.token }} run: | echo "Requesting: $TARGET_URL" + if [ -z "$GITHUB_TOKEN" ]; then + echo "GITHUB_TOKEN is EMPTY" + else + echo "GITHUB_TOKEN length: ${#GITHUB_TOKEN}" + fi STATUS=$(curl -s -o /tmp/resp.json -w "%{http_code}" \ -H "Authorization: Bearer $GITHUB_TOKEN" \ -H "Accept: application/vnd.github+json" \ From fbd3b65bec759ef10b4daece232be1f9744a4559 Mon Sep 17 00:00:00 2001 From: Dan Finn Date: Wed, 28 Jan 2026 15:46:46 -0500 Subject: [PATCH 3/7] Inline slack merge reaction workflow --- .github/workflows/slack-merge-reaction.yml | 100 +++++++++++++++++++-- 1 file changed, 91 insertions(+), 9 deletions(-) diff --git a/.github/workflows/slack-merge-reaction.yml b/.github/workflows/slack-merge-reaction.yml index 24f4d1f..0e2f57d 100644 --- a/.github/workflows/slack-merge-reaction.yml +++ b/.github/workflows/slack-merge-reaction.yml @@ -17,12 +17,94 @@ on: jobs: add-merge-reaction: - uses: digitalocean/docs-automation/.github/workflows/slack-merge-reaction.yml@main - with: - pr_url: ${{ inputs.pr_url || github.event.pull_request.html_url }} - pr_number: ${{ inputs.pr_number || github.event.pull_request.number }} - merged_by: ${{ github.event.pull_request.merged_by.login || 'manual-test' }} - merge_commit_sha: ${{ github.event.pull_request.merge_commit_sha || 'manual-test' }} - secrets: - SLACK_BOT_TOKEN: ${{ secrets.PDOCS_SLACK_BOT_TOKEN }} - SLACK_CHANNEL_ID: ${{ secrets.PDOCS_SLACK_CHANNEL_ID }} + if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' + runs-on: ubuntu-latest + steps: + - name: Log merge info + env: + PR_URL: ${{ inputs.pr_url || github.event.pull_request.html_url }} + PR_NUMBER: ${{ inputs.pr_number || github.event.pull_request.number }} + MERGED_BY: ${{ github.event.pull_request.merged_by.login || 'manual-test' }} + MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha || 'manual-test' }} + run: | + echo "✓ PR #$PR_NUMBER was merged by $MERGED_BY" + echo "✓ Merge commit: $MERGE_SHA" + echo "✓ Searching for: $PR_URL" + + - name: Search Slack and add reaction + env: + SLACK_BOT_TOKEN: ${{ secrets.PDOCS_SLACK_BOT_TOKEN }} + SLACK_CHANNEL_ID: ${{ secrets.PDOCS_SLACK_CHANNEL_ID }} + PR_URL: ${{ inputs.pr_url || github.event.pull_request.html_url }} + run: | + HISTORY_RESPONSE=$(curl -s -X GET "https://slack.com/api/conversations.history" \ + -H "Authorization: Bearer $SLACK_BOT_TOKEN" \ + -G --data-urlencode "channel=$SLACK_CHANNEL_ID" \ + -G --data-urlencode "limit=200") + + if [ "$(echo "$HISTORY_RESPONSE" | jq -r '.ok')" != "true" ]; then + echo "Error: History fetch failed - $(echo "$HISTORY_RESPONSE" | jq -r '.error')" + exit 1 + fi + + MSG_COUNT=$(echo "$HISTORY_RESPONSE" | jq '.messages | length') + echo "Fetched $MSG_COUNT messages from channel" + echo "Searching for PR URL: $PR_URL" + + EARLIEST_MESSAGE=$(echo "$HISTORY_RESPONSE" | jq -r --arg PR_URL "$PR_URL" --arg CHANNEL "$SLACK_CHANNEL_ID" ' + .messages[]? + | . as $msg + | ($msg | tostring | contains($PR_URL)) + | select(.) + | $msg + | {ts: .ts, timestamp: (.ts | tonumber)} + | "\($CHANNEL) \(.ts) \(.timestamp)" + ' | sort -k3 -n | head -n 1) + + if [ -z "$EARLIEST_MESSAGE" ]; then + echo "::warning::No messages found containing the PR URL" + if echo "$HISTORY_RESPONSE" | grep -q "$PR_URL"; then + echo "URL found in raw response but jq didn't match - please report this bug" + else + echo "URL not found in channel history" + echo "Recent PR URLs in channel:" + echo "$HISTORY_RESPONSE" | grep -oE 'https://github.com/[^"<>|]+/pull/[0-9]+' | sort -u | tail -10 + fi + exit 0 + fi + + read -r CHANNEL_ID TIMESTAMP _ <<< "$EARLIEST_MESSAGE" + echo "Found message at timestamp $TIMESTAMP" + + MESSAGE_INFO=$(curl -s -X GET "https://slack.com/api/conversations.history" \ + -H "Authorization: Bearer $SLACK_BOT_TOKEN" \ + -G --data-urlencode "channel=$CHANNEL_ID" \ + --data-urlencode "latest=$TIMESTAMP" \ + --data-urlencode "inclusive=true" \ + --data-urlencode "limit=1") + + HAS_MERGED=$(echo "$MESSAGE_INFO" | jq -r '.messages[0].reactions[]? | select(.name == "pr-merged") | .name') + + if [ "$HAS_MERGED" = "pr-merged" ]; then + echo "Merged reaction already exists, skipping" + exit 0 + fi + + REACTION_RESPONSE=$(curl -s -X POST "https://slack.com/api/reactions.add" \ + -H "Authorization: Bearer $SLACK_BOT_TOKEN" \ + -H "Content-Type: application/json" \ + -d "{ + \"channel\": \"$CHANNEL_ID\", + \"timestamp\": \"$TIMESTAMP\", + \"name\": \"pr-merged\" + }") + + if [ "$(echo "$REACTION_RESPONSE" | jq -r '.ok')" = "true" ]; then + echo "Successfully added pr-merged reaction" + else + ERROR=$(echo "$REACTION_RESPONSE" | jq -r '.error') + echo "Failed to add reaction: $ERROR" + if [ "$ERROR" = "already_reacted" ]; then + echo "Reaction was already added" + fi + fi From c7919d0733d110e568aab426b68378158a446dce Mon Sep 17 00:00:00 2001 From: Dan Finn Date: Wed, 28 Jan 2026 16:09:08 -0500 Subject: [PATCH 4/7] retest with better syntax --- .github/workflows/slack-merge-reaction.yml | 98 +++++++++------------- 1 file changed, 38 insertions(+), 60 deletions(-) diff --git a/.github/workflows/slack-merge-reaction.yml b/.github/workflows/slack-merge-reaction.yml index 0e2f57d..9b91dbb 100644 --- a/.github/workflows/slack-merge-reaction.yml +++ b/.github/workflows/slack-merge-reaction.yml @@ -3,93 +3,75 @@ name: Add Slack Merge Reaction on: pull_request: types: [closed] - # Manual trigger for testing - workflow_dispatch: - inputs: - pr_url: - description: 'PR URL to test (e.g., https://github.com/digitalocean/vale-package/pull/123)' - required: true - type: string - pr_number: - description: 'PR number' - required: true - type: string jobs: add-merge-reaction: - if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' + if: github.event.pull_request.merged == true runs-on: ubuntu-latest steps: - - name: Log merge info - env: - PR_URL: ${{ inputs.pr_url || github.event.pull_request.html_url }} - PR_NUMBER: ${{ inputs.pr_number || github.event.pull_request.number }} - MERGED_BY: ${{ github.event.pull_request.merged_by.login || 'manual-test' }} - MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha || 'manual-test' }} + - name: Verify PR was merged (not just closed) run: | - echo "✓ PR #$PR_NUMBER was merged by $MERGED_BY" - echo "✓ Merge commit: $MERGE_SHA" - echo "✓ Searching for: $PR_URL" - + if [ "${{ github.event.pull_request.merged }}" != "true" ]; then + echo "PR was closed without merging, skipping" + exit 0 + fi + echo "✓ PR #${{ github.event.pull_request.number }} was merged by ${{ github.event.pull_request.merged_by.login }}" + echo "✓ Merge commit: ${{ github.event.pull_request.merge_commit_sha }}" + - name: Search Slack and add reaction env: SLACK_BOT_TOKEN: ${{ secrets.PDOCS_SLACK_BOT_TOKEN }} SLACK_CHANNEL_ID: ${{ secrets.PDOCS_SLACK_CHANNEL_ID }} - PR_URL: ${{ inputs.pr_url || github.event.pull_request.html_url }} + PR_URL: ${{ github.event.pull_request.html_url }} run: | + # Fetch recent messages from the channel and search for the PR URL HISTORY_RESPONSE=$(curl -s -X GET "https://slack.com/api/conversations.history" \ -H "Authorization: Bearer $SLACK_BOT_TOKEN" \ -G --data-urlencode "channel=$SLACK_CHANNEL_ID" \ - -G --data-urlencode "limit=200") - + -G --data-urlencode "limit=100") + + echo "History response: $(echo "$HISTORY_RESPONSE" | jq -r '.ok')" + + # Check if history fetch was successful if [ "$(echo "$HISTORY_RESPONSE" | jq -r '.ok')" != "true" ]; then echo "Error: History fetch failed - $(echo "$HISTORY_RESPONSE" | jq -r '.error')" exit 1 fi - - MSG_COUNT=$(echo "$HISTORY_RESPONSE" | jq '.messages | length') - echo "Fetched $MSG_COUNT messages from channel" - echo "Searching for PR URL: $PR_URL" - - EARLIEST_MESSAGE=$(echo "$HISTORY_RESPONSE" | jq -r --arg PR_URL "$PR_URL" --arg CHANNEL "$SLACK_CHANNEL_ID" ' - .messages[]? - | . as $msg - | ($msg | tostring | contains($PR_URL)) - | select(.) - | $msg - | {ts: .ts, timestamp: (.ts | tonumber)} - | "\($CHANNEL) \(.ts) \(.timestamp)" + + # Find the earliest message containing the PR URL + # Slack wraps URLs in angle brackets, so check for both formats + EARLIEST_MESSAGE=$(echo "$HISTORY_RESPONSE" | jq -r --arg PR_URL "$PR_URL" ' + .messages[]? + | select(.text | (contains($PR_URL) or contains("<" + $PR_URL + ">") or contains("<" + $PR_URL + "|"))) + | {channel: "'$SLACK_CHANNEL_ID'", ts: .ts, timestamp: (.ts | tonumber)} + | "\(.channel) \(.ts) \(.timestamp)" ' | sort -k3 -n | head -n 1) - + if [ -z "$EARLIEST_MESSAGE" ]; then - echo "::warning::No messages found containing the PR URL" - if echo "$HISTORY_RESPONSE" | grep -q "$PR_URL"; then - echo "URL found in raw response but jq didn't match - please report this bug" - else - echo "URL not found in channel history" - echo "Recent PR URLs in channel:" - echo "$HISTORY_RESPONSE" | grep -oE 'https://github.com/[^"<>|]+/pull/[0-9]+' | sort -u | tail -10 - fi + echo "No messages found containing the PR URL in recent history" exit 0 fi - + read -r CHANNEL_ID TIMESTAMP _ <<< "$EARLIEST_MESSAGE" - echo "Found message at timestamp $TIMESTAMP" - + + echo "Adding merged reaction to message in channel $CHANNEL_ID at $TIMESTAMP" + + # Check if merged reaction already exists MESSAGE_INFO=$(curl -s -X GET "https://slack.com/api/conversations.history" \ -H "Authorization: Bearer $SLACK_BOT_TOKEN" \ -G --data-urlencode "channel=$CHANNEL_ID" \ --data-urlencode "latest=$TIMESTAMP" \ --data-urlencode "inclusive=true" \ --data-urlencode "limit=1") - + HAS_MERGED=$(echo "$MESSAGE_INFO" | jq -r '.messages[0].reactions[]? | select(.name == "pr-merged") | .name') - + if [ "$HAS_MERGED" = "pr-merged" ]; then echo "Merged reaction already exists, skipping" exit 0 fi - + + # Add the merged reaction REACTION_RESPONSE=$(curl -s -X POST "https://slack.com/api/reactions.add" \ -H "Authorization: Bearer $SLACK_BOT_TOKEN" \ -H "Content-Type: application/json" \ @@ -98,13 +80,9 @@ jobs: \"timestamp\": \"$TIMESTAMP\", \"name\": \"pr-merged\" }") - + if [ "$(echo "$REACTION_RESPONSE" | jq -r '.ok')" = "true" ]; then - echo "Successfully added pr-merged reaction" + echo "Successfully added merged reaction" else - ERROR=$(echo "$REACTION_RESPONSE" | jq -r '.error') - echo "Failed to add reaction: $ERROR" - if [ "$ERROR" = "already_reacted" ]; then - echo "Reaction was already added" - fi + echo "Failed to add reaction: $(echo "$REACTION_RESPONSE" | jq -r '.error')" fi From ed1f9f1281d73905a83d3f9c14d76a9513fcc7af Mon Sep 17 00:00:00 2001 From: Dan Finn Date: Wed, 28 Jan 2026 16:13:10 -0500 Subject: [PATCH 5/7] clean up the workflow --- .github/workflows/slack-merge-reaction.yml | 99 ++++------------------ 1 file changed, 18 insertions(+), 81 deletions(-) diff --git a/.github/workflows/slack-merge-reaction.yml b/.github/workflows/slack-merge-reaction.yml index 9b91dbb..5808ebb 100644 --- a/.github/workflows/slack-merge-reaction.yml +++ b/.github/workflows/slack-merge-reaction.yml @@ -1,88 +1,25 @@ name: Add Slack Merge Reaction - on: pull_request: types: [closed] + workflow_dispatch: + inputs: + pr_url: + description: 'PR URL to test' + required: true + type: string + pr_number: + description: 'PR number' + required: true + type: string jobs: add-merge-reaction: - if: github.event.pull_request.merged == true - runs-on: ubuntu-latest - steps: - - name: Verify PR was merged (not just closed) - run: | - if [ "${{ github.event.pull_request.merged }}" != "true" ]; then - echo "PR was closed without merging, skipping" - exit 0 - fi - echo "✓ PR #${{ github.event.pull_request.number }} was merged by ${{ github.event.pull_request.merged_by.login }}" - echo "✓ Merge commit: ${{ github.event.pull_request.merge_commit_sha }}" - - - name: Search Slack and add reaction - env: - SLACK_BOT_TOKEN: ${{ secrets.PDOCS_SLACK_BOT_TOKEN }} - SLACK_CHANNEL_ID: ${{ secrets.PDOCS_SLACK_CHANNEL_ID }} - PR_URL: ${{ github.event.pull_request.html_url }} - run: | - # Fetch recent messages from the channel and search for the PR URL - HISTORY_RESPONSE=$(curl -s -X GET "https://slack.com/api/conversations.history" \ - -H "Authorization: Bearer $SLACK_BOT_TOKEN" \ - -G --data-urlencode "channel=$SLACK_CHANNEL_ID" \ - -G --data-urlencode "limit=100") - - echo "History response: $(echo "$HISTORY_RESPONSE" | jq -r '.ok')" - - # Check if history fetch was successful - if [ "$(echo "$HISTORY_RESPONSE" | jq -r '.ok')" != "true" ]; then - echo "Error: History fetch failed - $(echo "$HISTORY_RESPONSE" | jq -r '.error')" - exit 1 - fi - - # Find the earliest message containing the PR URL - # Slack wraps URLs in angle brackets, so check for both formats - EARLIEST_MESSAGE=$(echo "$HISTORY_RESPONSE" | jq -r --arg PR_URL "$PR_URL" ' - .messages[]? - | select(.text | (contains($PR_URL) or contains("<" + $PR_URL + ">") or contains("<" + $PR_URL + "|"))) - | {channel: "'$SLACK_CHANNEL_ID'", ts: .ts, timestamp: (.ts | tonumber)} - | "\(.channel) \(.ts) \(.timestamp)" - ' | sort -k3 -n | head -n 1) - - if [ -z "$EARLIEST_MESSAGE" ]; then - echo "No messages found containing the PR URL in recent history" - exit 0 - fi - - read -r CHANNEL_ID TIMESTAMP _ <<< "$EARLIEST_MESSAGE" - - echo "Adding merged reaction to message in channel $CHANNEL_ID at $TIMESTAMP" - - # Check if merged reaction already exists - MESSAGE_INFO=$(curl -s -X GET "https://slack.com/api/conversations.history" \ - -H "Authorization: Bearer $SLACK_BOT_TOKEN" \ - -G --data-urlencode "channel=$CHANNEL_ID" \ - --data-urlencode "latest=$TIMESTAMP" \ - --data-urlencode "inclusive=true" \ - --data-urlencode "limit=1") - - HAS_MERGED=$(echo "$MESSAGE_INFO" | jq -r '.messages[0].reactions[]? | select(.name == "pr-merged") | .name') - - if [ "$HAS_MERGED" = "pr-merged" ]; then - echo "Merged reaction already exists, skipping" - exit 0 - fi - - # Add the merged reaction - REACTION_RESPONSE=$(curl -s -X POST "https://slack.com/api/reactions.add" \ - -H "Authorization: Bearer $SLACK_BOT_TOKEN" \ - -H "Content-Type: application/json" \ - -d "{ - \"channel\": \"$CHANNEL_ID\", - \"timestamp\": \"$TIMESTAMP\", - \"name\": \"pr-merged\" - }") - - if [ "$(echo "$REACTION_RESPONSE" | jq -r '.ok')" = "true" ]; then - echo "Successfully added merged reaction" - else - echo "Failed to add reaction: $(echo "$REACTION_RESPONSE" | jq -r '.error')" - fi + if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' + uses: digitalocean/docs-automation/.github/workflows/slack-merge-reaction.yml@main + with: + pr_url: ${{ inputs.pr_url || github.event.pull_request.html_url }} + pr_number: ${{ inputs.pr_number || github.event.pull_request.number }} + merged_by: ${{ github.event.pull_request.merged_by.login || 'manual-test' }} + merge_commit_sha: ${{ github.event.pull_request.merge_commit_sha || 'manual-test' }} + secrets: inherit From 2d6b2a6f0540f60586db8472633d4402c5d7d7c6 Mon Sep 17 00:00:00 2001 From: Dan Finn Date: Wed, 28 Jan 2026 16:15:55 -0500 Subject: [PATCH 6/7] clean up test file --- .../debug-docs-automation-access.yml | 29 ------------------- 1 file changed, 29 deletions(-) delete mode 100644 .github/workflows/debug-docs-automation-access.yml diff --git a/.github/workflows/debug-docs-automation-access.yml b/.github/workflows/debug-docs-automation-access.yml deleted file mode 100644 index fac9a9e..0000000 --- a/.github/workflows/debug-docs-automation-access.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Debug Docs-Automation Access - -on: - workflow_dispatch: - -jobs: - access-check: - runs-on: ubuntu-latest - permissions: - contents: read - steps: - - name: Check access to docs-automation workflow file - env: - TARGET_URL: https://api.github.com/repos/digitalocean/docs-automation/contents/.github/workflows/slack-merge-reaction.yml?ref=main - GITHUB_TOKEN: ${{ github.token }} - run: | - echo "Requesting: $TARGET_URL" - if [ -z "$GITHUB_TOKEN" ]; then - echo "GITHUB_TOKEN is EMPTY" - else - echo "GITHUB_TOKEN length: ${#GITHUB_TOKEN}" - fi - STATUS=$(curl -s -o /tmp/resp.json -w "%{http_code}" \ - -H "Authorization: Bearer $GITHUB_TOKEN" \ - -H "Accept: application/vnd.github+json" \ - "$TARGET_URL") - echo "HTTP status: $STATUS" - echo "Response:" - cat /tmp/resp.json From d7dfacb71e9fa41d059b87c196f28b6561e1e685 Mon Sep 17 00:00:00 2001 From: Dan Finn Date: Wed, 28 Jan 2026 16:22:53 -0500 Subject: [PATCH 7/7] Use reusable workflow with secrets inherit --- .github/workflows/slack-merge-reaction.yml | 104 ++------------------- 1 file changed, 10 insertions(+), 94 deletions(-) diff --git a/.github/workflows/slack-merge-reaction.yml b/.github/workflows/slack-merge-reaction.yml index a6fbe36..06c85fb 100644 --- a/.github/workflows/slack-merge-reaction.yml +++ b/.github/workflows/slack-merge-reaction.yml @@ -1,13 +1,11 @@ name: Add Slack Merge Reaction - on: pull_request: types: [closed] - # Manual trigger for testing workflow_dispatch: inputs: pr_url: - description: 'PR URL to test (e.g., https://github.com/digitalocean/vale-package/pull/123)' + description: 'PR URL to test' required: true type: string pr_number: @@ -17,94 +15,12 @@ on: jobs: add-merge-reaction: - if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' - runs-on: ubuntu-latest - steps: - - name: Log merge info - env: - PR_URL: ${{ inputs.pr_url || github.event.pull_request.html_url }} - PR_NUMBER: ${{ inputs.pr_number || github.event.pull_request.number }} - MERGED_BY: ${{ github.event.pull_request.merged_by.login || 'manual-test' }} - MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha || 'manual-test' }} - run: | - echo "✓ PR #$PR_NUMBER was merged by $MERGED_BY" - echo "✓ Merge commit: $MERGE_SHA" - echo "✓ Searching for: $PR_URL" - - - name: Search Slack and add reaction - env: - SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} - SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID }} - PR_URL: ${{ inputs.pr_url || github.event.pull_request.html_url }} - run: | - HISTORY_RESPONSE=$(curl -s -X GET "https://slack.com/api/conversations.history" \ - -H "Authorization: Bearer $SLACK_BOT_TOKEN" \ - -G --data-urlencode "channel=$SLACK_CHANNEL_ID" \ - -G --data-urlencode "limit=200") - - if [ "$(echo "$HISTORY_RESPONSE" | jq -r '.ok')" != "true" ]; then - echo "Error: History fetch failed - $(echo "$HISTORY_RESPONSE" | jq -r '.error')" - exit 1 - fi - - MSG_COUNT=$(echo "$HISTORY_RESPONSE" | jq '.messages | length') - echo "Fetched $MSG_COUNT messages from channel" - echo "Searching for PR URL: $PR_URL" - - EARLIEST_MESSAGE=$(echo "$HISTORY_RESPONSE" | jq -r --arg PR_URL "$PR_URL" --arg CHANNEL "$SLACK_CHANNEL_ID" ' - .messages[]? - | . as $msg - | ($msg | tostring | contains($PR_URL)) - | select(.) - | $msg - | {ts: .ts, timestamp: (.ts | tonumber)} - | "\($CHANNEL) \(.ts) \(.timestamp)" - ' | sort -k3 -n | head -n 1) - - if [ -z "$EARLIEST_MESSAGE" ]; then - echo "::warning::No messages found containing the PR URL" - if echo "$HISTORY_RESPONSE" | grep -q "$PR_URL"; then - echo "URL found in raw response but jq didn't match - please report this bug" - else - echo "URL not found in channel history" - echo "Recent PR URLs in channel:" - echo "$HISTORY_RESPONSE" | grep -oE 'https://github.com/[^"<>|]+/pull/[0-9]+' | sort -u | tail -10 - fi - exit 0 - fi - - read -r CHANNEL_ID TIMESTAMP _ <<< "$EARLIEST_MESSAGE" - echo "Found message at timestamp $TIMESTAMP" - - MESSAGE_INFO=$(curl -s -X GET "https://slack.com/api/conversations.history" \ - -H "Authorization: Bearer $SLACK_BOT_TOKEN" \ - -G --data-urlencode "channel=$CHANNEL_ID" \ - --data-urlencode "latest=$TIMESTAMP" \ - --data-urlencode "inclusive=true" \ - --data-urlencode "limit=1") - - HAS_MERGED=$(echo "$MESSAGE_INFO" | jq -r '.messages[0].reactions[]? | select(.name == "pr-merged") | .name') - - if [ "$HAS_MERGED" = "pr-merged" ]; then - echo "Merged reaction already exists, skipping" - exit 0 - fi - - REACTION_RESPONSE=$(curl -s -X POST "https://slack.com/api/reactions.add" \ - -H "Authorization: Bearer $SLACK_BOT_TOKEN" \ - -H "Content-Type: application/json" \ - -d "{ - \"channel\": \"$CHANNEL_ID\", - \"timestamp\": \"$TIMESTAMP\", - \"name\": \"pr-merged\" - }") - - if [ "$(echo "$REACTION_RESPONSE" | jq -r '.ok')" = "true" ]; then - echo "Successfully added pr-merged reaction" - else - ERROR=$(echo "$REACTION_RESPONSE" | jq -r '.error') - echo "Failed to add reaction: $ERROR" - if [ "$ERROR" = "already_reacted" ]; then - echo "Reaction was already added" - fi - fi + # Fix spacing and wrap the expression + if: ${{ github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' }} + uses: digitalocean/docs-automation/.github/workflows/slack-merge-reaction.yml@main + with: + pr_url: ${{ inputs.pr_url || github.event.pull_request.html_url }} + pr_number: ${{ inputs.pr_number || github.event.pull_request.number }} + merged_by: ${{ github.event.pull_request.merged_by.login || 'manual-test' }} + merge_commit_sha: ${{ github.event.pull_request.merge_commit_sha || 'manual-test' }} + secrets: inherit # Use 'inherit' to automatically pass all secrets to the reusable workflow