Skip to content

Test

Test #1

name: Assign Copilot as reviewer
on:
pull_request_target:
types:
- opened
- ready_for_review
permissions:
contents: read
pull-requests: write
jobs:
assign-copilot:
runs-on: ubuntu-latest
if: ${{ !github.event.pull_request.draft }}
steps:
- name: Assign Copilot as reviewer
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
with:
github-token: ${{ secrets.COPILOT_ASSIGNING_PAT }}
script: |
// First, get Copilot's Bot ID from the repository
const suggestedActorsQuery = `
query($owner: String!, $repo: String!) {
repository(owner: $owner, name: $repo) {
suggestedActors(capabilities: [CAN_BE_ASSIGNED], first: 100) {
nodes {
login
__typename
... on Bot {
id
}
}
}
}
}
`;
const actorsResult = await github.graphql(suggestedActorsQuery, {
owner: context.repo.owner,
repo: context.repo.repo
});
const copilotBot = actorsResult.repository.suggestedActors.nodes.find(
node => node.login === 'copilot-swe-agent'
);
if (!copilotBot) {
core.setFailed('Copilot coding agent is not enabled for this repository');
return;
}
core.info(`Found Copilot bot with ID: ${copilotBot.id}`);
// Get the PR's global ID
const prQuery = `
query($owner: String!, $repo: String!, $number: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $number) {
id
}
}
}
`;
const prResult = await github.graphql(prQuery, {
owner: context.repo.owner,
repo: context.repo.repo,
number: context.payload.pull_request.number
});
const prId = prResult.repository.pullRequest.id;
core.info(`PR global ID: ${prId}`);
// Request review from Copilot using GraphQL mutation
const requestReviewMutation = `
mutation($pullRequestId: ID!, $userIds: [ID!]!) {
requestReviews(input: {pullRequestId: $pullRequestId, userIds: $userIds}) {
pullRequest {
id
number
}
}
}
`;
await github.graphql(requestReviewMutation, {
pullRequestId: prId,
userIds: [copilotBot.id]
});
core.info('Successfully requested review from Copilot');