Skip to content

Commit 1506c45

Browse files
authored
Copilot Creates Issues includes codes snippets in its drafts [Public Preview] (#57733)
1 parent 40a47c4 commit 1506c45

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
lines changed

content/copilot/how-tos/use-copilot-for-common-tasks/use-copilot-to-create-issues.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ You can create issues from {% data variables.copilot.copilot_chat_short %}'s imm
3737
* {% prompt %}In OWNER/REPOSITORY, create a feature request to add fuzzy matching to search.{% endprompt %}
3838
* {% prompt %}Log a bug for a 500 error. This happens consistently when I try to log into the site.{% endprompt %}
3939
* {% prompt %}Create a task to change the application logo background to red and add the label "needs design review".{% endprompt %}
40+
* {% prompt %}In octo-org/octo-repo, create an issue and add relevant code snippets to improve the API response format.{% endprompt %}
4041

4142
> [!NOTE] You can only use {% data variables.product.prodname_copilot_short %} to create issues in repositories where you already have permission to create issues. This feature doesn't change your access or bypass repository permissions.
4243
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: Creating issues
3+
shortTitle: Create issues
4+
intro: '{% data variables.copilot.copilot_chat_short %} can help you quickly create issues without filling out every field manually.'
5+
versions:
6+
feature: copilot
7+
complexity:
8+
- Simple
9+
octicon: copilot
10+
category:
11+
- Document code
12+
topics:
13+
- Copilot
14+
contentType: tutorials
15+
---
16+
17+
Creating issues manually can be time-consuming. {% data variables.copilot.copilot_chat_short %} lets you create issues from natural language, and automatically fills in the title, body, labels, and other metadata based on your prompt.
18+
19+
## Example scenario
20+
21+
You're working on an API service and need to add server-side validation to the `createUser` endpoint. Instead of drafting the issue manually, you use {% data variables.copilot.copilot_chat_short %} to generate a detailed issue description that includes an example implementation of the validation middleware.
22+
23+
The following snippet shows the current implementation of the `createUser` route, before validation is added:
24+
25+
```javascript
26+
// Route
27+
app.post('/users', validateCreateUser, (req, res) => {
28+
const { username, email } = req.body;
29+
// Simulate user creation
30+
res.status(201).json({ message: 'User created', user: { username, email } });
31+
});
32+
```
33+
34+
## Example prompt
35+
36+
`In octo-org/octo-repo, create an issue to add server-side validation for the createUser API endpoint. Include an example of how to validate the request body using an existing middleware pattern. Label it with "backend" and "enhancement".`
37+
38+
## Example response
39+
40+
{% data reusables.copilot.example-prompts.response-is-an-example %}
41+
42+
When you submit the prompt, {% data variables.copilot.copilot_chat_short %} generates a draft issue based on your description and includes a code snippet. You can review and edit the draft before creating the issue.
43+
44+
```markdown
45+
## Problem
46+
The `createUser` API endpoint currently lacks robust server-side validation for incoming requests. To ensure data integrity and security, we should validate the request body before proceeding with user creation.
47+
48+
**Current API endpoint:**
49+
// Route
50+
app.post('/users', validateCreateUser, (req, res) => {
51+
const { username, email } = req.body;
52+
// Simulate user creation
53+
res.status(201).json({ message: 'User created', user: { username, email } });
54+
});
55+
56+
## Proposal
57+
- Add server-side validation for the request body using the existing middleware pattern.
58+
- Ensure required fields (`username`, `email`) are present and valid.
59+
- Return a 400 Bad Request response if validation fails.
60+
61+
**Example (middleware pattern):**
62+
function validateCreateUser(req, res, next) {
63+
const { username, email } = req.body;
64+
if (!username || !email) {
65+
return res.status(400).json({ error: 'Username and email are required.' });
66+
}
67+
// Additional validation logic here
68+
next();
69+
}
70+
71+
app.post('/users', validateCreateUser, (req, res) => {
72+
// ...
73+
});
74+
75+
76+
## Acceptance Criteria
77+
- Server-side validation middleware is added to the `createUser` endpoint.
78+
- Request body is properly validated.
79+
- Appropriate error responses are returned for invalid requests.
80+
```

content/copilot/tutorials/copilot-chat-cookbook/document-code/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ versions:
1010
topics:
1111
- Copilot
1212
children:
13+
- /creating-issues
1314
- /document-legacy-code
1415
- /explain-legacy-code
1516
- /explain-complex-logic

content/copilot/tutorials/plan-a-project.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ After you finish generating the issue tree you may notice that {% data variables
8888
1. Start with the newly generated issue such as "Task: Create placeholder pages for main routes".
8989

9090
Prompt {% data variables.product.prodname_copilot_short %} with:
91-
```Can you improve the description for “Task: Create placeholder pages for main routes”? Please provide a detailed technical summary, list the main routes to be included, outline the steps for implementation, and specify what should be delivered for this task.```
91+
```Can you improve the description for “Task: Create placeholder pages for main routes”? Please provide a detailed technical summary, list the main routes to be included, outline the steps for implementation, and specify what should be delivered for this task. Please add any relevant code snippets.```
9292

9393
1. {% data variables.product.prodname_copilot_short %} will generate a new version of the draft issue "Task: Create placeholder pages for main routes."
9494

9595
At the top-left of the issue, click the versioning drop-down and select **Version 2** to review the new changes.
96-
1. Review and decide whether to keep {% data variables.product.prodname_copilot_short %}’s revised version, edit further, or prompt again for more detail.
96+
1. Review and decide whether to keep {% data variables.product.prodname_copilot_short %}’s revised version, edit further, or prompt again for more detail. {% data variables.product.prodname_copilot_short %} can add code snippets into the draft to improve clarity and provide immediate context for these issues.
9797
1. Repeat this process for other issues in the epic, refining descriptions and breaking down tasks as needed.
9898
1. Once you’re satisfied with the issue descriptions, click **Create all** to create the issues in your repository.
9999

0 commit comments

Comments
 (0)