Skip to content

Commit 285a36a

Browse files
committed
Update issue creation script to assign issues to the Copilot Coding Agent
1 parent b88ba39 commit 285a36a

File tree

2 files changed

+16
-40
lines changed

2 files changed

+16
-40
lines changed

.github/scripts/create-issue-assigned-to-copilot.ts

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
44
const GITHUB_REPO_OWNER = process.env.GITHUB_REPO_OWNER;
55
const GITHUB_REPO_NAME = process.env.GITHUB_REPO_NAME;
66

7+
// Known Copilot Coding Agent bot identity
8+
const COPILOT_BOT_LOGIN = 'Copilot';
9+
const COPILOT_BOT_NODE_ID = 'BOT_kgDOC9w8XQ';
10+
711
/**
8-
* Creates a GitHub issue from the provided description and assigns it to @copilot-swe-agent if available.
9-
* Uses GraphQL for efficient repo/actor queries and issue creation with assignment.
12+
* Creates a GitHub issue and assigns it to the Copilot Coding Agent (@Copilot).
13+
* Uses GraphQL to create the issue with the bot's known node ID as assignee.
1014
* Returns the issue URL on success, null on failure.
1115
*/
1216
export async function createIssueWithCopilot(description: string): Promise<string | null> {
@@ -21,23 +25,12 @@ export async function createIssueWithCopilot(description: string): Promise<strin
2125
const octokit = new Octokit({ auth: GITHUB_TOKEN });
2226

2327
try {
24-
// Fetch repo ID and check for @copilot-swe-agent
25-
const repoInfoQuery = `
28+
// Fetch repo node ID
29+
const repoInfo: any = await octokit.graphql(`
2630
query($owner: String!, $name: String!) {
27-
repository(owner: $owner, name: $name) {
28-
id
29-
suggestedActors(capabilities: [CAN_BE_ASSIGNED], first: 100) {
30-
nodes {
31-
login
32-
... on User { id }
33-
... on Bot { id }
34-
}
35-
}
36-
}
31+
repository(owner: $owner, name: $name) { id }
3732
}
38-
`;
39-
40-
const repoInfo: any = await octokit.graphql(repoInfoQuery, {
33+
`, {
4134
owner: GITHUB_REPO_OWNER,
4235
name: GITHUB_REPO_NAME,
4336
});
@@ -47,26 +40,10 @@ export async function createIssueWithCopilot(description: string): Promise<strin
4740
return null;
4841
}
4942

50-
const copilotBot = repoInfo.repository.suggestedActors.nodes.find(
51-
(node: any) => node.login === 'copilot-swe-agent'
52-
);
53-
5443
const title = description.split('\n')[0].slice(0, 100);
5544

56-
if (!copilotBot) {
57-
// Fallback: Create issue without assignment via REST
58-
const issue = await octokit.issues.create({
59-
owner: GITHUB_REPO_OWNER,
60-
repo: GITHUB_REPO_NAME,
61-
title,
62-
body: description,
63-
});
64-
65-
return issue.data.html_url;
66-
}
67-
68-
// Create issue with assignment via GraphQL
69-
const createIssueMutation = `
45+
// Create issue with Copilot bot assigned via known node ID
46+
const response: any = await octokit.graphql(`
7047
mutation($repoId: ID!, $title: String!, $body: String!, $assigneeIds: [ID!]) {
7148
createIssue(input: { repositoryId: $repoId, title: $title, body: $body, assigneeIds: $assigneeIds }) {
7249
issue {
@@ -77,20 +54,19 @@ export async function createIssueWithCopilot(description: string): Promise<strin
7754
}
7855
}
7956
}
80-
`;
81-
82-
const response: any = await octokit.graphql(createIssueMutation, {
57+
`, {
8358
repoId,
8459
title,
8560
body: description,
86-
assigneeIds: [copilotBot.id],
61+
assigneeIds: [COPILOT_BOT_NODE_ID],
8762
});
8863

8964
const issue = response?.createIssue?.issue;
9065
if (!issue) {
9166
return null;
9267
}
9368

69+
console.log(`Assigned to: ${issue.assignees.nodes.map((a: any) => a.login).join(', ')}`);
9470
return issue.url;
9571
} catch (error) {
9672
console.error('Error creating issue:', error);

.github/workflows/copilot-issue.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
owner: context.repo.owner,
2929
repo: context.repo.repo,
3030
title,
31-
assignees: ['copilot-swe-agent']
31+
assignees: ['Copilot']
3232
});
3333
core.notice(`Created issue #${issue.data.number}: ${issue.data.html_url}`);
3434

0 commit comments

Comments
 (0)