Skip to content
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
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/request-review.yml
Copy link
Member

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?

- `/autoupdate` or `/au` - This comment will add `autoupdate` label to the PR and keeps your PR up-to-date to the target branch's future changes. Unless there is a merge conflict or it is a draft PR.`

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
Copy link
Member

@KhudaDad414 KhudaDad414 Jun 2, 2023

Choose a reason for hiding this comment

The 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);
}