-
Notifications
You must be signed in to change notification settings - Fork 348
38 lines (33 loc) · 1.27 KB
/
label-external-contributions.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
name: Workflow to label external contributions
on:
pull_request_target:
types: [opened, ready_for_review]
permissions:
contents: read
pull-requests: write
jobs:
label:
runs-on: ubuntu-latest
steps:
- name: Add external-contribution label
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
REPO_FULL_NAME=$(jq --raw-output .repository.full_name "$GITHUB_EVENT_PATH")
IS_FORK=$(jq --raw-output .pull_request.head.repo.fork "$GITHUB_EVENT_PATH")
if [[ "$IS_FORK" == "true" ]]; then
echo "This PR is created from a fork."
HTTP_STATUS=$(curl -o /dev/null -s -w "%{http_code}\n" \
-X POST \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/$REPO_FULL_NAME/issues/$PR_NUMBER/labels" \
-d '{"labels": ["external-contribution"]}')
if [[ $HTTP_STATUS -ge 300 ]]; then
echo "Failed to add label to PR, exiting."
exit 1
fi
else
echo "This PR is not created from a fork."
fi