|
1 | 1 | name: Auto Assign Copilot to Issues |
2 | | -uto-amazonq-review.properties.json |
3 | 2 |
|
4 | | -uto-amazonq-review.properties.json |
5 | 3 | on: |
6 | | -uto-amazonq-review.properties.json |
7 | 4 | issues: |
8 | | -uto-amazonq-review.properties.json |
9 | 5 | types: |
10 | | -uto-amazonq-review.properties.json |
11 | 6 | - opened |
12 | | -uto-amazonq-review.properties.json |
13 | 7 | - labeled |
14 | | -uto-amazonq-review.properties.json |
15 | 8 |
|
16 | | -uto-amazonq-review.properties.json |
| 9 | +permissions: |
| 10 | + issues: write |
| 11 | + |
17 | 12 | jobs: |
18 | | -uto-amazonq-review.properties.json |
| 13 | + ensure-labels: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + if: github.event.action == 'opened' || (github.event.action == 'labeled' && github.event.label.name == 'copilot') |
| 16 | + steps: |
| 17 | + - name: Ensure required labels exist |
| 18 | + uses: actions/github-script@v7 |
| 19 | + with: |
| 20 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 21 | + 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 |
| 51 | + }); |
| 52 | +
|
| 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 | +
|
19 | 75 | auto-assign: |
20 | | -uto-amazonq-review.properties.json |
21 | | - runs-on: self-hosted |
22 | | -uto-amazonq-review.properties.json |
| 76 | + runs-on: ubuntu-latest |
| 77 | + needs: ensure-labels |
23 | 78 | if: contains(github.event.issue.labels.*.name, 'copilot') |
24 | | -uto-amazonq-review.properties.json |
25 | 79 | steps: |
26 | | -uto-amazonq-review.properties.json |
27 | | - - name: Assign Copilot to new issues |
28 | | -uto-amazonq-review.properties.json |
29 | | - uses: actions/github-script@main |
30 | | -uto-amazonq-review.properties.json |
| 80 | + - name: Assign Copilot to issue |
| 81 | + uses: actions/github-script@v7 |
31 | 82 | with: |
32 | | -uto-amazonq-review.properties.json |
33 | 83 | github-token: ${{ secrets.GITHUB_TOKEN }} |
34 | | -uto-amazonq-review.properties.json |
35 | 84 | script: | |
36 | | -uto-amazonq-review.properties.json |
37 | 85 | const copilotUsername = "copilot"; |
38 | | -uto-amazonq-review.properties.json |
39 | 86 |
|
40 | | -uto-amazonq-review.properties.json |
41 | 87 | // Check if issue is already assigned to copilot |
42 | | -uto-amazonq-review.properties.json |
43 | 88 | const currentAssignees = context.payload.issue.assignees.map(u => u.login); |
44 | | -uto-amazonq-review.properties.json |
45 | 89 |
|
46 | | -uto-amazonq-review.properties.json |
47 | 90 | if (!currentAssignees.includes(copilotUsername)) { |
48 | | -uto-amazonq-review.properties.json |
49 | 91 | console.log(`Issue has 'copilot' label. Assigning @${copilotUsername}...`); |
50 | | -uto-amazonq-review.properties.json |
51 | 92 |
|
52 | | -uto-amazonq-review.properties.json |
53 | 93 | try { |
54 | | -uto-amazonq-review.properties.json |
55 | 94 | await github.rest.issues.addAssignees({ |
56 | | -uto-amazonq-review.properties.json |
57 | 95 | owner: context.repo.owner, |
58 | | -uto-amazonq-review.properties.json |
59 | 96 | repo: context.repo.repo, |
60 | | -uto-amazonq-review.properties.json |
61 | 97 | issue_number: context.issue.number, |
62 | | -uto-amazonq-review.properties.json |
63 | 98 | assignees: [copilotUsername] |
64 | | -uto-amazonq-review.properties.json |
65 | 99 | }); |
66 | | -uto-amazonq-review.properties.json |
67 | 100 | console.log(`✅ Assigned @${copilotUsername} to issue #${context.issue.number}`); |
68 | | -uto-amazonq-review.properties.json |
69 | 101 | } catch (error) { |
70 | | -uto-amazonq-review.properties.json |
71 | 102 | console.log(`⚠️ Failed to assign Copilot: ${error.message}`); |
72 | | -uto-amazonq-review.properties.json |
73 | 103 | console.log("Note: You must have a Copilot seat assigned to your account/org for this to work."); |
74 | | -uto-amazonq-review.properties.json |
75 | 104 | } |
76 | | -uto-amazonq-review.properties.json |
77 | 105 | } else { |
78 | | -uto-amazonq-review.properties.json |
79 | 106 | console.log(`ℹ️ @${copilotUsername} is already assigned to issue #${context.issue.number}`); |
80 | | -uto-amazonq-review.properties.json |
81 | 107 | } |
82 | | -uto-amazonq-review.properties.json |
| 108 | +
|
| 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 |
| 158 | + }); |
| 159 | + |
| 160 | + console.log('✅ Added informational comment'); |
| 161 | + } |
0 commit comments