-
Notifications
You must be signed in to change notification settings - Fork 22
43 lines (38 loc) · 1.82 KB
/
assigned-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
40
41
42
43
name: Manage label based on assignee changes
on:
issues:
types: [opened, edited, reopened, assigned, unassigned, labeled, unlabeled]
jobs:
manage_label:
runs-on: ubuntu-latest
steps:
- name: Check if issue has an assignee
id: check_assignee
run: echo "::set-output name=assignee::$(jq -r '.issue.assignee.login // empty' $GITHUB_EVENT_PATH)"
- name: Determine if assignee changes
id: check_assignee_changes
run: |
current_assignee=$(jq -r '.issue.assignee.login // empty' $GITHUB_EVENT_PATH)
previous_assignee=$(jq -r '.changes.assignee.previous_value // empty' $GITHUB_EVENT_PATH)
if [ "$current_assignee" != "$previous_assignee" ]; then
echo "::set-output name=assignee_changes::true"
else
echo "::set-output name=assignee_changes::false"
fi
- name: Add label if issue has an assignee
if: steps.check_assignee.outputs.assignee != '' && steps.check_assignee_changes.outputs.assignee_changes == 'true'
run: |
echo "Adding label..."
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/labels \
-d '["assigned :computer:"]'
- name: Remove label if issue has no assignee
if: steps.check_assignee.outputs.assignee == ''
run: |
echo "Removing label..."
curl -X DELETE \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/labels/assigned%20%3Acomputer%3A