-
Notifications
You must be signed in to change notification settings - Fork 330
Add /ready slash command and author notification for "Author attention needed" label
#4353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b3bf82e
Introduces workflow to make PR ready to review again with addressed f…
cheenamalhotra e2222e4
Apply suggestions from code review
cheenamalhotra 482195a
Apply suggestions from code review
cheenamalhotra 1182a84
include label comment
cheenamalhotra a606801
Update label
cheenamalhotra 2148aa1
Potential fix for pull request finding
cheenamalhotra b5606a5
updates
cheenamalhotra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| name: Notify Author attention needed | ||
|
|
||
| on: | ||
| pull_request_target: | ||
| types: [labeled] | ||
|
|
||
| jobs: | ||
| notify-author: | ||
| # Only run when 'Author attention needed' label is added to a PR | ||
| if: >- | ||
| github.repository == 'dotnet/SqlClient' && | ||
| github.event.label.name == 'Author attention needed' | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| issues: write | ||
| pull-requests: write | ||
| steps: | ||
| - name: Post comment to PR author | ||
| uses: actions/github-script@v9 | ||
| with: | ||
| script: | | ||
| const issue_number = context.payload.pull_request.number; | ||
| const owner = context.repo.owner; | ||
| const repo = context.repo.repo; | ||
| const author = context.payload.pull_request.user.login; | ||
|
|
||
| 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.`; | ||
|
|
||
| await github.rest.issues.createComment({ | ||
| owner, | ||
| repo, | ||
| issue_number, | ||
| body, | ||
| }); | ||
| core.info(`Posted notification comment on PR #${issue_number}`); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| name: Remove Author attention needed Label | ||
|
|
||
| on: | ||
| issue_comment: | ||
| types: [created] | ||
|
|
||
| jobs: | ||
| remove-label: | ||
| # Only run on PR comments with '/ready' from the PR author | ||
| if: >- | ||
| github.repository == 'dotnet/SqlClient' && | ||
| github.event.issue.pull_request != null && | ||
| github.event.comment.user.login == github.event.issue.user.login && | ||
| startsWith(github.event.comment.body, '/ready') | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| issues: write | ||
| pull-requests: write | ||
|
cheenamalhotra marked this conversation as resolved.
|
||
| steps: | ||
| - name: Remove 'Author attention needed' label | ||
| uses: actions/github-script@v9 | ||
| with: | ||
| script: | | ||
| const labelName = 'Author attention needed'; | ||
| const issue_number = context.issue.number; | ||
| const owner = context.repo.owner; | ||
| const repo = context.repo.repo; | ||
|
|
||
| // Check if the label exists on the PR | ||
| const labels = await github.paginate(github.rest.issues.listLabelsOnIssue, { | ||
| owner, | ||
| repo, | ||
| issue_number, | ||
| per_page: 100, | ||
| }); | ||
|
|
||
| const hasLabel = labels.some(label => label.name === labelName); | ||
|
|
||
| if (!hasLabel) { | ||
| core.info(`PR #${issue_number} does not have the '${labelName}' label. No action taken.`); | ||
| return; | ||
| } | ||
|
Copilot marked this conversation as resolved.
|
||
|
|
||
| await github.rest.issues.removeLabel({ | ||
| owner, | ||
| repo, | ||
| issue_number, | ||
| name: labelName, | ||
| }); | ||
| core.info(`Removed '${labelName}' label from PR #${issue_number}`); | ||
|
|
||
| // Re-request reviews from existing reviewers (paginate to include all reviews) | ||
| const reviews = await github.paginate(github.rest.pulls.listReviews, { | ||
| owner, | ||
| repo, | ||
| pull_number: issue_number, | ||
| per_page: 100, | ||
| }); | ||
|
|
||
| // Collect unique reviewers (exclude the PR author) | ||
| const author = context.payload.issue.user.login; | ||
| const reviewers = [...new Set( | ||
| reviews | ||
| .filter(r => r.user?.type === 'User') | ||
| .map(r => r.user?.login) | ||
| .filter(login => login && login !== author) | ||
| )]; | ||
|
cheenamalhotra marked this conversation as resolved.
|
||
|
|
||
| if (reviewers.length > 0) { | ||
| try { | ||
| await github.rest.pulls.requestReviewers({ | ||
| owner, | ||
| repo, | ||
| pull_number: issue_number, | ||
| reviewers: reviewers.slice(0, 15), | ||
| }); | ||
| core.info(`Re-requested reviews from: ${reviewers.join(', ')}`); | ||
| } catch (err) { | ||
| core.warning(`Failed to re-request reviewers: ${err.message}`); | ||
| } | ||
| } else { | ||
| core.info('No previous reviewers to re-request.'); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.