-
-
Notifications
You must be signed in to change notification settings - Fork 3k
159 lines (143 loc) Β· 5.88 KB
/
issue-autoassign.yml
File metadata and controls
159 lines (143 loc) Β· 5.88 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
name: Issue Auto-Assign
on:
issues:
types: [labeled]
permissions:
issues: write
jobs:
auto-assign:
name: Auto-assign to Copilot
runs-on: ubuntu-latest
steps:
- name: Assign to Copilot on auto-fix label
if: |
github.event.label.name == 'auto-fix' ||
github.event.label.name == 'copilot'
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue;
// Assign to Copilot
try {
await github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
assignees: ['copilot'],
});
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: [
':robot: This issue has been assigned to **Copilot** for automated resolution.',
'',
'Copilot will analyse the issue and open a draft PR with the proposed fix.',
'A maintainer will review the changes before merging.',
'',
'_If Copilot cannot resolve this automatically, a maintainer will follow up manually._',
].join('\n'),
});
core.info(`Issue #${issue.number} assigned to Copilot.`);
} catch (err) {
core.warning(`Could not assign to Copilot: ${err.message}`);
// Fallback: add comment directing maintainer
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: ':robot: Attempted to auto-assign this issue to Copilot, but assignment was not possible. A maintainer will review this manually.',
});
}
- name: Label critical issues
if: github.event.label.name == 'critical'
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue;
// Assign to maintainer
try {
await github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
assignees: ['dr5hn'],
});
} catch (err) {
core.warning(`Could not assign to maintainer: ${err.message}`);
}
// Notify via Slack if webhook is configured
const webhookUrl = process.env.SLACK_WEBHOOK_URL;
if (webhookUrl) {
const https = require('https');
const payload = JSON.stringify({
attachments: [{
color: '#FF0000',
blocks: [
{
type: 'header',
text: { type: 'plain_text', text: ':rotating_light: Critical Issue', emoji: true },
},
{
type: 'section',
fields: [
{ type: 'mrkdwn', text: `*Issue:* <${issue.html_url}|#${issue.number}> ${issue.title}` },
{ type: 'mrkdwn', text: `*Author:* ${issue.user.login}` },
],
},
],
}],
});
const url = new URL(webhookUrl);
const data = payload;
await new Promise((resolve) => {
const req = https.request({
hostname: url.hostname,
path: url.pathname,
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(data) },
}, (res) => {
if (res.statusCode !== 200) core.warning(`Slack responded with ${res.statusCode}`);
resolve();
});
req.on('error', (err) => {
core.warning(`Slack error: ${err.message}`);
resolve();
});
req.write(data);
req.end();
});
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Add template for data corrections
if: github.event.label.name == 'data-correction'
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue;
// Only add template if issue body is sparse
if (issue.body && issue.body.length > 200) return;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: [
'Thanks for reporting this data correction! To help us process this efficiently, please ensure you have provided:',
'',
'- [ ] **Entity type** (city, state, or country)',
'- [ ] **Entity name** and current incorrect data',
'- [ ] **Correct data** with source URL',
'- [ ] **Country/State** context',
'',
'If you\'d like to fix this yourself, you can submit a PR editing the relevant file in the `contributions/` directory.',
'Alternatively, use our [CSC Update Tool](https://manager.countrystatecity.in/) for a guided process.',
].join('\n'),
});
// Add help-wanted label
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: ['help-wanted'],
});