Skip to content

Commit 5540f12

Browse files
[CCA] add docs re: how to assign copilot on issue via REST and gql APIs (#58689)
Co-authored-by: Sophie <29382425+sophietheking@users.noreply.github.com>
1 parent 5dafee5 commit 5540f12

File tree

2 files changed

+190
-14
lines changed

2 files changed

+190
-14
lines changed
54.1 KB
Loading

content/copilot/how-tos/use-copilot-agents/coding-agent/create-a-pr.md

Lines changed: 190 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ You can assign an issue to {% data variables.product.prodname_copilot_short %}:
6060

6161
### Assigning an issue to {% data variables.product.prodname_copilot_short %} on {% data variables.product.prodname_dotcom_the_website %}
6262

63+
> [!NOTE]
64+
> This feature is in {% data variables.release-phases.public_preview %} and subject to change.
65+
6366
{% data reusables.repositories.navigate-to-repo %}
6467
{% data reusables.repositories.sidebar-issues %}
6568

@@ -113,9 +116,32 @@ You can also assign issues to {% data variables.product.prodname_copilot_short %
113116

114117
### Assigning an issue to {% data variables.product.prodname_copilot_short %} via the {% data variables.product.github %} API
115118

116-
You can assign issues to {% data variables.product.prodname_copilot_short %} using the GraphQL API.
119+
> [!NOTE]
120+
> This feature is in {% data variables.release-phases.public_preview %} and subject to change.
121+
122+
You can assign issues to {% data variables.product.prodname_copilot_short %} using either the GraphQL API or the REST API. Both APIs support an optional Agent Assignment input to customize the task:
123+
124+
| GraphQL parameter | REST parameter | Description |
125+
| --- | --- | --- |
126+
| `targetRepositoryId` | `target_repo` | The repository where {% data variables.product.prodname_copilot_short %} will work |
127+
| `baseRef` | `base_branch` | The branch that {% data variables.product.prodname_copilot_short %} will branch from |
128+
| `customInstructions` | `custom_instructions` | Additional instructions for {% data variables.product.prodname_copilot_short %} |
129+
| `customAgent` | `custom_agent` | A custom agent to use for the task |
130+
| `model` | `model` | The model for {% data variables.product.prodname_copilot_short %} to use |
131+
132+
#### Using the GraphQL API
117133

118-
#### Creating and assigning a new issue
134+
> [!NOTE]
135+
> You must include the `GraphQL-Features` header with the values `issues_copilot_assignment_api_support` and `coding_agent_model_selection`.
136+
137+
You can use the following GraphQL mutations to assign issues to {% data variables.product.prodname_copilot_short %}:
138+
139+
* [`updateIssue`](/graphql/reference/mutations#updateissue)
140+
* [`createIssue`](/graphql/reference/mutations#createissue)
141+
* [`addAssigneesToAssignable`](/graphql/reference/mutations#addassigneestoassignable)
142+
* [`replaceActorsForAssignable`](/graphql/reference/mutations#replaceactorsforassignable)
143+
144+
##### Creating and assigning a new issue
119145

120146
1. Make sure you're authenticating with the API using a user token, for example a {% data variables.product.pat_generic %} or a {% data variables.product.prodname_github_app %} user-to-server token.
121147

@@ -163,11 +189,23 @@ You can assign issues to {% data variables.product.prodname_copilot_short %} usi
163189
}
164190
```
165191

166-
1. Create the issue with the `createIssue` mutation. Replace `REPOSITORY_ID` with the ID returned from the previous step, and `BOT_ID` with the ID returned from the step before that.
167-
168-
```graphql copy
169-
mutation {
170-
createIssue(input: {repositoryId: "REPOSITORY_ID", title: "Implement comprehensive unit tests", body: "DETAILS", assigneeIds: ["BOT_ID"]}) {
192+
1. Create the issue with the `createIssue` mutation. Replace `REPOSITORY_ID` with the ID returned from the previous step, and `BOT_ID` with the ID returned from the step before that. You can optionally include the `agentAssignment` input to customize the task.
193+
194+
```shell copy
195+
gh api graphql -f query='mutation {
196+
createIssue(input: {
197+
repositoryId: "REPOSITORY_ID",
198+
title: "Implement comprehensive unit tests",
199+
body: "DETAILS",
200+
assigneeIds: ["BOT_ID"],
201+
agentAssignment: {
202+
targetRepositoryId: "REPOSITORY_ID",
203+
baseRef: "main",
204+
customInstructions: "Add comprehensive test coverage",
205+
customAgent: "",
206+
model: ""
207+
}
208+
}) {
171209
issue {
172210
id
173211
title
@@ -178,10 +216,10 @@ You can assign issues to {% data variables.product.prodname_copilot_short %} usi
178216
}
179217
}
180218
}
181-
}
219+
}' -H 'GraphQL-Features: issues_copilot_assignment_api_support,coding_agent_model_selection'
182220
```
183221

184-
#### Assigning an existing issue
222+
##### Assigning an existing issue
185223

186224
1. Make sure you're authenticating with the API using a user token, for example a {% data variables.product.pat_generic %} or a {% data variables.product.prodname_github_app %} user-to-server token.
187225
1. Verify that {% data variables.copilot.copilot_coding_agent %} is enabled in the repository by checking if the repository's `suggestedActors` in the GraphQL API includes {% data variables.product.prodname_copilot_short %}. Replace `octo-org` with the repository owner, and `octo-repo` with the repository name.
@@ -222,11 +260,79 @@ You can assign issues to {% data variables.product.prodname_copilot_short %} usi
222260
}
223261
```
224262

225-
1. Assign the existing issue to {% data variables.product.prodname_copilot_short %} using the `replaceActorsForAssignable` mutation. Replace `ISSUE_ID` with the ID returned from the previous step, and `BOT_ID` with the ID returned from the step before that.
263+
1. Assign the existing issue to {% data variables.product.prodname_copilot_short %} using the `replaceActorsForAssignable` mutation. Replace `ISSUE_ID` with the ID returned from the previous step, `BOT_ID` with the ID returned from the step before that, and `REPOSITORY_ID` with the repository ID. You can optionally include the `agentAssignment` input to customize the task.
264+
265+
```shell copy
266+
gh api graphql -f query='mutation {
267+
replaceActorsForAssignable(input: {
268+
assignableId: "ISSUE_ID",
269+
actorIds: ["BOT_ID"],
270+
agentAssignment: {
271+
targetRepositoryId: "REPOSITORY_ID",
272+
baseRef: "main",
273+
customInstructions: "Fix the reported bug",
274+
customAgent: "",
275+
model: ""
276+
}
277+
}) {
278+
assignable {
279+
... on Issue {
280+
id
281+
title
282+
assignees(first: 10) {
283+
nodes {
284+
login
285+
}
286+
}
287+
}
288+
}
289+
}
290+
}' -H 'GraphQL-Features: issues_copilot_assignment_api_support,coding_agent_model_selection'
291+
```
226292

227-
```graphql copy
228-
mutation {
229-
replaceActorsForAssignable(input: {assignableId: "ISSUE_ID", actorIds: ["BOT_ID"]}) {
293+
1. Alternatively, you can use the `updateIssue` mutation to update an existing issue and assign it to {% data variables.product.prodname_copilot_short %}. Replace `ISSUE_ID` with the issue ID and `BOT_ID` with the bot ID.
294+
295+
```shell copy
296+
gh api graphql -f query='mutation {
297+
updateIssue(input: {
298+
id: "ISSUE_ID",
299+
assigneeIds: ["BOT_ID"],
300+
agentAssignment: {
301+
targetRepositoryId: "REPOSITORY_ID",
302+
baseRef: "main",
303+
customInstructions: "Update feature implementation",
304+
customAgent: "",
305+
model: ""
306+
}
307+
}) {
308+
issue {
309+
id
310+
title
311+
assignees(first: 10) {
312+
nodes {
313+
login
314+
}
315+
}
316+
}
317+
}
318+
}' -H 'GraphQL-Features: issues_copilot_assignment_api_support,coding_agent_model_selection'
319+
```
320+
321+
1. You can also use the `addAssigneesToAssignable` mutation to add {% data variables.product.prodname_copilot_short %} to an existing issue while keeping other assignees. Replace `ISSUE_ID` with the issue ID and `BOT_ID` with the bot ID.
322+
323+
```shell copy
324+
gh api graphql -f query='mutation {
325+
addAssigneesToAssignable(input: {
326+
assignableId: "ISSUE_ID",
327+
assigneeIds: ["BOT_ID"],
328+
agentAssignment: {
329+
targetRepositoryId: "REPOSITORY_ID",
330+
baseRef: "main",
331+
customInstructions: "Collaborate on this task",
332+
customAgent: "",
333+
model: ""
334+
}
335+
}) {
230336
assignable {
231337
... on Issue {
232338
id
@@ -239,9 +345,79 @@ You can assign issues to {% data variables.product.prodname_copilot_short %} usi
239345
}
240346
}
241347
}
242-
}
348+
}' -H 'GraphQL-Features: issues_copilot_assignment_api_support,coding_agent_model_selection'
243349
```
244350

351+
#### Using the REST API
352+
353+
You can use the following REST API endpoints to assign issues to {% data variables.product.prodname_copilot_short %}:
354+
355+
* [Add assignees to an issue](/rest/issues/assignees#add-assignees-to-an-issue)
356+
* [Create an issue](/rest/issues/issues#create-an-issue)
357+
* [Update an issue](/rest/issues/issues#update-an-issue)
358+
359+
##### Adding assignees to an existing issue
360+
361+
```shell copy
362+
gh api \
363+
--method POST \
364+
-H "Accept: application/vnd.github+json" \
365+
-H "X-GitHub-Api-Version: 2022-11-28" \
366+
/repos/OWNER/REPO/issues/ISSUE_NUMBER/assignees \
367+
--input - <<< '{
368+
"assignees": ["copilot-swe-agent[bot]"],
369+
"agent_assignment": {
370+
"target_repo": "OWNER/REPO",
371+
"base_branch": "main",
372+
"custom_instructions": "",
373+
"custom_agent": "",
374+
"model": ""
375+
}
376+
}'
377+
```
378+
379+
##### Creating a new issue
380+
381+
```shell copy
382+
gh api \
383+
--method POST \
384+
-H "Accept: application/vnd.github+json" \
385+
-H "X-GitHub-Api-Version: 2022-11-28" \
386+
/repos/OWNER/REPO/issues \
387+
--input - <<< '{
388+
"title": "Issue title",
389+
"body": "Issue description.",
390+
"assignees": ["copilot-swe-agent[bot]"],
391+
"agent_assignment": {
392+
"target_repo": "OWNER/REPO",
393+
"base_branch": "main",
394+
"custom_instructions": "",
395+
"custom_agent": "",
396+
"model": ""
397+
}
398+
}'
399+
```
400+
401+
##### Updating an existing issue
402+
403+
```shell copy
404+
gh api \
405+
--method PATCH \
406+
-H "Accept: application/vnd.github+json" \
407+
-H "X-GitHub-Api-Version: 2022-11-28" \
408+
/repos/OWNER/REPO/issues/ISSUE_NUMBER \
409+
--input - <<< '{
410+
"assignees": ["copilot-swe-agent[bot]"],
411+
"agent_assignment": {
412+
"target_repo": "OWNER/REPO",
413+
"base_branch": "main",
414+
"custom_instructions": "",
415+
"custom_agent": "",
416+
"model": ""
417+
}
418+
}'
419+
```
420+
245421
## Asking {% data variables.product.prodname_copilot_short %} to create a pull request from the agents tab or panel
246422

247423
You can ask {% data variables.product.prodname_copilot_short %} to open a pull request from either the agents tab or the agents panel. The only difference is the entry point - once you see the "New agent task" form, the steps are the same.

0 commit comments

Comments
 (0)