-
Notifications
You must be signed in to change notification settings - Fork 390
207 lines (177 loc) · 7.64 KB
/
Copy pathissue-assignment-tracking.yml
File metadata and controls
207 lines (177 loc) · 7.64 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
name: Issue Assignment Tracking
# Tracks issue assignments in real-time and clears reminder labels when activity happens
on:
issues:
types: [assigned, unassigned]
issue_comment:
types: [created]
pull_request:
types: [opened, edited]
permissions:
issues: write
pull-requests: read
jobs:
# Handle new assignments
on-assignment:
if: github.event_name == 'issues' && github.event.action == 'assigned'
runs-on: ubuntu-latest
steps:
- name: Welcome new assignee
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue;
const assignee = context.payload.assignee;
console.log(`Issue #${issue.number} assigned to ${assignee.login}`);
// Check if this is the first assignment (no previous reminder labels)
const labels = issue.labels.map(l => l.name);
const hasReminderLabels = labels.some(l =>
['reminder-sent', 'needs-update'].includes(l)
);
// Remove 'help wanted' label if present
if (labels.includes('help wanted')) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
name: 'help wanted'
}).catch(() => {});
}
// Only welcome if this is a fresh assignment (no previous reminders)
if (!hasReminderLabels) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: `Thanks for picking this up, @${assignee.login}! :tada:\n\n**Here's what to expect:**\n- We'll check in after **7 days** if we haven't heard an update\n- After **14 days**, we'll send a second reminder\n- After **21 days** without activity, we'll unassign to let others contribute\n\n**Tips for success:**\n- Drop a comment when you start working on it\n- Share any blockers - we're here to help!\n- Link your PR with \`Fixes #${issue.number}\` in the description\n\nHappy coding! :rocket:`
});
}
# Clear reminder labels when assignee comments
on-assignee-comment:
if: github.event_name == 'issue_comment'
runs-on: ubuntu-latest
steps:
- name: Clear reminder labels on assignee activity
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue;
const comment = context.payload.comment;
const commenter = comment.user.login;
// Skip if this is a PR comment
if (issue.pull_request) return;
// Check if commenter is an assignee
const assignees = issue.assignees.map(a => a.login);
if (!assignees.includes(commenter)) {
console.log(`Commenter ${commenter} is not an assignee, skipping`);
return;
}
console.log(`Assignee ${commenter} commented on #${issue.number}`);
const labels = issue.labels.map(l => l.name);
const reminderLabels = ['reminder-sent', 'needs-update'].filter(l => labels.includes(l));
if (reminderLabels.length === 0) {
console.log('No reminder labels to clear');
return;
}
// Clear reminder labels
for (const label of reminderLabels) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
name: label
}).catch(() => {});
}
console.log(`Cleared labels: ${reminderLabels.join(', ')}`);
# Handle unassignment
on-unassignment:
if: github.event_name == 'issues' && github.event.action == 'unassigned'
runs-on: ubuntu-latest
steps:
- name: Handle unassignment
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue;
const unassignee = context.payload.assignee;
console.log(`${unassignee.login} unassigned from #${issue.number}`);
// If no assignees left, add 'help wanted' label
if (issue.assignees.length === 0) {
const labels = issue.labels.map(l => l.name);
// Clear any reminder labels
for (const label of ['reminder-sent', 'needs-update']) {
if (labels.includes(label)) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
name: label
}).catch(() => {});
}
}
// Add 'help wanted' if not already present
if (!labels.includes('help wanted')) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: ['help wanted']
});
}
}
# Track PRs that link to issues
on-pr-link:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Clear reminders when PR is linked
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const prAuthor = pr.user.login;
const text = `${pr.title} ${pr.body || ''}`;
// Find linked issues
const issueMatches = text.match(/(close[sd]?|fix(e[sd])?|resolve[sd]?)[\s:]*#(\d+)/gi) || [];
const issueNumbers = [...new Set(
issueMatches.map(m => {
const num = m.match(/#(\d+)/);
return num ? parseInt(num[1]) : null;
}).filter(Boolean)
)];
if (issueNumbers.length === 0) {
console.log('No linked issues found in PR');
return;
}
console.log(`PR #${pr.number} links to issues: ${issueNumbers.join(', ')}`);
for (const issueNumber of issueNumbers) {
try {
const issue = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber
});
// Check if PR author is an assignee
const assignees = issue.data.assignees.map(a => a.login);
if (!assignees.includes(prAuthor)) {
console.log(`PR author ${prAuthor} is not assigned to #${issueNumber}`);
continue;
}
const labels = issue.data.labels.map(l => l.name);
const reminderLabels = ['reminder-sent', 'needs-update'].filter(l => labels.includes(l));
// Clear reminder labels
for (const label of reminderLabels) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
name: label
}).catch(() => {});
}
if (reminderLabels.length > 0) {
console.log(`Cleared labels on #${issueNumber}: ${reminderLabels.join(', ')}`);
}
} catch (err) {
console.log(`Error processing issue #${issueNumber}: ${err.message}`);
}
}