-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pull_request_target workarounds, and labeling fixes (#1479)
### What kind of change does this PR introduce? * Deals with a security-related bug/feature that prevents Pull Requests coming from forks from being tagged automatically. * Prevents changes to the `.zenodo.json` file being labelled as `CI`-related. ### Does this PR introduce a breaking change? No. ### Other information: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
- Loading branch information
Showing
3 changed files
with
65 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,27 @@ on: | |
pull_request_review: | ||
types: | ||
- submitted | ||
pull_request_target: | ||
types: | ||
- ready_for_review | ||
- review_requested | ||
|
||
permissions: | ||
checks: write | ||
contents: read | ||
pull-requests: write | ||
|
||
jobs: | ||
approved: | ||
label_approved: | ||
name: Label on Approval | ||
if: github.event.review.state == 'approved' | ||
if: | | ||
(!contains(github.event.pull_request.labels.*.name, 'approved')) && | ||
(github.event.review.state == 'approved') && | ||
(github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name) | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/[email protected] | ||
- name: Label Approved | ||
uses: actions/[email protected] | ||
with: | ||
script: | | ||
github.rest.issues.addLabels({ | ||
|
@@ -20,3 +33,42 @@ jobs: | |
repo: context.repo.repo, | ||
labels: ['approved'] | ||
}) | ||
comment_approved: | ||
name: Comment Concerning Approved Tag | ||
if: | | ||
(github.event_name == 'pull_request_target') || | ||
(github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Find comment | ||
uses: peter-evans/find-comment@v2 | ||
id: fc | ||
with: | ||
issue-number: ${{ github.event.pull_request.number }} | ||
comment-author: 'github-actions[bot]' | ||
body-includes: This Pull Request is coming from a fork and must be manually tagged `approved` in order to perform additional testing | ||
- name: Create comment | ||
if: | | ||
(steps.fc.outputs.comment-id == '') || | ||
(!contains(github.event.pull_request.labels.*.name, 'approved')) | ||
uses: peter-evans/create-or-update-comment@v3 | ||
with: | ||
comment-id: ${{ steps.fc.outputs.comment-id }} | ||
issue-number: ${{ github.event.pull_request.number }} | ||
body: | | ||
> **Warning** | ||
> This Pull Request is coming from a fork and must be manually tagged `approved` in order to perform additional testing. | ||
edit-mode: replace | ||
- name: Update comment | ||
if: | | ||
contains(github.event.pull_request.labels.*.name, 'approved') | ||
uses: peter-evans/create-or-update-comment@v3 | ||
with: | ||
comment-id: ${{ steps.fc.outputs.comment-id }} | ||
issue-number: ${{ github.event.pull_request.number }} | ||
body: | | ||
Pull Request is approved! | ||
reactions: | | ||
hooray | ||
edit-mode: append |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters