Skip to content

Commit 46d899e

Browse files
authored
Merge pull request #37763 from github/repo-sync
Repo sync
2 parents 65ee537 + 1448c36 commit 46d899e

File tree

4 files changed

+83
-17
lines changed

4 files changed

+83
-17
lines changed

content/get-started/learning-to-code/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ children:
77
- /getting-started-with-git
88
- /finding-and-understanding-example-code
99
- /reusing-other-peoples-code-in-your-projects
10+
- /setting-up-copilot-for-learning-to-code
1011
- /learning-to-debug-with-github-copilot
1112
- /storing-your-secrets-safely
1213
shortTitle: Learn to code
1314
---
15+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
title: Setting up Copilot for learning to code
3+
intro: 'Configure {% data variables.product.prodname_copilot_short %} to help you learn coding concepts and actively build your programming skills.'
4+
versions:
5+
fpt: '*'
6+
topics:
7+
- Copilot
8+
shortTitle: Set up Copilot for learning
9+
---
10+
11+
## Can {% data variables.product.prodname_copilot_short %} help me learn to code?
12+
13+
Yes! {% data variables.product.prodname_copilot_short %} can adapt to meet your changing needs throughout your coding journey. When you're an experienced developer, you'll use {% data variables.product.prodname_copilot_short %} as a coding assistant. While you're learning to code, it's more beneficial as a **supportive companion**.
14+
15+
In this guide, you’ll learn how to set up {% data variables.product.prodname_copilot_short %} to act as a **tutor** that will help you build a deep understanding of programming concepts, rather than relying on it to write your code for you. To optimize your learning, follow these steps for each repository you work on!
16+
17+
## Prerequisites
18+
19+
This guide assumes that you'll use {% data variables.product.prodname_copilot_short %} in {% data variables.product.prodname_vscode_shortname %}. To get set up, see [Set up Copilot in {% data variables.product.prodname_vscode_shortname %}](https://code.visualstudio.com/docs/copilot/setup-simplified) in the {% data variables.product.prodname_vscode %} documentation.
20+
21+
## Step 1: Disable code completions
22+
23+
First, let's disable code completions. This will give you the opportunity to deepen your understanding of programming concepts by writing more code yourself.
24+
25+
1. In {% data variables.product.prodname_vscode_shortname %}, open your project.
26+
1. Create a folder in the root directory called `.vscode`.
27+
1. Inside `.vscode`, create a file called `settings.json`.
28+
1. Add the following text to the file:
29+
30+
```json copy
31+
{
32+
"github.copilot.enable": {
33+
"*": false
34+
}
35+
}
36+
```
37+
38+
1. Save the file. {% data variables.product.prodname_copilot_short %} code completions are now disabled for this project in {% data variables.product.prodname_vscode_shortname %}.
39+
40+
## Step 2: Add learning instructions
41+
42+
Now, let's provide {% data variables.product.prodname_copilot_chat_short %} with instructions to act like a tutor that supports your learning.
43+
44+
1. In the root folder of your project, create a file called `copilot-instructions.md`.
45+
1. Add the following text, or customize it for your personal learning goals:
46+
47+
```markdown copy
48+
I am learning to code. You are to act as a tutor; assume I am a beginning coder. Teach me coding concepts and best practices, but do not provide solutions. Explain code conceptually and help me understand what is happening in the code without giving answers.
49+
50+
Do not provide code snippets, even if I ask you for implementation advice in my prompts. Teach me all the basic coding concepts in your answers. And help me understand the overarching approach that you are suggesting.
51+
52+
Whenever possible, share links to relevant external documentation and sources of truth.
53+
54+
At the end of every response, add "Always check the correctness of AI-generated responses."
55+
```
56+
57+
1. Save the file. {% data variables.product.prodname_copilot_short %} will use these instructions when you ask questions in {% data variables.product.prodname_copilot_chat_short %}.
58+
59+
## Step 3: Use {% data variables.product.prodname_copilot_chat_short %} to learn
60+
61+
You're ready to start building real coding skills with {% data variables.product.prodname_copilot_short %}'s help!
62+
63+
Throughout your work on the project, engage in a long-running conversation with **{% data variables.product.prodname_copilot_chat_short %}**. Treat it as your **personal tutor**, asking questions as they arise and using it to navigate challenges or clarify concepts.
64+
65+
> [!TIP] You can open {% data variables.product.prodname_copilot_chat_short %} with a keyboard shortcut: <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>I</kbd> (Windows/Linux) or <kbd>Command</kbd>+<kbd>Shift</kbd>+<kbd>I</kbd> (Mac).
66+
67+
{% data variables.product.prodname_copilot_chat_short %} is especially helpful for debugging your code. For step-by-step guidance, see [AUTOTITLE](/get-started/learning-to-code/learning-to-debug-with-github-copilot).

src/events/middleware.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,19 @@ router.post(
4747
const validEvents: any[] = []
4848
const validationErrors: any[] = []
4949

50+
// We use a LRU cache & a hash of the request IP + error message
51+
// to prevent sending multiple validation errors per user that can spam requests to Hydro
52+
const getValidationErrorHash = (validateErrors: ErrorObject[]) =>
53+
`${req.ip}:${(validateErrors || [])
54+
.map(
55+
(error: ErrorObject) => error.message + error.instancePath + JSON.stringify(error.params),
56+
)
57+
.join(':')}`
58+
5059
for (const eventBody of eventsToProcess) {
5160
try {
61+
// Skip event if it doesn't have a type or if the type is not in the allowed types
5262
if (!eventBody.type || !allowedTypes.has(eventBody.type)) {
53-
validationErrors.push({ event: eventBody, error: 'Invalid type' })
5463
continue
5564
}
5665
const type: EventType = eventBody.type
@@ -71,18 +80,7 @@ router.post(
7180
}
7281
const validate = validators[type]
7382
if (!validate(body)) {
74-
validationErrors.push({
75-
event: body,
76-
error: validate.errors || [],
77-
})
78-
// This protects so we don't bother sending the same validation
79-
// error, per user, more than once (per time interval).
80-
// This helps if we're bombarded with junk bot traffic. So it
81-
// protects our Hydro instance from being overloaded with things
82-
// that aren't helping anybody.
83-
const hash = `${req.ip}:${(validate.errors || [])
84-
.map((error: ErrorObject) => error.message + error.instancePath)
85-
.join(':')}`
83+
const hash = getValidationErrorHash(validate.errors || [])
8684
if (!sentValidationErrors.has(hash)) {
8785
sentValidationErrors.set(hash, true)
8886
formatErrors(validate.errors || [], body).map((error) => {

src/events/tests/middleware.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ describe('POST /events', () => {
66
vi.setConfig({ testTimeout: 60 * 1000 })
77

88
async function checkEvent(data: any) {
9-
// if data is not an array, make it one
109
if (!Array.isArray(data)) {
1110
data = [data]
1211
}
@@ -89,9 +88,9 @@ describe('POST /events', () => {
8988
})
9089

9190
test('should require a type', async () => {
92-
const { statusCode, body } = await checkEvent({ ...pageExample, type: undefined })
93-
expect(statusCode).toBe(400)
94-
expect(body).toContain('"error":"Invalid type"}')
91+
const { statusCode } = await checkEvent({ ...pageExample, type: undefined })
92+
// should skip events with no type
93+
expect(statusCode).toBe(200)
9594
})
9695

9796
test('should require an event_id in uuid', async () => {

0 commit comments

Comments
 (0)