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

Add second_reviewer.yml #7829

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
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
100 changes: 100 additions & 0 deletions .github/workflows/second_reviewer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Second Reviewer Assignment

on:
pull_request_target:
types: [ labeled ]

permissions:
pull-requests: write

jobs:
assign-reviewer:
if: ${{ contains(github.event.pull_request.labels.*.name, format('PR{0} second reviewer', ':')) }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Get team members
id: get-team-members
uses: actions/github-script@v7
with:
github-token: ${{secrets.PAT_TOKEN_FOR_SECOND_REVIEWER_UNTIL_JAN_2025}}
script: |
/*
* Using PAT_TOKEN_FOR_SECOND_REVIEWER_UNTIL_JAN_2025 because the current workflow
* lacks sufficient permissions to view members of the Tribler organization.
* This token is valid until January 2025. It's issued for a maximum of one year,
* so in January 2025, it will expire and need to be replaced with a new token.
*/

const teamResponse = await github.rest.teams.listMembersInOrg({
org: 'Tribler',
team_slug: 'reviewers'
});
const allReviewers = teamResponse.data.map(member => member.login);
return allReviewers;

- name: Add second reviewer
uses: actions/github-script@v7
env:
ALL_REVIEWERS: ${{ steps.get-team-members.outputs.result }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const pullRequest = context.payload.pull_request;
const author = pullRequest.user.login;
console.log("Author:", author);

const currentReviewers = pullRequest.requested_reviewers.map(reviewer => reviewer.login);
console.log("Current Reviewers:", currentReviewers);

// Get the list of potential reviewers from the previous step
const allReviewers = JSON.parse(process.env.ALL_REVIEWERS)
console.log("Potential Reviewers:", allReviewers);

// Filter out the PR author and current reviewers
const eligibleReviewers = allReviewers.filter(reviewer => reviewer !== author && !currentReviewers.includes(reviewer));
console.log("Eligible Reviewers:", eligibleReviewers);

// Randomly select a reviewer
if (eligibleReviewers.length > 0) {
const randomReviewer = eligibleReviewers[Math.floor(Math.random() * eligibleReviewers.length)];
console.log("Selected Reviewer:", randomReviewer);

// Assign the selected reviewer
await github.rest.pulls.requestReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pullRequest.number,
reviewers: [randomReviewer]
});

// Add a comment explaining the selection
const comment = `A 'second reviewer' has been requested for this pull request. @${randomReviewer} has been randomly selected as the second opinion reviewer. This action is part of the Tie Breaker mechanism designed to resolve conflicts. The decision of the 'second reviewer' is considered final in the dispute.`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullRequest.number,
body: comment
});
} else {
// Add a comment indicating no eligible reviewers are left
const noReviewerComment = `All eligible reviewers have already been added to this pull request.`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullRequest.number,
body: noReviewerComment
});
console.log("No eligible reviewers left to add.");
}

// Remove the 'PR: second reviewer' label
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullRequest.number,
name: 'PR: second reviewer'
});
console.log("Label 'PR: second reviewer' removed successfully.");
2 changes: 2 additions & 0 deletions doc/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ PR policies
===========
* We use `rebase + merge –no–ff <https://www.endoflineblog.com/oneflow-a-git-branching-model-and-workflow#option-3-rebase-merge-no-ff>`_ for merging a branch
* Responsibility for merging the PR is on the creator of PR
* In the case where you cannot reach a consensus with the reviewer, you can request a second reviewer to act as a `Tie Breaker <https://github.com/Tribler/tribler/issues/7807>`_.


Recommendations:

Expand Down
Loading