-
Notifications
You must be signed in to change notification settings - Fork 152
105 lines (94 loc) · 3.55 KB
/
on-create-notes.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: 'On Create: Remove Governed Label'
on:
discussion:
types: [created]
jobs:
check_labels:
name: Check labels
runs-on: ubuntu-latest
steps:
- name: Check if employee
id: check_employee
uses: actions/github-script@v6
with:
github-token: ${{ secrets.READ_GITHUB_ORG_MEMBERS_TOKEN }}
result-encoding: string
script: |
console.log(context.payload);
try {
const response = await github.rest.orgs.checkMembershipForUser({
org: `github`,
username: context.payload.sender.login
});
if (response.status === 204) {
return 'true';
} else {
return 'false';
}
} catch (error) {
console.log(error);
return 'false';
}
- name: Fetch label id
id: fetch_label_id
if: ${{ steps.check_employee.outputs.result == 'false' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
// how to format query for topic take multiple inputs? https://graphql.org/learn/queries/ TOPIC: 'more information needed'
run: |
gh api graphql -F owner=$OWNER -F name=$REPO -F topic="$TOPIC" -f query='
query($owner: String!, $name: String!, $topic: String) {
repository(owner: $owner, name: $name){
// needs to be more than fist 1 labels(first: 1, query: $topic) {
edges {
node {
id
name
}
}
}
}
}' > repository_label_data.json
echo 'LABEL_ID='$(jq '.data.repository.labels.edges[].node | .id ' repository_label_data.json) >> $GITHUB_ENV
- name: Fetch discussion ID
id: fetch_discussion_id
if: ${{ steps.check_employee.outputs.result == 'false' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
TOPIC: 'more information needed'
run: |
gh api graphql -F owner=$OWNER -F name=$REPO -f query='
query($owner: String!, $name: String!) {
repository(owner: $owner, name: $name) {
discussion(number: ${{ github.event.discussion.number }}) {
id
}
}
}' > discussion_data.json
echo 'DISCUSSION_ID='$(jq '.data.repository.discussion.id' discussion_data.json) >> $GITHUB_ENV
- name: Unlabel the discussion
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
TOPIC: 'more information needed'
run: |
gh api graphql -f query='
mutation($labelableId: ID!, $labelIds: [ID!]!) {
removeLabelsFromLabelable(input: {labelableId: $labelableId, labelIds: $labelIds}) {
labelable {
labels(first: 10) {
edges {
node {
id
name
}
}
}
}
}
}' -f labelableId=$DISCUSSION_ID -f labelIds=$LABEL_ID