forked from SASTxNST/Website_SAST
-
Notifications
You must be signed in to change notification settings - Fork 0
51 lines (44 loc) · 1.93 KB
/
auto-request-review.yml
File metadata and controls
51 lines (44 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
name: Auto request review from maintainer
on:
pull_request_target:
types: [opened, reopened, ready_for_review] # fires when a PR becomes ready
permissions:
pull-requests: write
contents: read
jobs:
request:
runs-on: ubuntu-latest
steps:
- name: Request review from maintainer
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const REVIEWERS = ["KatalKavya96"]; // <-- your GitHub username
const TEAM_REVIEWERS = []; // e.g., ["maintainers"] for org teams
// Skip drafts (can request when they click "Ready for review")
if (pr.draft) {
core.notice("PR is draft; skipping for now.");
return;
}
// Can't request review from the PR author (GitHub restriction)
const allowedReviewers = REVIEWERS.filter(r => r.toLowerCase() !== pr.user.login.toLowerCase());
const alreadyRequested = (pr.requested_reviewers || []).map(u => u.login.toLowerCase());
const toRequest = allowedReviewers.filter(r => !alreadyRequested.includes(r.toLowerCase()));
if (toRequest.length === 0 && TEAM_REVIEWERS.length === 0) {
core.notice("No reviewers to request (either author or already requested).");
return;
}
try {
await github.rest.pulls.requestReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
reviewers: toRequest,
team_reviewers: TEAM_REVIEWERS
});
core.info(`Requested reviewers: [${[...toRequest, ...TEAM_REVIEWERS].join(", ")}]`);
} catch (e) {
// Ignore 422 (e.g., user has no access or already requested)
core.warning(`requestReviewers: ${e.message}`);
}