Skip to content

Commit fed2645

Browse files
dry_run
Signed-off-by: tech0priyanshu <priyanshuyadv101106@gmail.com>
1 parent 63cc81f commit fed2645

2 files changed

Lines changed: 56 additions & 21 deletions

File tree

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
# Simple script to request a reviewer for a PR when invoked from GitHub Actions.
5-
# Expects: GITHUB_EVENT_PATH and GITHUB_REPOSITORY to be set by Actions and
6-
# a valid GITHUB_TOKEN in the environment.
4+
# Comment-based triage request script for PRs.
5+
# Aligns with issue #1721: post a comment to request triage reviewers
6+
# instead of assigning reviewers. Uses a triage list file or env var.
7+
# Safety: defaults to dry-run mode unless DRY_RUN is explicitly set to 'false'.
78

89
if [ -z "${GITHUB_EVENT_PATH:-}" ] || [ -z "${GITHUB_REPOSITORY:-}" ]; then
910
echo "This script is intended to run inside GitHub Actions (needs GITHUB_EVENT_PATH and GITHUB_REPOSITORY)."
@@ -18,32 +19,63 @@ fi
1819

1920
OWNER=${GITHUB_REPOSITORY%%/*}
2021
REPO=${GITHUB_REPOSITORY##*/}
21-
REVIEWER="coderabbit"
2222
TOKEN="${GITHUB_TOKEN:-}"
2323

2424
if [ -z "$TOKEN" ]; then
2525
echo "GITHUB_TOKEN not set"
2626
exit 1
2727
fi
2828

29-
echo "Checking existing requested reviewers for PR #$PR_NUMBER in $OWNER/$REPO"
30-
existing=$(curl -sS -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.github+json" \
31-
"https://api.github.com/repos/$OWNER/$REPO/pulls/$PR_NUMBER/requested_reviewers")
32-
33-
if echo "$existing" | jq -e --arg r "$REVIEWER" '.users[]?.login == $r' >/dev/null 2>&1; then
34-
echo "User $REVIEWER already requested for PR #$PR_NUMBER"
35-
exit 0
29+
# Dry-run guard: default to true to avoid accidental state changes.
30+
DRY_RUN=${DRY_RUN:-true}
31+
DRY_RUN_LC=$(echo "$DRY_RUN" | tr '[:upper:]' '[:lower:]')
32+
is_dry_run=true
33+
if [ "$DRY_RUN_LC" = "false" ] || [ "$DRY_RUN_LC" = "0" ] || [ "$DRY_RUN_LC" = "no" ]; then
34+
is_dry_run=false
3635
fi
3736

38-
echo "Requesting reviewer $REVIEWER for PR #$PR_NUMBER"
39-
resp=$(curl -sS -X POST -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.github+json" \
40-
-d "{\"reviewers\":[\"$REVIEWER\"]}" \
41-
"https://api.github.com/repos/$OWNER/$REPO/pulls/$PR_NUMBER/requested_reviewers")
37+
# Determine triage reviewers: prefer file in repo, fallback to TRIAGE_REVIEWERS env var
38+
TRIAGE_FILE=".github/triage-reviewers.txt"
39+
if [ -f "$TRIAGE_FILE" ]; then
40+
TRIAGE_LIST=$(tr '\n' ' ' < "$TRIAGE_FILE" | xargs)
41+
else
42+
TRIAGE_LIST="${TRIAGE_REVIEWERS:-}"
43+
fi
4244

43-
if echo "$resp" | jq -e '.errors? // empty' >/dev/null 2>&1; then
44-
echo "Request API returned an error: $resp"
45+
if [ -z "$TRIAGE_LIST" ]; then
46+
echo "No triage reviewers configured. Provide .github/triage-reviewers.txt or TRIAGE_REVIEWERS env var."
4547
exit 1
4648
fi
4749

48-
echo "Requested $REVIEWER for PR #$PR_NUMBER successfully"
50+
# Prepare mentions: accept comma or space separated values
51+
mentions=$(echo "$TRIAGE_LIST" | sed -E 's/,/ /g')
52+
53+
MARKER='<!-- triage-request -->'
54+
BODY_TEXT="${MARKER}\nRequesting triage review from: $mentions"
55+
56+
echo "PR #$PR_NUMBER in $OWNER/$REPO — triage mentions: $mentions"
57+
58+
# Idempotency: check existing comments for our marker
59+
comments=$(curl -fS -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.github+json" \
60+
"https://api.github.com/repos/$OWNER/$REPO/issues/$PR_NUMBER/comments")
61+
62+
if echo "$comments" | jq -r '.[].body' | grep -Fq "$MARKER"; then
63+
echo "Triage comment already present; skipping."
64+
exit 0
65+
fi
66+
67+
if [ "$is_dry_run" = true ]; then
68+
echo "DRY RUN: would post comment to PR #$PR_NUMBER with body:"
69+
echo "---"
70+
echo -e "$BODY_TEXT"
71+
echo "---"
72+
exit 0
73+
fi
74+
75+
echo "Posting triage request comment to PR #$PR_NUMBER"
76+
resp=$(curl -fS -X POST -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.github+json" -H "User-Agent: hiero-sdk-bot" \
77+
-d "{\"body\": $(jq -n --arg b "$BODY_TEXT" '$b')}" \
78+
"https://api.github.com/repos/$OWNER/$REPO/issues/$PR_NUMBER/comments")
79+
80+
echo "Comment posted successfully"
4981
exit 0

.github/workflows/request-triage-review.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ jobs:
2525
runs-on: ubuntu-latest
2626
steps:
2727
- name: Checkout
28-
uses: actions/checkout@v4
28+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
2929

30-
- name: Request review from triage team
31-
run: bash .github/scripts/bot-pr-gfi-review-triage.sh
30+
- name: Make script executable
31+
run: chmod +x .github/scripts/bot-pr-gfi-review-triage.sh
32+
33+
- name: Request triage by comment
34+
run: .github/scripts/bot-pr-gfi-review-triage.sh
3235
env:
3336
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)