From 455c661a242f10663c63ae435cf2641bb6fb32c7 Mon Sep 17 00:00:00 2001 From: Siddarth Kumar Date: Tue, 1 Oct 2024 09:22:50 +0530 Subject: [PATCH] chore!: actions bot will not request changes on PR --- .github/workflows/breaking-change-review.yml | 63 +++++++++++++++----- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/.github/workflows/breaking-change-review.yml b/.github/workflows/breaking-change-review.yml index 328388d457..0484a0df94 100644 --- a/.github/workflows/breaking-change-review.yml +++ b/.github/workflows/breaking-change-review.yml @@ -18,7 +18,7 @@ jobs: check_breaking_change: runs-on: ubuntu-latest steps: - - name: Check for breaking_change label + - name: Check for breaking change label id: check_label uses: actions/github-script@v6 with: @@ -30,20 +30,31 @@ jobs: issue_number: context.issue.number, }); const hasBreakingChange = labels.some(label => label.name === 'breaking change'); - console.log(`Has breaking_change label: ${hasBreakingChange}`); + console.log(`Has breaking change label: ${hasBreakingChange}`); return hasBreakingChange; + - name: Set QA reviewers + if: steps.check_label.outputs.result == 'true' + id: set_reviewers + run: | + echo "mobile_qa=churik,yevh-berdnyk,VolodLytvynenko,pavloburykh,mariia-skrypnyk,Horupa-Olena" >> $GITHUB_OUTPUT + echo "desktop_qa=anastasiyaig,virginiabalducci,glitchminer,antdanchenko" >> $GITHUB_OUTPUT + - name: Request QA reviews if: steps.check_label.outputs.result == 'true' uses: actions/github-script@v6 with: github-token: ${{secrets.GITHUB_TOKEN}} script: | + const mobileQA = '${{ steps.set_reviewers.outputs.mobile_qa }}'.split(','); + const desktopQA = '${{ steps.set_reviewers.outputs.desktop_qa }}'.split(','); + const reviewers = [...mobileQA, ...desktopQA]; + await github.rest.pulls.requestReviewers({ owner: context.repo.owner, repo: context.repo.repo, pull_number: context.issue.number, - reviewers: ['churik'] + reviewers: reviewers }); - name: Check QA approvals @@ -59,17 +70,23 @@ jobs: pull_number: context.issue.number, }); - const desktopQAApproved = reviews.some(review => - review.state === 'APPROVED' && review.user.login.includes('desktop-qa') - ); + const mobileQA = '${{ steps.set_reviewers.outputs.mobile_qa }}'.split(','); + const desktopQA = '${{ steps.set_reviewers.outputs.desktop_qa }}'.split(','); + const mobileQAApproved = reviews.some(review => - review.state === 'APPROVED' && review.user.login.includes('mobile-qa') + review.state === 'APPROVED' && mobileQA.includes(review.user.login) + ); + const desktopQAApproved = reviews.some(review => + review.state === 'APPROVED' && desktopQA.includes(review.user.login) ); - console.log(`Desktop QA approved: ${desktopQAApproved}`); console.log(`Mobile QA approved: ${mobileQAApproved}`); + console.log(`Desktop QA approved: ${desktopQAApproved}`); - return desktopQAApproved && mobileQAApproved; + core.setOutput('mobile-qa-approved', mobileQAApproved); + core.setOutput('desktop-qa-approved', desktopQAApproved); + + return mobileQAApproved && desktopQAApproved; - name: Block PR if conditions not met if: steps.check_label.outputs.result == 'true' && steps.check_approvals.outputs.result != 'true' @@ -77,12 +94,30 @@ jobs: with: github-token: ${{secrets.GITHUB_TOKEN}} script: | - await github.rest.pulls.createReview({ + const mobileQAApproved = ${{ steps.check_approvals.outputs.mobile-qa-approved }}; + const desktopQAApproved = ${{ steps.check_approvals.outputs.desktop-qa-approved }}; + + let message = 'This PR has the breaking change label and requires approval from both mobile-qa and desktop-qa teams before it can be merged.\n\n'; + + if (!mobileQAApproved && !desktopQAApproved) { + message += 'Both mobile-qa and desktop-qa teams have not approved this PR yet.'; + } else if (!mobileQAApproved) { + message += 'The mobile-qa team has not approved this PR yet.'; + } else if (!desktopQAApproved) { + message += 'The desktop-qa team has not approved this PR yet.'; + } + + await github.rest.checks.create({ owner: context.repo.owner, repo: context.repo.repo, - pull_number: context.issue.number, - event: 'REQUEST_CHANGES', - body: 'This PR has the breaking_change label and requires approval from both @status-im/desktop-qa and @status-im/mobile-qa teams before it can be merged.' + name: 'QA Approval Check', + head_sha: context.payload.pull_request.head.sha, + status: 'completed', + conclusion: 'failure', + output: { + title: 'QA Approval Required', + summary: message + } }); - name: Allow PR merge if conditions are met @@ -96,5 +131,5 @@ jobs: repo: context.repo.repo, pull_number: context.issue.number, event: 'APPROVE', - body: 'All conditions have been met. This PR can now be merged.' + body: 'Breaking changes have been approved by Mobile and Desktop QA. This PR can now be merged.' }); \ No newline at end of file