Skip to content

Commit 81e2865

Browse files
Initial commit
0 parents  commit 81e2865

24 files changed

+2147
-0
lines changed

.devcontainer/devcontainer.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "Python 3",
3+
"image": "mcr.microsoft.com/vscode/devcontainers/python:3.13",
4+
"forwardPorts": [8000],
5+
"postCreateCommand": "pip install -r requirements.txt",
6+
"customizations": {
7+
"vscode": {
8+
"extensions": [
9+
"GitHub.copilot",
10+
"ms-python.python",
11+
"ms-python.debugpy"
12+
]
13+
}
14+
}
15+
}

.github/steps/1-preparing.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
## Step 1: Hello Copilot
2+
3+
Welcome to your **"Getting Started with GitHub Copilot"** exercise! :robot:
4+
5+
In this exercise, you will be using different GitHub Copilot features to work on a website that allows students of Mergington High School to sign up for extracurricular activities. 🎻 ⚽️ ♟️
6+
7+
<img width="600" alt="screenshot of Mergington High School WebApp" src="https://github.com/user-attachments/assets/472398fd-1aa1-4084-b443-4e242deb30d9" />
8+
9+
### What is GitHub Copilot?
10+
11+
<img width="150" align="right" alt="copilot logo" src="https://github.com/user-attachments/assets/4d22496d-850b-4785-aafe-11cba03cd5f2" />
12+
13+
GitHub Copilot is an AI coding assistant that helps you write code faster and with less effort, allowing you to focus more energy on problem solving and collaboration.
14+
15+
GitHub Copilot has been proven to increase developer productivity and accelerate the pace of software development. For more information, see [Research: quantifying GitHub Copilot’s impact on developer productivity and happiness in the GitHub blog.](https://github.blog/news-insights/research/research-quantifying-github-copilots-impact-on-developer-productivity-and-happiness/)
16+
17+
Your most common interactions will likely be:
18+
19+
- **Inline suggestions**: As you type, Copilot uses the nearby context to suggest code directly in your editor. This will be a familiar interaction if you have used code completion tools like [Intellisense](https://code.visualstudio.com/docs/editor/intellisense), except that the completions may be entire functions.
20+
- **Copilot Chat**: A dedicated chat panel that lets you ask coding related questions. This will feel familiar if you have used online AI assistant chats. The big difference however, is that your project files will provide automatic context to provide tailored responses.
21+
- **Copilot Edits**: Similar to Copilot Chat, but less conversational and more big picture or goal oriented.
22+
23+
> [!TIP]
24+
> You can learn more about current and upcoming features in the [GitHub Copilot Features](https://docs.github.com/en/copilot/about-github-copilot/github-copilot-features) documentation. You can also select different [models](https://docs.github.com/en/github-models) and make your own [extensions](https://github.com/features/copilot/extensions), but that's for a different lesson!
25+
26+
### How can I use GitHub Copilot?
27+
28+
As you work, you'll find GitHub Copilot can help out in several places across the website and in your favorite coding environments such as VS Code, Jet Brains, and Xcode! For today's coding though, we will practice with VS Code in a preconfigured development environment known as [Codespace](https://github.com/features/codespaces).
29+
30+
### :keyboard: Activity: Get a project intro from Copilot Chat
31+
32+
Let's start up our development environment, use copilot to learn a bit about the project, and then give it a test run.
33+
34+
1. Right-click the below button to open the **Create Codespace** page in a new tab. Use the default configuration.
35+
36+
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/{{full_repo_name}}?quickstart=1)
37+
38+
1. Confirm the **Repository** field is your copy of the exercise, not the original, then click the green **Create Codespace** button.
39+
40+
- ✅ Your copy: `/{{{full_repo_name}}}`
41+
- ❌ Original: `/skills/getting-started-with-github-copilot`
42+
43+
1. Wait a moment for Visual Studio Code to load in your browser.
44+
45+
1. In the left sidebar, click the extensions tab and verify that the `GitHub Copilot` and `Python` extensions are installed and enabled.
46+
47+
<img width="350" alt="copilot extension for VS Code" src="https://github.com/user-attachments/assets/ef1ef984-17fc-4b20-a9a6-65a866def468" />
48+
49+
<img width="350" alt="python extension for VS Code" src="https://github.com/user-attachments/assets/3040c0f5-1658-47e2-a439-20504a384f77" />
50+
51+
1. At the top of VS Code, locate and click the **Copilot icon** to open a Copilot Chat panel.
52+
53+
<img width="150" alt="image" src="https://github.com/user-attachments/assets/5e64db46-95cb-415d-badc-b6b8677f10c1" />
54+
55+
1. If this is your first, time using GitHub Copilot, you will have to accept the usage terms to continue.
56+
57+
1. Enter the below prompt to ask Copilot to introduce you to the project.
58+
59+
> <img width="13px" src="https://github.com/user-attachments/assets/98fd5d2e-ea29-4a4a-9212-c7050e177a69" /> **Prompt**
60+
>
61+
> ```prompt
62+
> @workspace Please briefly explain the structure of this project.
63+
> What should I do to run it?
64+
> ```
65+
66+
> **Note**: It is not necesesary to follow Copilot's recommended instructions. We have already prepared the environment for you.
67+
68+
1. Now that we know a bit more about the project, let's actually try running it! In the left sidebar, select the `Run and Debug` tab and then press the **Start Debugging** icon.
69+
70+
<img width="300" alt="image" src="https://github.com/user-attachments/assets/50b27f2a-5eab-4827-9343-ab5bce62357e" />
71+
72+
1. We want to see our webpage running in a browser, so let's find the url and port. If it isn't visible, expand the lower panel and select the **Ports** tab.
73+
74+
1. In the list, find port `8000` and the related link. Hover over the link and select the **Open in browser** icon.
75+
76+
![image](https://github.com/user-attachments/assets/92d5642e-ce99-4a66-850c-2d311a673596)
77+
78+
### :keyboard: Activity: Use Copilot to help remember a terminal command 🙋
79+
80+
Great work! Now that we are familiar with the app and we know it works, let's ask copilot for help starting a branch so we can do some customizing.
81+
82+
1. If not already there, return to VS Code.
83+
84+
1. In the bottom panel, select the **Terminal** tab. On the right side, click the plus `+` sign to create a new terminal window.
85+
86+
> **Note:** This will avoid stopping the existing debug session that is hosting our web application service.
87+
88+
1. Within the new terminal window use the keyboard shortcut `Ctrl + I` (windows) or `Cmd + I` (mac) to bring up **Copilot's Terminal Inline Chat**.
89+
90+
1. Let's ask Copilot to help us remember a command we have forgotten: creating a branch and publishing it
91+
92+
> <img width="13px" src="https://github.com/user-attachments/assets/98fd5d2e-ea29-4a4a-9212-c7050e177a69" /> **Prompt**
93+
>
94+
> ```prompt
95+
> Hey copilot, how can I create and publish a new Git branch?
96+
> ```
97+
98+
> **Tip:** This is a simple example, but Copilot is great at providing more tailored commands that might involve loops, pattern matching, file modification, and more! Don't be afraid to ask Copilot for a suggestion. Just remember it is a suggestion and you should always verify it first to be safe.
99+
100+
1. Copilot probably gave us a command like the following. Rather than manually modify it, let's respond back to tell Copilot to use a particular name.
101+
102+
```bash
103+
git checkout -b {new_branch_name}
104+
git push -u origin {new_branch_name}
105+
```
106+
107+
> <img width="13px" src="https://github.com/user-attachments/assets/98fd5d2e-ea29-4a4a-9212-c7050e177a69" /> **Prompt**
108+
>
109+
> ```prompt
110+
> Awesome! Thanks, Copilot! Let's use the
111+
> branch name "accelerate-with-copilot".
112+
> ```
113+
114+
> **Tip:** If Copilot doesn't give you quite what you want, you can always continue explaining what you need. Copilot will remember the conversation history for follow-up responses.
115+
116+
1. Now that we are happy with the command, press the `Run` button to let Copilot run it for us. No need to copy and paste!
117+
118+
1. After a moment, look in the VS Code lower status bar, on the left, to see the active branch. It should now say `accelerate-with-copilot`. If so, you are all done with this step!
119+
120+
1. Now that your branch is pushed to GitHub, Mona should already be busy checking your work. Give her a moment and keep watch in the comments. You will see her respond with progress info and the next lesson.
121+
122+
<details>
123+
<summary>Having trouble? 🤷</summary><br/>
124+
125+
If you don't get feedback, here are some things to check:
126+
127+
- Make sure your created the branch with the exact name `accelerate-with-copilot`. No prefixes or suffixes.
128+
- Make sure the branch was indeed published to your repository.
129+
130+
</details>

.github/steps/2-first-introduction.md

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
## Step 2: Getting work done with Copilot
2+
3+
In the previous step, GitHub Copilot was able to help us onboard to the project. That alone is a huge time saver, but now let's get some work done!
4+
5+
We recently learned there is a bug where students are registering for the same activities twice. That simply isn't acceptable, so let's get it fixed!
6+
7+
Unfortunately, we were given little information to solve this problem. So, let's enlist Copilot to help find the problem area and get a potential solution made.
8+
9+
But before we do that, let's learn a bit more about Copilot! 🧑‍🚀
10+
11+
### How does Copilot work?
12+
13+
In short, you can think of Copilot like a very focused coworker. To be effective with them, you need to provide them background (context) and clear direction (prompts). Additionally, different people are better at different things because of their unique experiences (models).
14+
15+
- **How do we provide context?:** In our coding environment, Copilot will automatically consider nearby code and open tabs. If you are using chat, you can also explicitly refer to files.
16+
17+
- **What model should we pick?:** For our exercise, it shouldn't matter too much. Experimenting with different models is part of the fun! That's another lesson! 🤖
18+
19+
- **How do I make prompts?:** Being explicit and clear helps Copilot do the best job. But unlike some traditional systems, you can always clarify your direction with followup prompts.
20+
21+
### :keyboard: Activity: Use Copilot to fix our registration bug :bug:
22+
23+
1. Let's ask Copilot to suggest where our bug might be coming from. Open the **Copilot Chat** panel and ask the following.
24+
25+
> <img width="13px" src="https://github.com/user-attachments/assets/98fd5d2e-ea29-4a4a-9212-c7050e177a69" /> **Prompt**
26+
>
27+
> ```prompt
28+
> @workspace Students are able to register twice for an activity.
29+
> Where could this bug be coming from?
30+
> ```
31+
32+
1. Now that we know the issue is in the `src/appy.py` file and the `signup_for_activity` method, let's follow Copilot's recommendation and go fix it (semi-manually). We'll start with a comment and let Copilot finish the correction.
33+
34+
1. In VS Code, select the file **Explorer tab** to show the project files and open the `src/app.py` file.
35+
36+
1. Scroll near the bottom of the file and find the `signup_for_activity` method.
37+
38+
1. Find the comment line that describes adding a student. Above this is where it seems logical to do our registration check.
39+
40+
1. Enter the below comment and press enter to go to the next line. After a moment, temporary shadow text will appear with a suggestion from Copilot! Nice! :tada:
41+
42+
```python
43+
# Validate student is not already signed up
44+
```
45+
46+
1. Press `Tab` to accept Copilot's suggestion and convert the shadow text to code.
47+
48+
> **Tip:** If you would like to see other suggestions, instead of pressing `Tab`, hover over the shadow text suggestion and a toolbar will appear. Use the arrows to select other suggestions or the three dots `...` and `Open Completions Panel` option to show all suggestions in a dedicated panel.
49+
50+
<details>
51+
<summary>Example Results</summary><br/>
52+
53+
Copilot is growing every day and may not always produce the same results. If you are unhappy with the suggestions, here is an example of a valid suggestion result we produced during the making of this exercise. You can use it to continue forward.
54+
55+
```python
56+
@app.post("/activities/{activity_name}/signup")
57+
def signup_for_activity(activity_name: str, email: str):
58+
"""Sign up a student for an activity"""
59+
# Validate activity exists
60+
if activity_name not in activities:
61+
raise HTTPException(status_code=404, detail="Activity not found")
62+
63+
# Get the activity
64+
activity = activities[activity_name]
65+
66+
# Validate student is not already signed up
67+
if email in activity["participants"]:
68+
raise HTTPException(status_code=400, detail="Student is already signed up")
69+
70+
# Add student
71+
activity["participants"].append(email)
72+
return {"message": f"Signed up {email} for {activity_name}"}
73+
```
74+
75+
</details>
76+
77+
### :keyboard: Activity: Let Copilot generate sample data 📋
78+
79+
In new project developments, it's often helpful to have some realistic looking fake data for testing. Copilot is excellent at this task, so let's add some more sample activities and introduce another way to interact with Copilot using **Inline Chat**
80+
81+
**Inline Chat** and the **Copilot Chat** panel are very similar tools, but with slightly different automatic context. As such, while Copilot Chat is good at explaining about the project, inline chat might feel more natural for asking about a particular line or function.
82+
83+
1. If not already open, open the `src/app.py` file.
84+
85+
1. Near the top (about line 23), find the `activities` variable, where our example extracurricular activies are configured.
86+
87+
1. Click on any of the related lines and bring up Copilot inline chat by using the keyboard command `Ctrl + I` (windows) or `Cmd + I` (mac).
88+
89+
> **Tip:** Another way to bring up Copilot inline chat is: `right click` on any of the selected lines -> `Copilot` -> `Editor Inline Chat`.
90+
91+
1. Enter the following prompt text and press enter or the **Send and Dispatch** button.
92+
93+
> <img width="13px" src="https://github.com/user-attachments/assets/98fd5d2e-ea29-4a4a-9212-c7050e177a69" /> **Prompt**
94+
>
95+
> ```prompt
96+
> Add 2 more sports related activities, 2 more artistic
97+
> activities, and 2 more intellectual activities.
98+
> ```
99+
100+
1. After a moment, Copilot will directly start making changes to the code. The changes will be stylized differently to make any additions and removals easy to identify. Take a moment to inspect and then press the **Accept** button.
101+
102+
<details>
103+
<summary>Example Results</summary><br/>
104+
105+
Copilot is growing every day and may not always produce the same results. If you are unhappy with the suggestions, here is an example result we produced during the making of this exercise. You can use it to continue forward, if having trouble.
106+
107+
```python
108+
# In-memory activity database
109+
activities = {
110+
"Chess Club": {
111+
"description": "Learn strategies and compete in chess tournaments",
112+
"schedule": "Fridays, 3:30 PM - 5:00 PM",
113+
"max_participants": 12,
114+
"participants": ["[email protected]", "[email protected]"]
115+
},
116+
"Programming Class": {
117+
"description": "Learn programming fundamentals and build software projects",
118+
"schedule": "Tuesdays and Thursdays, 3:30 PM - 4:30 PM",
119+
"max_participants": 20,
120+
"participants": ["[email protected]", "[email protected]"]
121+
},
122+
"Gym Class": {
123+
"description": "Physical education and sports activities",
124+
"schedule": "Mondays, Wednesdays, Fridays, 2:00 PM - 3:00 PM",
125+
"max_participants": 30,
126+
"participants": ["[email protected]", "[email protected]"]
127+
},
128+
"Basketball Team": {
129+
"description": "Competitive basketball training and games",
130+
"schedule": "Tuesdays and Thursdays, 4:00 PM - 6:00 PM",
131+
"max_participants": 15,
132+
"participants": []
133+
},
134+
"Swimming Club": {
135+
"description": "Swimming training and water sports",
136+
"schedule": "Mondays and Wednesdays, 3:30 PM - 5:00 PM",
137+
"max_participants": 20,
138+
"participants": []
139+
},
140+
"Art Studio": {
141+
"description": "Express creativity through painting and drawing",
142+
"schedule": "Wednesdays, 3:30 PM - 5:00 PM",
143+
"max_participants": 15,
144+
"participants": []
145+
},
146+
"Drama Club": {
147+
"description": "Theater arts and performance training",
148+
"schedule": "Tuesdays, 4:00 PM - 6:00 PM",
149+
"max_participants": 25,
150+
"participants": []
151+
},
152+
"Debate Team": {
153+
"description": "Learn public speaking and argumentation skills",
154+
"schedule": "Thursdays, 3:30 PM - 5:00 PM",
155+
"max_participants": 16,
156+
"participants": []
157+
},
158+
"Science Club": {
159+
"description": "Hands-on experiments and scientific exploration",
160+
"schedule": "Fridays, 3:30 PM - 5:00 PM",
161+
"max_participants": 20,
162+
"participants": []
163+
}
164+
}
165+
```
166+
167+
</details>
168+
169+
### :keyboard: Activity: Use Copilot to describe our work 💬
170+
171+
Nice work fixing that bug and expanding the example activities! Now let's get our work committed and pushed to GitHub, again with the help of Copilot!
172+
173+
1. In the left sidebar, select the `Source Control` tab.
174+
175+
> **Tip:** Opening a file from the source control area will show the differences to the original rather than simply opening it.
176+
177+
1. Find the `app.py` file and press the `+` sign to collect your changes together in the staging area.
178+
179+
![image](https://github.com/user-attachments/assets/7d3daf4e-4125-4775-88a7-33251cd7293e)
180+
181+
1. Above the list of staged changes, find the **Message** text box, but **don't enter anything** for now.
182+
183+
- Typically, you would write a short description of the changes here, but now we have Copilot to help out!
184+
185+
1. To the right of the **Message** text box, find and click the **Generate Commit Message with Copilot** button (sparkles icon).
186+
187+
1. Press the **Commit** button and **Sync Changes** button to push your changes to GitHub.
188+
189+
1. Wait a moment for Mona to check your work, provide feedback, and share the next lesson.
190+
191+
<details>
192+
<summary>Having trouble? 🤷</summary><br/>
193+
194+
If you don't get feedback, here are some things to check:
195+
196+
- Make sure your pushed the `src/app.py` file changes to the branch `accelerate-with-copilot`.
197+
198+
</details>

0 commit comments

Comments
 (0)