-
Notifications
You must be signed in to change notification settings - Fork 31
104 lines (91 loc) · 4.21 KB
/
Copy pathissue-handler.yml
File metadata and controls
104 lines (91 loc) · 4.21 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
name: Issue Auto Handler
on:
issues:
types: [opened, labeled]
permissions:
issues: write
jobs:
# Job 1: Auto-reply when a new issue is opened
auto-reply:
if: github.event.action == 'opened'
runs-on: ubuntu-latest
steps:
- name: Post welcome comment
uses: actions/github-script@v7
with:
script: |
const issueNumber = context.issue.number;
const author = context.payload.issue.user.login;
const body = [
`👋 你好 @${author},感谢你提交这个 Issue!`,
'',
'我们已收到你的反馈,会尽快查看。在此之前,请确认以下信息以帮助我们更快地定位问题:',
'',
'- **环境信息**:操作系统、浏览器版本、相关工具版本等',
'- **复现步骤**:如何稳定触发该问题',
'- **期望行为 vs 实际行为**:你预期看到什么,实际发生了什么',
'',
'如果是功能建议,请描述你期望的使用场景和预期效果。',
'',
'> 🤖 此回复由自动化工作流生成。'
].join('\n');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: body
});
# Job 2: Assign to Copilot coding agent when bug label is added
assign-copilot-on-bug:
if: github.event.action == 'labeled' && github.event.label.name == 'bug'
runs-on: ubuntu-latest
steps:
- name: Assign issue to Copilot coding agent
uses: actions/github-script@v7
with:
github-token: ${{ secrets.COPILOT_ASSIGN_TOKEN }}
script: |
const issueNumber = context.issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
const baseBranch = context.payload.repository.default_branch;
console.log(`Bug label added to issue #${issueNumber}, assigning to Copilot coding agent...`);
try {
const response = await github.request(
'POST /repos/{owner}/{repo}/issues/{issue_number}/assignees',
{
owner,
repo,
issue_number: issueNumber,
assignees: ['copilot-swe-agent[bot]'],
agent_assignment: {
target_repo: `${owner}/${repo}`,
base_branch: baseBranch,
custom_instructions: '',
custom_agent: '',
model: ''
}
}
);
const assignees = (response.data.assignees || []).map(a => String(a.login || a.name || '').trim());
const assigned = assignees.some(a => a.toLowerCase().includes('copilot'));
if (!assigned) {
throw new Error(`Copilot coding agent was not found in assignees after the API call. Current assignees: ${assignees.join(', ') || '(none)'}`);
}
console.log('Successfully assigned to Copilot coding agent.');
await github.rest.issues.createComment({
owner,
repo,
issue_number: issueNumber,
body: '🐛 已识别为 Bug,并已成功分配给 Copilot coding agent。Copilot 将继续分析问题并尝试创建修复 PR。\n\n> 🤖 此回复由自动化工作流生成。'
});
} catch (error) {
const errMsg = String(error.message).replace(/[`$\\]/g, '');
console.error(`Failed to assign Copilot coding agent: ${errMsg}`);
await github.rest.issues.createComment({
owner,
repo,
issue_number: issueNumber,
body: `⚠️ 尝试将此 Issue 分配给 Copilot coding agent 失败:\n\n\`${errMsg}\`\n\n请检查仓库是否已启用 Copilot coding agent,以及当前仓库策略是否允许通过 API 自动分配。\n\n> 🤖 此回复由自动化工作流生成。`
});
}