-
Notifications
You must be signed in to change notification settings - Fork 1.5k
155 lines (149 loc) · 5.94 KB
/
Copy pathcheck-issue-status.yml
File metadata and controls
155 lines (149 loc) · 5.94 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
---
name: Check if datadog commented an issue
on:
issue_comment:
types: [created]
workflow_dispatch:
inputs:
issue_number:
description: 'Issue number to check'
required: true
type: number
jobs:
check_comment:
runs-on: ubuntu-latest
if: github.event.issue.pull_request == null
permissions:
id-token: write # Required for OIDC token
environment:
name: main
steps:
- uses: DataDog/dd-octo-sts-action@96a25462dbcb10ebf0bfd6e2ccc917d2ab235b9a # v1.0.4
id: octo-sts
with:
scope: DataDog/datadog-agent
policy: self.check-issue-status.label-issue
- name: Check if the latest comment is from a datadog member
id: datadog-comment
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ steps.octo-sts.outputs.token }}
result-encoding: string
script: |
const issueNumber = context.eventName === 'issue_comment'
? context.issue.number
: parseInt(context.payload.inputs.issue_number);
// Determine the username of the current comment's author depending on event type
let username = null;
if (context.eventName === 'issue_comment') {
username = context.payload.comment.user.login;
} else if (context.payload.inputs && context.payload.inputs.issue_number) {
// For workflow_dispatch, fetch the latest comment's author on the issue
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
});
if (comments.data.length === 0) {
// no comments, cannot determine user
return "false";
}
username = comments.data[comments.data.length - 1].user.login;
} else {
return "false";
}
try {
const membership = await github.rest.orgs.checkMembershipForUser({
org: 'datadog',
username: username
});
if (membership.status === 204) {
return "true";
}
return "false";
} catch (error) {
if (error.message.startsWith('User does not exist or is not a member')) {
// User is not a datadog member
return "false";
}
throw error;
}
- name: Remove the pending label when issue is commented
if: steps.datadog-comment.outputs.result == 'true'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ steps.octo-sts.outputs.token }}
script: |
const issueNumber = context.eventName === 'issue_comment'
? context.issue.number
: parseInt(context.payload.inputs.issue_number);
const labels = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber
});
for (const label of labels.data) {
if (label.name === 'pending') {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
name: label.name
});
}
}
- name: Remove the "waiting on author" label when issue is commented
if: steps.datadog-comment.outputs.result == 'false'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ steps.octo-sts.outputs.token }}
script: |
const issueNumber = context.eventName === 'issue_comment'
? context.issue.number
: parseInt(context.payload.inputs.issue_number);
const labels = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber
});
for (const label of labels.data) {
if (label.name === 'waiting on author') {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
name: label.name
});
}
}
- name: Remove the team/triage label if another team label exists
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ steps.octo-sts.outputs.token }}
script: |
const issueNumber = context.eventName === 'issue_comment'
? context.issue.number
: parseInt(context.payload.inputs.issue_number);
const labels = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber
});
let hasTeamLabel = false;
let hasTriageLabel = false;
for (const label of labels.data) {
if (label.name === 'team/triage') {
hasTriageLabel = true;
} else if (label.name.startsWith('team/')) {
hasTeamLabel = true;
}
}
if (hasTriageLabel && hasTeamLabel) {
// Remove only 'team/triage' label, let others be
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
name: 'team/triage'
});
}