166 lines (144 loc) · 6.29 KB
/
issue_automation.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
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
name: "Issue Automation"
on:
issues:
types: [opened, edited, closed, reopened, labeled, unlabeled]
jobs:
issue-automation:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let labels = context.payload.issue.labels.map(label => label.name);
let setLabels = false;
switch (context.payload.action) {
case 'opened':
case 'edited': {
if (context.payload.issue.title.match(/\[request\]|feature request/i)) {
labels.push('request');
labels = labels.filter(label => label !== 'triage');
setLabels = true;
}
if (context.payload.issue.title.match(/\[rc feedback\]/i)) {
labels.push('rc feedback');
labels = labels.filter(label => label !== 'triage');
setLabels = true;
}
if (context.payload.issue.title.match(/\[task\]/i)) {
labels.push('task');
labels = labels.filter(label => label !== 'triage');
setLabels = true;
}
if (labels.length === 0) {
labels.push('triage');
setLabels = true;
}
break;
}
case 'closed': {
if (labels.includes('bug') || labels.includes('request') || labels.includes('improvement') || labels.includes('task')) {
labels.push('done');
setLabels = true;
}
break;
}
case 'reopened': {
if (labels.includes('done')) {
labels = labels.filter(label => label !== 'done');
setLabels = true;
}
break;
}
}
if (setLabels) {
github.rest.issues.setLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: labels
})
}
#- uses: OctoPrint/actions/issue-validation@main
# if: github.event_name == 'issues' && (github.event.action == 'opened' || github.event.action == 'edited')
# with:
# repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/github-script@v5
env:
REMINDER: >
Hi @${{ github.event.issue.user.login }}!
It looks like you didn't upload a [system info bundle](https://community.octoprint.org/t/29887) as requested by the template.
A bundle is required to further process your issue. It contains important logs and
system information to be able to put your issue into context and give pointers as to
what has happened.
Please **edit your original post above** and upload **a bundle zip file**. Actually upload the file please and
do not paste some link to a cloud provider, we want to have everything in one place here. Also do
not unpack, repack or otherwise modify the bundle or its name, share it **exactly** like you get it from OctoPrint.
Without the availability of a bundle, your issue will have to be closed.
Thank you for your collaboration.
THANKYOU: >
Thank you @${{ github.event.issue.user.login }} for adding a bundle! Now this can actually get looked at.
with:
script: |
const { REMINDER, THANKYOU } = process.env;
const bundleRegex = /\[(octoprint-systeminfo-\d{14}\.zip)\]\(([^)]+)\)/g;
const marker = "<!-- check_for_bundle -->";
const issueLabels = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
let labels = issueLabels.data.map(label => label.name);
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
})
const comment = comments.data.find(c => c.user.login === "github-actions[bot]" && c.body.includes(marker));
if (comment) {
console.log("Found comment, id=" + comment.id);
} else {
console.log("No comment found");
}
if (!labels.includes("triage") || labels.includes("approved")) {
console.log("Deleting comment if it exists...");
if (comment) {
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id,
})
}
return;
}
const found = !!context.payload.issue.body.match(bundleRegex);
if (!found) {
console.log("No bundle found, posting/updating reminder");
const text = REMINDER + "\n" + marker;
if (!comment) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: text
});
} else if (comment.body !== text) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id,
body: text
});
}
} else if (found && comment) {
console.log("Bundle found, saying thanks");
const text = REMINDER.split("\n\n").map(line => `~~${line.trim()}~~`).join("\n\n") + "\n\n" + THANKYOU + "\n" + marker;
if (comment.body !== text) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id,
body: text
});
}
}