feat!: implement PR review workflow
This commit is contained in:
parent
d794e43347
commit
6b552c1556
|
@ -0,0 +1,99 @@
|
|||
name: PR Review Workflow for Breaking Changes
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types:
|
||||
- opened
|
||||
- reopened
|
||||
- labeled
|
||||
- unlabeled
|
||||
pull_request_review:
|
||||
types:
|
||||
- submitted
|
||||
- edited
|
||||
- dismissed
|
||||
|
||||
jobs:
|
||||
check_breaking_change:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check for breaking_change label
|
||||
id: check_label
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||
script: |
|
||||
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: context.issue.number,
|
||||
});
|
||||
const hasBreakingChange = labels.some(label => label.name === 'breaking change');
|
||||
console.log(`Has breaking_change label: ${hasBreakingChange}`);
|
||||
return hasBreakingChange;
|
||||
|
||||
- name: Request QA reviews
|
||||
if: steps.check_label.outputs.result == 'true'
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||
script: |
|
||||
await github.rest.pulls.requestReviewers({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
pull_number: context.issue.number,
|
||||
team_reviewers: ['Desktop-QA', 'Mobile-QA']
|
||||
});
|
||||
|
||||
- name: Check QA approvals
|
||||
if: steps.check_label.outputs.result == 'true'
|
||||
id: check_approvals
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||
script: |
|
||||
const { data: reviews } = await github.rest.pulls.listReviews({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
pull_number: context.issue.number,
|
||||
});
|
||||
|
||||
const desktopQAApproved = reviews.some(review =>
|
||||
review.state === 'APPROVED' && review.user.login.includes('desktop-qa')
|
||||
);
|
||||
const mobileQAApproved = reviews.some(review =>
|
||||
review.state === 'APPROVED' && review.user.login.includes('mobile-qa')
|
||||
);
|
||||
|
||||
console.log(`Desktop QA approved: ${desktopQAApproved}`);
|
||||
console.log(`Mobile QA approved: ${mobileQAApproved}`);
|
||||
|
||||
return desktopQAApproved && mobileQAApproved;
|
||||
|
||||
- name: Block PR if conditions not met
|
||||
if: steps.check_label.outputs.result == 'true' && steps.check_approvals.outputs.result != 'true'
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||
script: |
|
||||
await github.rest.pulls.createReview({
|
||||
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: Allow PR merge if conditions are met
|
||||
if: steps.check_label.outputs.result == 'true' && steps.check_approvals.outputs.result == 'true'
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||
script: |
|
||||
await github.rest.pulls.createReview({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
pull_number: context.issue.number,
|
||||
event: 'APPROVE',
|
||||
body: 'All conditions have been met. This PR can now be merged.'
|
||||
});
|
Loading…
Reference in New Issue