Fix semver minor action (#7261)

* Update check-merge.yml

* chore: update action

* chore(action): better check if block exists

* chore(action): update check-merge action
This commit is contained in:
Nate Moore 2023-05-31 17:15:14 -05:00 committed by GitHub
parent e0ca0d8c8a
commit c4c086e5e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,10 +1,12 @@
name: Check mergeability name: Check mergeability
on: pull_request # run on pull request events on: pull_request
permissions: permissions:
# grant write permission on the pull-requests endpoint
pull-requests: write pull-requests: write
checks: write
statuses: write
jobs: jobs:
check: check:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -12,15 +14,18 @@ jobs:
- name: Check if there is already a block on this PR - name: Check if there is already a block on this PR
id: set-blocks id: set-blocks
uses: actions/github-script@v6 uses: actions/github-script@v6
env:
issue_number: ${{ github.event.number }}
with: with:
script: | script: |
const url = 'https://api.github.com/repos/' + context.repo.owner + '/' + context.repo.repo + '/pulls/' + context.issue.number + '/reviews'; const { data: reviews } = await github.rest.pulls.listReviews({
console.log('reviews URL', url); owner: context.repo.owner,
const result = await github.request(url); repo: context.repo.repo,
console.log(result); pull_number: process.env.issue_number,
const reviews = result.data; });
for(const review of reviews) { console.log(reviews);
if(review.user.id === 41898282 && review.state === 'CHANGES_REQUESTED') { for (const review of reviews) {
if (review.user.id === 41898282 && review.state === 'CHANGES_REQUESTED') {
return 'block'; return 'block';
} }
} }
@ -54,38 +59,31 @@ jobs:
done done
- name: Add label - name: Add label
uses: actions/github-script@v6
if: steps.find-blockers.outputs.found == 'true' if: steps.find-blockers.outputs.found == 'true'
run: | env:
curl --request POST \ issue_number: ${{ github.event.number }}
--url https://api.github.com/repos/${{github.repository}}/issues/${{github.event.number}}/labels \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
-d '["semver minor"]'
- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc
with: with:
issue-number: ${{ github.event.number }} script: |
comment-author: 'github-actions[bot]' github.rest.issues.addLabels({
issue_number: process.env.issue_number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['semver minor']
});
- name: Send PR review - name: Change PR Status
uses: actions/github-script@v6
if: steps.find-blockers.outputs.found == 'true' if: steps.find-blockers.outputs.found == 'true'
uses: peter-evans/create-or-update-comment@v3 env:
continue-on-error: true issue_number: ${{ github.event.number }}
with: with:
comment-id: ${{ steps.fc.outputs.comment-id }} script: |
issue-number: ${{ github.event.number }} github.rest.pulls.createReview({
body: | owner: context.repo.owner,
This PR is blocked because it contains a `minor` changeset. A reviewer will merge this at the next release if approved. repo: context.repo.repo,
edit-mode: replace pull_number: process.env.issue_number,
- name: Change PR status event: 'REQUEST_CHANGES',
if: steps.find-blockers.outputs.found == 'true' body: 'This PR is blocked because it contains a `minor` changeset. A reviewer will merge this at the next release if approved.'
run: | });
curl --request POST \
--url https://api.github.com/repos/${{github.repository}}/pulls/${{github.event.number}}/reviews \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
-d '{"event":"REQUEST_CHANGES", body: ""}'