|
| 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 | +``` |
0 commit comments