forked from alibaba/zvec
-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (88 loc) · 3.84 KB
/
issue-auto-assign.yml
File metadata and controls
99 lines (88 loc) · 3.84 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
name: Issue Auto Assign
on:
issues:
types: [opened]
jobs:
auto-assign:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Parse issue and assign
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue;
const issueBody = issue.body || '';
const issueLabels = (issue.labels || []).map(l => l.name);
// Default assignees per template type (based on labels)
const defaultAssignees = {
'bug': 'zhourrr',
'feature': 'feihongxu0824',
'benchmark': 'egolearner',
'enhancement': 'feihongxu0824',
'integration': 'chinaux',
'profile': 'richyreachy'
};
// Global fallback assignee
const fallbackAssignee = 'feihongxu0824';
// Parse user-selected assignee from issue body
// The input field renders as: "### Preferred Assignee\n\n<entered_value>"
let selectedAssignee = null;
const assigneeMatch = issueBody.match(/### Preferred Assignee\s*\n+([^\n#]+)/);
if (assigneeMatch) {
const selection = assigneeMatch[1].trim();
console.log(`Parsed assignee input: "${selection}"`);
// If user entered a valid GitHub username (not empty, not placeholder text)
if (selection &&
selection !== '_No response_' &&
selection !== 'None' &&
!selection.toLowerCase().includes('leave empty') &&
!selection.startsWith('e.g.,')) {
// Clean up the username (remove @ if present)
selectedAssignee = selection.replace(/^@/, '').trim();
}
}
// Determine final assignee
let finalAssignee = selectedAssignee;
// If no user selection, use default based on label
if (!finalAssignee && issueLabels.length > 0) {
for (const [label, assignee] of Object.entries(defaultAssignees)) {
if (issueLabels.includes(label)) {
finalAssignee = assignee;
console.log(`Matched label "${label}" -> assignee "${assignee}"`);
break;
}
}
}
// Fallback to default assignee if no match
if (!finalAssignee) {
finalAssignee = fallbackAssignee;
console.log(`No match found, using fallback assignee: ${fallbackAssignee}`);
}
console.log(`Issue #${issue.number}: Labels = [${issueLabels.join(', ')}]`);
console.log(`User selected assignee: ${selectedAssignee || 'None (Auto)'}`);
console.log(`Final assignee: ${finalAssignee}`);
// Assign the issue
try {
await github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
assignees: [finalAssignee]
});
console.log(`Successfully assigned issue #${issue.number} to ${finalAssignee}`);
} catch (error) {
console.error(`Failed to assign issue: ${error.message}`);
// If assignment fails (user may not have permission), add a comment
try {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: `⚠️ Auto-assignment to \`${finalAssignee}\` failed. Please assign manually.`
});
} catch (commentError) {
console.error(`Failed to create comment: ${commentError.message}`);
}
}