-
Notifications
You must be signed in to change notification settings - Fork 8
39 lines (35 loc) · 1.44 KB
/
label.yml
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
39
name: Add Tags to PRs for New Contributors
on:
pull_request:
types:
- opened
jobs:
add_tags:
runs-on: ubuntu-latest
steps:
- name: Check if contributor is new
id: check_new_contributor
run: |
contributor_username=$(jq -r '.pull_request.user.login' $GITHUB_EVENT_PATH)
labels=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/contributors?anon=true")
if [[ $(echo $labels | jq --arg contributor "$contributor_username" \
'.[] | select(.login==$contributor)') == "" ]]; then
echo "New contributor detected."
echo "::set-output name=new_contributor::true"
else
echo "Existing contributor."
echo "::set-output name=new_contributor::false"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Add tags for new contributors
if: steps.check_new_contributor.outputs.new_contributor == 'true'
run: |
pr_number=$(jq -r '.pull_request.number' $GITHUB_EVENT_PATH)
tag_name="new-contributor"
curl -X POST -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-d "{\"labels\":[\"$tag_name\"]}" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/$pr_number/labels"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}