From d22c3074b745a07474a7dc1e06dd58908994bf37 Mon Sep 17 00:00:00 2001 From: Dan Finn Date: Tue, 27 Jan 2026 11:31:37 -0500 Subject: [PATCH 1/3] 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/3] 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/3] 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