|
8 | 8 |
|
9 | 9 | permissions: |
10 | 10 | contents: read |
| 11 | + pull-requests: write |
11 | 12 |
|
12 | 13 | jobs: |
13 | 14 | assign-copilot: |
|
19 | 20 | with: |
20 | 21 | github-token: ${{ secrets.COPILOT_ASSIGNING_PAT }} |
21 | 22 | script: | |
22 | | - await github.rest.pulls.requestReviewers({ |
| 23 | + // First, get Copilot's Bot ID from the repository |
| 24 | + const suggestedActorsQuery = ` |
| 25 | + query($owner: String!, $repo: String!) { |
| 26 | + repository(owner: $owner, name: $repo) { |
| 27 | + suggestedActors(capabilities: [CAN_BE_ASSIGNED], first: 100) { |
| 28 | + nodes { |
| 29 | + login |
| 30 | + __typename |
| 31 | + ... on Bot { |
| 32 | + id |
| 33 | + } |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + `; |
| 39 | + |
| 40 | + const actorsResult = await github.graphql(suggestedActorsQuery, { |
| 41 | + owner: context.repo.owner, |
| 42 | + repo: context.repo.repo |
| 43 | + }); |
| 44 | + |
| 45 | + const copilotBot = actorsResult.repository.suggestedActors.nodes.find( |
| 46 | + node => node.login === 'copilot-swe-agent' |
| 47 | + ); |
| 48 | + |
| 49 | + if (!copilotBot) { |
| 50 | + core.setFailed('Copilot coding agent is not enabled for this repository'); |
| 51 | + return; |
| 52 | + } |
| 53 | + |
| 54 | + core.info(`Found Copilot bot with ID: ${copilotBot.id}`); |
| 55 | + |
| 56 | + // Get the PR's global ID |
| 57 | + const prQuery = ` |
| 58 | + query($owner: String!, $repo: String!, $number: Int!) { |
| 59 | + repository(owner: $owner, name: $repo) { |
| 60 | + pullRequest(number: $number) { |
| 61 | + id |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + `; |
| 66 | + |
| 67 | + const prResult = await github.graphql(prQuery, { |
23 | 68 | owner: context.repo.owner, |
24 | 69 | repo: context.repo.repo, |
25 | | - pull_number: context.payload.pull_request.number, |
26 | | - reviewers: ['copilot-swe-agent'] |
| 70 | + number: context.payload.pull_request.number |
| 71 | + }); |
| 72 | + |
| 73 | + const prId = prResult.repository.pullRequest.id; |
| 74 | + core.info(`PR global ID: ${prId}`); |
| 75 | + |
| 76 | + // Request review from Copilot using GraphQL mutation |
| 77 | + const requestReviewMutation = ` |
| 78 | + mutation($pullRequestId: ID!, $userIds: [ID!]!) { |
| 79 | + requestReviews(input: {pullRequestId: $pullRequestId, userIds: $userIds}) { |
| 80 | + pullRequest { |
| 81 | + id |
| 82 | + number |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + `; |
| 87 | + |
| 88 | + await github.graphql(requestReviewMutation, { |
| 89 | + pullRequestId: prId, |
| 90 | + userIds: [copilotBot.id] |
27 | 91 | }); |
| 92 | + |
| 93 | + core.info('Successfully requested review from Copilot'); |
0 commit comments