-
Notifications
You must be signed in to change notification settings - Fork 66
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
feat: added /review /rerequest command to get reviews from the reviewers #243
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
There are no files selected for viewing
This file contains 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,76 @@ | ||
# This action is centrally managed in https://github.com/asyncapi/.github/ | ||
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo | ||
|
||
# This action is used to call the reviewer to review the PR using the command /review | ||
# or /rerequest. If the user is not mentioned, then all the reviewers are called to review the PR. | ||
# If the user is mentioned, then only those users are called to review the PR. | ||
# e.g. /review @user1 @user2 this will call only user1 and user2 to review the PR | ||
# e.g. /review this will call all the reviewers to review the PR | ||
|
||
name: Review | ||
|
||
on: | ||
issue_comment: | ||
types: [created] | ||
|
||
jobs: | ||
review: | ||
permissions: write-all | ||
if : > | ||
github.event.issue.pull_request && | ||
github.event.issue.state != 'closed' && | ||
github.actor != 'asyncapi-bot' && | ||
( | ||
contains(github.event.comment.body, '/review') || | ||
contains(github.event.comment.body, '/rerequest ') | ||
) | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Adds reviewers to the PR | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const comment = context.payload.comment.body; | ||
const prDetailsUrl = context.payload.issue.pull_request.url; | ||
const { data : pull} = await github.request(prDetailsUrl); | ||
const pullRequestId = pull.node_id; | ||
const reviewers = pull.requested_reviewers.map(reviewer => reviewer.login); | ||
const userIDregex = /@([A-Za-z0-9-]+)/g; | ||
const userIDmatches = comment.match(userIDregex); | ||
var userIdArray = []; | ||
if (userIDmatches){ | ||
// If user is mentioned, then add only those users | ||
// Remove the @ from the user name | ||
for (const user of userIDmatches) { | ||
const userId = user.substring(1); | ||
userIdArray.push(userId); | ||
} | ||
} | ||
else { | ||
// If no user is mentioned, then add all the reviewers | ||
userIdArray = reviewers; | ||
} | ||
const userIdNodeArray = []; | ||
for (const user of userIdArray) { | ||
const { data } = await github.request(`https://api.github.com/users/${user}`); | ||
const userId = data.node_id; | ||
userIdNodeArray.push(userId); | ||
} | ||
if (userIdNodeArray.length > 0) { | ||
const mutationQuery = ` | ||
mutation { | ||
requestReviews(input: { | ||
Comment on lines
+34
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. some logs would be great so it becomes easier to debug. :) |
||
pullRequestId: "${pullRequestId}", | ||
userIds: ${JSON.stringify(userIdNodeArray)} | ||
}) { | ||
pullRequest { | ||
id | ||
} | ||
} | ||
}`; | ||
|
||
const { data } = await github.graphql(mutationQuery); | ||
} | ||
|
||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please document these commands here as well?
.github/.github/workflows/help-command.yml
Line 36 in 31b1ebe