TEST: PR for triggering a workflow #5
Workflow file for this run
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
name: Second Reviewer Assignment | |
on: | |
pull_request_target: | |
types: [ labeled ] | |
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: Add second reviewer | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
// Get PR information | |
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 | |
const org = 'Tribler'; | |
const teamSlug = 'reviewers'; | |
const response = await github.rest.teams.listMembersInOrg({ | |
org, | |
team_slug: teamSlug | |
}); | |
const allReviewers = response.data.map(member => member.login); | |
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 | |
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 | |
}); | |
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."); |