-
Notifications
You must be signed in to change notification settings - Fork 27
161 lines (141 loc) · 6.03 KB
/
auto-assign-copilot.yml
File metadata and controls
161 lines (141 loc) · 6.03 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
name: Auto Assign Copilot to Issues
on:
issues:
types:
- opened
- labeled
permissions:
issues: write
jobs:
ensure-labels:
runs-on: ubuntu-latest
if: github.event.action == 'opened' || (github.event.action == 'labeled' && github.event.label.name == 'copilot')
steps:
- name: Ensure required labels exist
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Define all required labels
const requiredLabels = [
{
name: 'copilot',
color: '0E8A16',
description: 'Assign this issue to GitHub Copilot'
},
{
name: 'copilot-gpt-5.1-codex',
color: '1D76DB',
description: 'Use GPT-5.1-Codex model for Copilot'
},
{
name: 'copilot-gpt-5.1',
color: '5319E7',
description: 'Use GPT-5.1 model for Copilot'
},
{
name: 'copilot-claude-4.5-opus',
color: 'D93F0B',
description: 'Use Claude 4.5 Opus model for Copilot'
}
];
// Get existing labels in the repository
const { data: existingLabels } = await github.rest.issues.listLabelsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100
});
const existingLabelNames = new Set(existingLabels.map(l => l.name));
// Create missing labels
for (const label of requiredLabels) {
if (!existingLabelNames.has(label.name)) {
try {
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: label.name,
color: label.color,
description: label.description
});
console.log(`✅ Created label: ${label.name}`);
} catch (error) {
console.log(`⚠️ Failed to create label ${label.name}: ${error.message}`);
}
} else {
console.log(`ℹ️ Label already exists: ${label.name}`);
}
}
auto-assign:
runs-on: ubuntu-latest
needs: ensure-labels
if: contains(github.event.issue.labels.*.name, 'copilot')
steps:
- name: Assign Copilot to issue
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const copilotUsername = "copilot";
// Check if issue is already assigned to copilot
const currentAssignees = context.payload.issue.assignees.map(u => u.login);
if (!currentAssignees.includes(copilotUsername)) {
console.log(`Issue has 'copilot' label. Assigning @${copilotUsername}...`);
try {
await github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
assignees: [copilotUsername]
});
console.log(`✅ Assigned @${copilotUsername} to issue #${context.issue.number}`);
} catch (error) {
console.log(`⚠️ Failed to assign Copilot: ${error.message}`);
console.log("Note: You must have a Copilot seat assigned to your account/org for this to work.");
}
} else {
console.log(`ℹ️ @${copilotUsername} is already assigned to issue #${context.issue.number}`);
}
- name: Add comment about model selection
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issueLabels = context.payload.issue.labels.map(l => l.name);
// Check which model label is present
const modelLabels = [
'copilot-gpt-5.1-codex',
'copilot-gpt-5.1',
'copilot-claude-4.5-opus'
];
const selectedModel = modelLabels.find(label => issueLabels.includes(label));
// Check if we've already commented
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
const botComment = comments.find(c =>
c.user.type === 'Bot' &&
c.body.includes('GitHub Copilot has been assigned')
);
if (!botComment) {
let message = '🤖 **GitHub Copilot has been assigned to this issue!**\n\n';
if (selectedModel) {
message += `📊 **Model selected:** \`${selectedModel}\`\n\n`;
} else {
message += '📊 **Model selection:** To specify a Copilot model, add one of these labels:\n';
message += '- `copilot-gpt-5.1-codex` - Best for code generation and analysis\n';
message += '- `copilot-gpt-5.1` - Latest GPT model\n';
message += '- `copilot-claude-4.5-opus` - Claude model for code review\n\n';
}
message += '💡 **Next steps:**\n';
message += '- Copilot will analyze the issue and provide assistance\n';
message += '- You can interact with Copilot by mentioning `@copilot` in comments\n';
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: message
});
console.log('✅ Added informational comment');
}