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(pull-request): change reviewer request policy #95

Merged
merged 17 commits into from
Oct 2, 2024
35 changes: 35 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ name: Pull Request
on:
pull_request:
types:
- converted_to_draft
- edited
- opened
- ready_for_review
- reopened
- review_requested
- synchronize

workflow_call:
inputs:
Expand Down Expand Up @@ -71,10 +74,42 @@ jobs:
const reviewers = "${{ github.event.inputs.reviewers || inputs.reviewers }}".split(',').filter((reviewer) => reviewer);
const team_reviewers = "${{ github.event.inputs.team-reviewers || inputs.team-reviewers }}".split(',').filter((reviewer) => reviewer);

console.log(`@${owner}/${repo}#${pull_number}: Retrieving reviews`);

const { data } = await github.rest.pulls.listReviews({ owner, repo, pull_number });

if (data.length > 0) {
console.log(`@${owner}/${repo}#${pull_number}: Skipping request review as there are already ${data.length} reviews`);
return;
}

console.log(`@${owner}/${repo}#${pull_number}: Requesting review from ${reviewers.concat(team_reviewers)}`);

await github.rest.pulls.requestReviewers({ owner, repo, pull_number, reviewers, team_reviewers });

- if: >
(
github.event.pull_request.draft == true &&
github.event.pull_request.requested_teams[0] != null
) || (
github.event.pull_request.requested_reviewers[0] != null &&
github.event.pull_request.requested_teams[0] != null
)
name: Remove Team Request
uses: actions/github-script@v7
with:
github-token: ${{ secrets.HEDIA_BOT_GITHUB_PAT }}
script: |
const owner = "${{ github.repository_owner }}";
const repo = "${{ github.event.repository.name }}";
const pull_number = ${{ github.event.pull_request.number }};
const reviewers = [];
const team_reviewers = ["${{ github.event.pull_request.requested_teams[0].slug }}"];

console.log(`@${owner}/${repo}#${pull_number}: Removing review from ${reviewers.concat(team_reviewers)}`);

await github.rest.pulls.removeRequestedReviewers({ owner, repo, pull_number, reviewers, team_reviewers });

- name: Set Labels
uses: hedia-team/.github/.github/actions/set-labels@main
with:
Expand Down