-
Notifications
You must be signed in to change notification settings - Fork 12
173 lines (159 loc) · 6.29 KB
/
reconcile-issue.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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
name: Reusable Reconcile Issue
on:
workflow_call:
jobs:
event_type:
name: Check event type
runs-on: ubuntu-latest
if: github.event_name == 'issues' || github.event_name == 'pull_request'
steps:
- name: ok
run: /bin/true
labels:
needs: event_type
name: Check labels
runs-on: ubuntu-latest
if: github.event.action != 'closed'
steps:
- name: Get Token
id: get_workflow_token
uses: peter-murray/workflow-application-token-action@v3
with:
application_id: ${{ vars.KONVEYOR_BOT_ID }}
application_private_key: ${{ secrets.KONVEYOR_BOT_KEY }}
- name: Handle labels
uses: actions/github-script@v7
with:
github-token: ${{ steps.get_workflow_token.outputs.token }}
script: |
// begin helper function for adding comments
async function ensureComment(body, shouldExist) {
// Try to find the comment
for await (const { data: comments } of github.paginate.iterator(
github.rest.issues.listComments,
{
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
}
)) {
const comment = comments.find(
(comment) =>
comment.user &&
comment.user.login == "konveyor-ci-bot[bot]" &&
comment.body &&
comment.body.includes(body)
);
// If we find the comment...we are done
if (comment) {
if (!shouldExist) {
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id,
});
}
return;
}
}
// Create the comment if it doesn't exist
if (shouldExist) {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body,
});
}
}
// end helper function for adding comments
const { data: issue } = await github.rest.issues.get({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const labels = issue.labels.map(label => label.name);
console.log(`Labels: ${labels}`);
// triage label
if (labels.some(label => label.match('^triage/accepted$'))) {
if (labels.includes('needs-triage')) {
await github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: 'needs-triage'
});
}
} else {
let comment = "This issue is currently awaiting triage.\n";
comment += "If contributors determine this is a relevant issue, they will accept it by applying the `triage/accepted` label and provide further guidance.\n";
comment += "The `triage/accepted` label can be added by org members.";
await github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['needs-triage']
});
await ensureComment(comment, true);
}
// kind label
if (labels.some(label => label.match('^kind/'))) {
if (labels.includes('needs-kind')) {
await github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: 'needs-kind'
});
}
} else {
await github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['needs-kind']
});
}
// priority label
if (labels.some(label => label.match('^priority/'))) {
if (labels.includes('needs-priority')) {
await github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: 'needs-priority'
});
}
} else {
await github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['needs-priority']
});
}
// good first issue
let firstIssueComment = "This issue has been marked 'good first issue'\n";
firstIssueComment += "Please, make sure it aligns with the criteria found [here](https://contribute.cncf.io/maintainers/templates/issue-labels/#good-first-issue)\n";
if (labels.some(label => label.match('^good first issue$'))) {
await ensureComment(firstIssueComment, true);
} else {
await ensureComment(firstIssueComment, false);
}
project:
needs: event_type
name: Add new issues to planning project
runs-on: ubuntu-latest
if: github.event.action == 'opened'
steps:
- name: Get Token
id: get_workflow_token
uses: peter-murray/workflow-application-token-action@v3
with:
application_id: ${{ vars.KONVEYOR_BOT_ID }}
application_private_key: ${{ secrets.KONVEYOR_BOT_KEY }}
- name: Add to planning project
uses: actions/add-to-project@v0.5.0
with:
github-token: ${{ steps.get_workflow_token.outputs.token }}
project-url: https://github.com/orgs/konveyor/projects/67