Skip to content

Commit 1afe611

Browse files
Add /ready slash command and author notification for "Author attention needed" label (#4353)
* Introduces workflow to make PR ready to review again with addressed feedback * Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * include label comment * Update label * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * updates --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 348f007 commit 1afe611

2 files changed

Lines changed: 118 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Notify Author attention needed
2+
3+
on:
4+
pull_request_target:
5+
types: [labeled]
6+
7+
jobs:
8+
notify-author:
9+
# Only run when 'Author attention needed' label is added to a PR
10+
if: >-
11+
github.repository == 'dotnet/SqlClient' &&
12+
github.event.label.name == 'Author attention needed'
13+
runs-on: ubuntu-latest
14+
permissions:
15+
issues: write
16+
pull-requests: write
17+
steps:
18+
- name: Post comment to PR author
19+
uses: actions/github-script@v9
20+
with:
21+
script: |
22+
const issue_number = context.payload.pull_request.number;
23+
const owner = context.repo.owner;
24+
const repo = context.repo.repo;
25+
const author = context.payload.pull_request.user.login;
26+
27+
const body = `@${author} This pull request has been marked as **Author attention needed**.\n\nWhen you have addressed the reviewer feedback and are ready for another review, please post a comment with \`/ready\` to remove the label and re-engage reviewers.`;
28+
29+
await github.rest.issues.createComment({
30+
owner,
31+
repo,
32+
issue_number,
33+
body,
34+
});
35+
core.info(`Posted notification comment on PR #${issue_number}`);
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Remove Author attention needed Label
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
7+
jobs:
8+
remove-label:
9+
# Only run on PR comments with '/ready' from the PR author
10+
if: >-
11+
github.repository == 'dotnet/SqlClient' &&
12+
github.event.issue.pull_request != null &&
13+
github.event.comment.user.login == github.event.issue.user.login &&
14+
startsWith(github.event.comment.body, '/ready')
15+
runs-on: ubuntu-latest
16+
permissions:
17+
issues: write
18+
pull-requests: write
19+
steps:
20+
- name: Remove 'Author attention needed' label
21+
uses: actions/github-script@v9
22+
with:
23+
script: |
24+
const labelName = 'Author attention needed';
25+
const issue_number = context.issue.number;
26+
const owner = context.repo.owner;
27+
const repo = context.repo.repo;
28+
29+
// Check if the label exists on the PR
30+
const labels = await github.paginate(github.rest.issues.listLabelsOnIssue, {
31+
owner,
32+
repo,
33+
issue_number,
34+
per_page: 100,
35+
});
36+
37+
const hasLabel = labels.some(label => label.name === labelName);
38+
39+
if (!hasLabel) {
40+
core.info(`PR #${issue_number} does not have the '${labelName}' label. No action taken.`);
41+
return;
42+
}
43+
44+
await github.rest.issues.removeLabel({
45+
owner,
46+
repo,
47+
issue_number,
48+
name: labelName,
49+
});
50+
core.info(`Removed '${labelName}' label from PR #${issue_number}`);
51+
52+
// Re-request reviews from existing reviewers (paginate to include all reviews)
53+
const reviews = await github.paginate(github.rest.pulls.listReviews, {
54+
owner,
55+
repo,
56+
pull_number: issue_number,
57+
per_page: 100,
58+
});
59+
60+
// Collect unique reviewers (exclude the PR author)
61+
const author = context.payload.issue.user.login;
62+
const reviewers = [...new Set(
63+
reviews
64+
.filter(r => r.user?.type === 'User')
65+
.map(r => r.user?.login)
66+
.filter(login => login && login !== author)
67+
)];
68+
69+
if (reviewers.length > 0) {
70+
try {
71+
await github.rest.pulls.requestReviewers({
72+
owner,
73+
repo,
74+
pull_number: issue_number,
75+
reviewers: reviewers.slice(0, 15),
76+
});
77+
core.info(`Re-requested reviews from: ${reviewers.join(', ')}`);
78+
} catch (err) {
79+
core.warning(`Failed to re-request reviewers: ${err.message}`);
80+
}
81+
} else {
82+
core.info('No previous reviewers to re-request.');
83+
}

0 commit comments

Comments
 (0)