Skip to content

Commit 63cc81f

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

2 files changed

Lines changed: 54 additions & 27 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
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.
7+
8+
if [ -z "${GITHUB_EVENT_PATH:-}" ] || [ -z "${GITHUB_REPOSITORY:-}" ]; then
9+
echo "This script is intended to run inside GitHub Actions (needs GITHUB_EVENT_PATH and GITHUB_REPOSITORY)."
10+
exit 1
11+
fi
12+
13+
PR_NUMBER=$(jq -r .pull_request.number < "$GITHUB_EVENT_PATH")
14+
if [ "$PR_NUMBER" = "null" ] || [ -z "$PR_NUMBER" ]; then
15+
echo "No pull_request.number found in event payload"
16+
exit 0
17+
fi
18+
19+
OWNER=${GITHUB_REPOSITORY%%/*}
20+
REPO=${GITHUB_REPOSITORY##*/}
21+
REVIEWER="coderabbit"
22+
TOKEN="${GITHUB_TOKEN:-}"
23+
24+
if [ -z "$TOKEN" ]; then
25+
echo "GITHUB_TOKEN not set"
26+
exit 1
27+
fi
28+
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
36+
fi
37+
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")
42+
43+
if echo "$resp" | jq -e '.errors? // empty' >/dev/null 2>&1; then
44+
echo "Request API returned an error: $resp"
45+
exit 1
46+
fi
47+
48+
echo "Requested $REVIEWER for PR #$PR_NUMBER successfully"
49+
exit 0

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

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
required: false
1212
default: 'true'
1313

14-
concurrency:
14+
concurrency:
1515
group: request-triage-${{ github.event.pull_request.number }}
1616
cancel-in-progress: false
1717

@@ -24,32 +24,10 @@ jobs:
2424
if: ${{ github.event.label && (github.event.label.name == 'Good First Issue' || github.event.label.name == 'Beginner') }}
2525
runs-on: ubuntu-latest
2626
steps:
27-
- name: Request review from triage team
28-
uses: actions/github-script@v7
29-
with:
30-
script: |
31-
const prNumber = context.payload.pull_request.number;
32-
const owner = context.repo.owner;
33-
const repo = context.repo.repo;
34-
const reviewer = 'coderabbit';
35-
36-
// Check whether the user is already requested to avoid duplicates
37-
const existing = await github.rest.pulls.listRequestedReviewers({
38-
owner,
39-
repo,
40-
pull_number: prNumber,
41-
});
42-
const requestedUsers = (existing.data.users || []).map(u => u.login);
43-
if (requestedUsers.includes(reviewer)) {
44-
console.log(`User ${reviewer} already requested for PR #${prNumber}`);
45-
return;
46-
}
27+
- name: Checkout
28+
uses: actions/checkout@v4
4729

48-
await github.rest.pulls.requestReviewers({
49-
owner,
50-
repo,
51-
pull_number: prNumber,
52-
reviewers: [reviewer],
53-
});
30+
- name: Request review from triage team
31+
run: bash .github/scripts/bot-pr-gfi-review-triage.sh
5432
env:
5533
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)