|
1 | | -name: Auto Assign Copilot to Issues |
| 1 | +name: Copilot on label |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | issues: |
5 | | - types: |
6 | | - - opened |
7 | | - - labeled |
| 5 | + types: [labeled] |
8 | 6 |
|
9 | 7 | permissions: |
10 | 8 | issues: write |
11 | 9 |
|
12 | 10 | jobs: |
13 | | - ensure-labels: |
14 | | - runs-on: [self-hosted, linux, x64, big] |
15 | | - if: github.event.action == 'opened' || (github.event.action == 'labeled' && github.event.label.name == 'copilot') |
| 11 | + copilot: |
| 12 | + # only run when the label that was added is exactly "copilot" |
| 13 | + if: github.event.label.name == 'copilot' |
| 14 | + runs-on: ubuntu-latest |
16 | 15 | steps: |
17 | | - - name: Ensure required labels exist |
| 16 | + - name: Comment and (optionally) add model label |
18 | 17 | uses: actions/github-script@v7 |
19 | 18 | with: |
20 | 19 | github-token: ${{ secrets.GITHUB_TOKEN }} |
21 | 20 | script: | |
22 | | - // Define all required labels |
23 | | - const requiredLabels = [ |
24 | | - { |
25 | | - name: 'copilot', |
26 | | - color: '0E8A16', |
27 | | - description: 'Assign this issue to GitHub Copilot' |
28 | | - }, |
29 | | - { |
30 | | - name: 'copilot-gpt-5.1-codex', |
31 | | - color: '1D76DB', |
32 | | - description: 'Use GPT-5.1-Codex model for Copilot' |
33 | | - }, |
34 | | - { |
35 | | - name: 'copilot-gpt-5.1', |
36 | | - color: '5319E7', |
37 | | - description: 'Use GPT-5.1 model for Copilot' |
38 | | - }, |
39 | | - { |
40 | | - name: 'copilot-claude-4.5-opus', |
41 | | - color: 'D93F0B', |
42 | | - description: 'Use Claude 4.5 Opus model for Copilot' |
43 | | - } |
44 | | - ]; |
45 | | -
|
46 | | - // Get existing labels in the repository |
47 | | - const { data: existingLabels } = await github.rest.issues.listLabelsForRepo({ |
48 | | - owner: context.repo.owner, |
49 | | - repo: context.repo.repo, |
50 | | - per_page: 100 |
| 21 | + const owner = context.repo.owner; |
| 22 | + const repo = context.repo.repo; |
| 23 | + const issue_number = context.issue.number; |
| 24 | +
|
| 25 | + // 1) Comment to summon Copilot |
| 26 | + await github.rest.issues.createComment({ |
| 27 | + owner, |
| 28 | + repo, |
| 29 | + issue_number, |
| 30 | + body: '@copilot :)' |
51 | 31 | }); |
52 | 32 |
|
53 | | - const existingLabelNames = new Set(existingLabels.map(l => l.name)); |
54 | | -
|
55 | | - // Create missing labels |
56 | | - for (const label of requiredLabels) { |
57 | | - if (!existingLabelNames.has(label.name)) { |
58 | | - try { |
59 | | - await github.rest.issues.createLabel({ |
60 | | - owner: context.repo.owner, |
61 | | - repo: context.repo.repo, |
62 | | - name: label.name, |
63 | | - color: label.color, |
64 | | - description: label.description |
65 | | - }); |
66 | | - console.log(`✅ Created label: ${label.name}`); |
67 | | - } catch (error) { |
68 | | - console.log(`⚠️ Failed to create label ${label.name}: ${error.message}`); |
69 | | - } |
70 | | - } else { |
71 | | - console.log(`ℹ️ Label already exists: ${label.name}`); |
72 | | - } |
73 | | - } |
74 | | -
|
75 | | - auto-assign: |
76 | | - runs-on: [self-hosted, linux, x64, big] |
77 | | - needs: ensure-labels |
78 | | - if: contains(github.event.issue.labels.*.name, 'copilot') |
79 | | - steps: |
80 | | - - name: Assign Copilot to issue |
81 | | - uses: actions/github-script@v7 |
82 | | - with: |
83 | | - github-token: ${{ secrets.GITHUB_TOKEN }} |
84 | | - script: | |
85 | | - const copilotUsername = "copilot"; |
| 33 | + // 2) Optional: add a model-selection label (only if you want this behavior) |
| 34 | + const modelLabel = 'copilot-gpt-5.3'; |
86 | 35 |
|
87 | | - // Check if issue is already assigned to copilot |
88 | | - const currentAssignees = context.payload.issue.assignees.map(u => u.login); |
89 | | -
|
90 | | - if (!currentAssignees.includes(copilotUsername)) { |
91 | | - console.log(`Issue has 'copilot' label. Assigning @${copilotUsername}...`); |
92 | | -
|
93 | | - try { |
94 | | - await github.rest.issues.addAssignees({ |
95 | | - owner: context.repo.owner, |
96 | | - repo: context.repo.repo, |
97 | | - issue_number: context.issue.number, |
98 | | - assignees: [copilotUsername] |
99 | | - }); |
100 | | - console.log(`✅ Assigned @${copilotUsername} to issue #${context.issue.number}`); |
101 | | - } catch (error) { |
102 | | - console.log(`⚠️ Failed to assign Copilot: ${error.message}`); |
103 | | - console.log("Note: You must have a Copilot seat assigned to your account/org for this to work."); |
104 | | - } |
105 | | - } else { |
106 | | - console.log(`ℹ️ @${copilotUsername} is already assigned to issue #${context.issue.number}`); |
| 36 | + // Try to create the label (ignore if it already exists) |
| 37 | + try { |
| 38 | + await github.rest.issues.createLabel({ |
| 39 | + owner, |
| 40 | + repo, |
| 41 | + name: modelLabel, |
| 42 | + color: '5319E7', |
| 43 | + description: 'Prefer GPT-5.3 for Copilot (if supported)' |
| 44 | + }); |
| 45 | + } catch (e) { |
| 46 | + // 422 = already exists (or validation). We can safely ignore. |
107 | 47 | } |
108 | 48 |
|
109 | | - - name: Add comment about model selection |
110 | | - uses: actions/github-script@v7 |
111 | | - with: |
112 | | - github-token: ${{ secrets.GITHUB_TOKEN }} |
113 | | - script: | |
114 | | - const issueLabels = context.payload.issue.labels.map(l => l.name); |
115 | | - |
116 | | - // Check which model label is present |
117 | | - const modelLabels = [ |
118 | | - 'copilot-gpt-5.1-codex', |
119 | | - 'copilot-gpt-5.1', |
120 | | - 'copilot-claude-4.5-opus' |
121 | | - ]; |
122 | | - |
123 | | - const selectedModel = modelLabels.find(label => issueLabels.includes(label)); |
124 | | - |
125 | | - // Check if we've already commented |
126 | | - const { data: comments } = await github.rest.issues.listComments({ |
127 | | - owner: context.repo.owner, |
128 | | - repo: context.repo.repo, |
129 | | - issue_number: context.issue.number |
130 | | - }); |
131 | | - |
132 | | - const botComment = comments.find(c => |
133 | | - c.user.type === 'Bot' && |
134 | | - c.body.includes('GitHub Copilot has been assigned') |
135 | | - ); |
136 | | - |
137 | | - if (!botComment) { |
138 | | - let message = '🤖 **GitHub Copilot has been assigned to this issue!**\n\n'; |
139 | | - |
140 | | - if (selectedModel) { |
141 | | - message += `📊 **Model selected:** \`${selectedModel}\`\n\n`; |
142 | | - } else { |
143 | | - message += '📊 **Model selection:** To specify a Copilot model, add one of these labels:\n'; |
144 | | - message += '- `copilot-gpt-5.1-codex` - Best for code generation and analysis\n'; |
145 | | - message += '- `copilot-gpt-5.1` - Latest GPT model\n'; |
146 | | - message += '- `copilot-claude-4.5-opus` - Claude model for code review\n\n'; |
147 | | - } |
148 | | - |
149 | | - message += '💡 **Next steps:**\n'; |
150 | | - message += '- Copilot will analyze the issue and provide assistance\n'; |
151 | | - message += '- You can interact with Copilot by mentioning `@copilot` in comments\n'; |
152 | | - |
153 | | - await github.rest.issues.createComment({ |
154 | | - owner: context.repo.owner, |
155 | | - repo: context.repo.repo, |
156 | | - issue_number: context.issue.number, |
157 | | - body: message |
| 49 | + // Add the label to the issue if it isn't already present |
| 50 | + const existing = new Set(context.payload.issue.labels.map(l => l.name)); |
| 51 | + if (!existing.has(modelLabel)) { |
| 52 | + await github.rest.issues.addLabels({ |
| 53 | + owner, |
| 54 | + repo, |
| 55 | + issue_number, |
| 56 | + labels: [modelLabel] |
158 | 57 | }); |
159 | | - |
160 | | - console.log('✅ Added informational comment'); |
161 | 58 | } |
0 commit comments