diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index fc7c2c9..1f818cc 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -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: @@ -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: