@@ -4,13 +4,14 @@ const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
44const GITHUB_REPO_OWNER = process . env . GITHUB_REPO_OWNER ;
55const 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' ;
7+ const GRAPHQL_FEATURES_HEADER = 'issues_copilot_assignment_api_support,coding_agent_model_selection' ;
108
119/**
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.
10+ * Creates a GitHub issue and assigns it to the Copilot Coding Agent.
11+ * Follows the official GitHub API docs:
12+ * 1. Query suggestedActors to find copilot-swe-agent and get its node ID
13+ * 2. Get the repository node ID
14+ * 3. Create issue with assigneeIds + agentAssignment, including required GraphQL-Features header
1415 * Returns the issue URL on success, null on failure.
1516 */
1617export async function createIssueWithCopilot ( description : string ) : Promise < string | null > {
@@ -25,10 +26,20 @@ export async function createIssueWithCopilot(description: string): Promise<strin
2526 const octokit = new Octokit ( { auth : GITHUB_TOKEN } ) ;
2627
2728 try {
28- // Fetch repo node ID
29+ // Step 1: Fetch repo ID and find copilot-swe-agent in suggestedActors
2930 const repoInfo : any = await octokit . graphql ( `
3031 query($owner: String!, $name: String!) {
31- repository(owner: $owner, name: $name) { id }
32+ repository(owner: $owner, name: $name) {
33+ id
34+ suggestedActors(capabilities: [CAN_BE_ASSIGNED], first: 100) {
35+ nodes {
36+ login
37+ __typename
38+ ... on Bot { id }
39+ ... on User { id }
40+ }
41+ }
42+ }
3243 }
3344 ` , {
3445 owner : GITHUB_REPO_OWNER ,
@@ -37,15 +48,39 @@ export async function createIssueWithCopilot(description: string): Promise<strin
3748
3849 const repoId = repoInfo ?. repository ?. id ;
3950 if ( ! repoId ) {
51+ console . error ( 'Could not fetch repository ID' ) ;
52+ return null ;
53+ }
54+
55+ const copilotBot = repoInfo . repository . suggestedActors . nodes . find (
56+ ( node : any ) => node . login === 'copilot-swe-agent'
57+ ) ;
58+
59+ if ( ! copilotBot ) {
60+ console . error ( 'copilot-swe-agent not found in suggestedActors. Is Copilot coding agent enabled for this repo?' ) ;
4061 return null ;
4162 }
4263
64+ console . log ( `Found Copilot bot: login=${ copilotBot . login } , id=${ copilotBot . id } , type=${ copilotBot . __typename } ` ) ;
65+
4366 const title = description . split ( '\n' ) [ 0 ] . slice ( 0 , 100 ) ;
4467
45- // Create issue with Copilot bot assigned via known node ID
68+ // Step 2: Create issue with agentAssignment and required GraphQL-Features header
4669 const response : any = await octokit . graphql ( `
4770 mutation($repoId: ID!, $title: String!, $body: String!, $assigneeIds: [ID!]) {
48- createIssue(input: { repositoryId: $repoId, title: $title, body: $body, assigneeIds: $assigneeIds }) {
71+ createIssue(input: {
72+ repositoryId: $repoId,
73+ title: $title,
74+ body: $body,
75+ assigneeIds: $assigneeIds,
76+ agentAssignment: {
77+ targetRepositoryId: $repoId,
78+ baseRef: "main",
79+ customInstructions: "",
80+ customAgent: "",
81+ model: ""
82+ }
83+ }) {
4984 issue {
5085 number
5186 title
@@ -58,7 +93,10 @@ export async function createIssueWithCopilot(description: string): Promise<strin
5893 repoId,
5994 title,
6095 body : description ,
61- assigneeIds : [ COPILOT_BOT_NODE_ID ] ,
96+ assigneeIds : [ copilotBot . id ] ,
97+ headers : {
98+ 'GraphQL-Features' : GRAPHQL_FEATURES_HEADER ,
99+ } ,
62100 } ) ;
63101
64102 const issue = response ?. createIssue ?. issue ;
0 commit comments