Skip to content

Commit 58916be

Browse files
committed
Fix copilot review workflow
1 parent 38c28b9 commit 58916be

File tree

1 file changed

+69
-3
lines changed

1 file changed

+69
-3
lines changed

.github/workflows/assign-copilot-reviewer.yml

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
permissions:
1010
contents: read
11+
pull-requests: write
1112

1213
jobs:
1314
assign-copilot:
@@ -19,9 +20,74 @@ jobs:
1920
with:
2021
github-token: ${{ secrets.COPILOT_ASSIGNING_PAT }}
2122
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, {
2368
owner: context.repo.owner,
2469
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]
2791
});
92+
93+
core.info('Successfully requested review from Copilot');

0 commit comments

Comments
 (0)