Skip to content

Commit 217a8e3

Browse files
Initial commit
0 parents  commit 217a8e3

30 files changed

+3614
-0
lines changed

.devcontainer/devcontainer.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "Python 3",
3+
"image": "mcr.microsoft.com/vscode/devcontainers/python:3.13",
4+
"features": {
5+
"ghcr.io/devcontainers/features/github-cli:1": {}
6+
},
7+
"forwardPorts": [8000],
8+
"postCreateCommand": "bash ./.devcontainer/postCreate.sh",
9+
"postStartCommand": "bash ./.devcontainer/postStart.sh",
10+
"customizations": {
11+
"vscode": {
12+
"extensions": [
13+
"GitHub.copilot",
14+
"ms-python.python",
15+
"ms-python.debugpy" ]
16+
}
17+
}
18+
}

.devcontainer/installMongoDB.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
# Install MongoDB
4+
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/mongodb-server-7.0.gpg
5+
echo "deb [ arch=amd64,arm64 signed-by=/etc/apt/trusted.gpg.d/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
6+
sudo apt-get update
7+
sudo apt-get install -y mongodb-org
8+
9+
# Create necessary directories and set permissions
10+
sudo mkdir -p /data/db
11+
sudo chown -R mongodb:mongodb /data/db

.devcontainer/postCreate.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Prepare python environment
2+
pip install -r requirements.txt
3+
4+
# Prepare MongoDB Development DB
5+
./.devcontainer/installMongoDB.sh
6+
./.devcontainer/startMongoDB.sh

.devcontainer/postStart.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Start MongoDB Development DB
2+
./.devcontainer/startMongoDB.sh

.devcontainer/startMongoDB.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
# Start MongoDB service
4+
sudo mongod --fork --logpath /var/log/mongodb/mongod.log
5+
6+
echo "MongoDB has been started successfully!"
7+
mongod --version
8+
9+
# Run sample MongoDB commands
10+
echo "Current databases:"
11+
mongosh --eval "db.getMongo().getDBNames()"

.github/steps/1-step.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
## Step 1: Ask for a Review in VS Code
2+
3+
Mergington High School has an Extracurricular Activities website. In the last months, you have added lots of features and it has become increasingly well used by your fellow staff and students.
4+
5+
Now, multiple teachers want to help develop new features. This is great, but your energy is limited and if you don't have time to review changes, you fear the application will become messy. To scale your "review" availability, let's implement **GitHub Copilot code review**!
6+
7+
Before we implement automated code reviews with Copilot, it makes sense to try reviews locally in VS Code. This will help us better understand it, build our review criteria, and ensure all teacher-collaborators receive consistent feedback when they start contributing.
8+
9+
### 📖 Theory: GitHub Copilot Local Code Review
10+
11+
GitHub Copilot can review your code directly in VS Code, providing immediate feedback on uncommitted changes. It even adds comments similar to the feedback in a pull request! This local review capability allows developers to catch issues before they even reach version control, improving code quality from the start. And maybe catch those embarrassing typos! 😅
12+
13+
Key features:
14+
15+
- **Local analysis** of uncommitted changes
16+
- **Code quality and style** recommendations
17+
- **Detection** of common security vulnerabilities
18+
- **Performance optimization** suggestions
19+
20+
This immediate feedback helps you identify and fix issues early in your development process, making your code more robust before it even reaches a pull request.
21+
22+
## ⌨️ Activity: Get to know the extracurricular activities site
23+
24+
Before we start developing and reviewing, let's take a moment to understand the current site.
25+
26+
1. Right-click the below button to open the **Create Codespace** page in a new tab. Use the default configuration.
27+
28+
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/{{full_repo_name}}?quickstart=1)
29+
30+
1. Wait some time for the environment to be prepared. It will automatically install all requirements and services.
31+
32+
1. Validate the **GitHub Copilot** and **Python** extensions are installed and enabled.
33+
34+
<img width="300" alt="copilot extension for VS Code" src="https://github.com/user-attachments/assets/ef1ef984-17fc-4b20-a9a6-65a866def468" /><br/>
35+
<img width="300" alt="python extension for VS Code" src="https://github.com/user-attachments/assets/3040c0f5-1658-47e2-a439-20504a384f77" />
36+
37+
1. Try running the application. In the left sidebar, select the **Run and Debug** tab and then press the **Start Debugging** icon.
38+
39+
<img width="300" alt="run and debug" src="https://github.com/user-attachments/assets/50b27f2a-5eab-4827-9343-ab5bce62357e" />
40+
41+
<details>
42+
<summary>🤷 Having trouble?</summary><br/>
43+
44+
If the **Run and Debug** area is empty, try reloading VS Code: Open the command palette (`Ctrl`+`Shift`+`P`) and search for `Developer: Reload Window`.
45+
46+
<img width="300" alt="empty run and debug panel" src="https://github.com/user-attachments/assets/0dbf1407-3a97-401a-a630-f462697082d6" />
47+
48+
</details>
49+
50+
1. Use the **Ports** tab to find the webpage address, open it, and verify it is running.
51+
52+
<img width="350" alt="ports tab" src="https://github.com/user-attachments/assets/8d24d6b5-202d-4109-8174-2f0d1e4d8d44" />
53+
54+
![Screenshot of Mergington High School WebApp](https://github.com/user-attachments/assets/5e1e7c1e-1b0e-4378-a5af-a266763e6544)
55+
56+
### ⌨️ Activity: Ask Copilot for a review
57+
58+
Let's add a simple banner feature for teachers to make announcements and then ask Copilot for feedback.
59+
60+
1. In VS Code, create a new branch with the following name.
61+
62+
```txt
63+
add-announcement-banner
64+
```
65+
66+
1. Open the `src/static/index.html` file. Add the following after the `<body>` tag.
67+
68+
```html
69+
<div class="announcement-banner">
70+
📢 Activity registration is open until the end of the month. Don't lose your spot!
71+
</div>
72+
```
73+
74+
1. Open the `src/static/styles.css` file. Add the following to the end.
75+
76+
```css
77+
.announcement-banner {
78+
background-color: #4caf50;
79+
color: white;
80+
text-align: center;
81+
padding: 15px;
82+
font-weight: bold;
83+
}
84+
```
85+
86+
1. (optional) Refresh the running app to see the change.
87+
88+
<img width="400" alt="screenshot of site with announcement banner" src="https://github.com/user-attachments/assets/39de7fe0-58f2-4eba-a163-d3037b2b3b06"/>
89+
90+
1. In VS Code, open the source control panel and ensure there are uncommitted changes.
91+
92+
1. Hover over the **Changes** section to show various icons. Click the **Code Review** button and wait a moment for Copilot to add comments.
93+
94+
<img width="300" alt="screenshot of site with announcement banner" src="https://github.com/user-attachments/assets/6c52d550-d67b-4af9-99dd-e181695a4933"/>
95+
96+
> 💡 **TIP:** There are 3 levels of review available: `unstaged changes` and `staged changes` and `uncommitted changes`
97+
98+
1. Expand the **Comments** panel to find a list of review feedback from Copilot.
99+
100+
<img width="300" alt="screenshot of problems control panel with comments from Copilot" src="https://github.com/user-attachments/assets/64c5efb6-9071-4511-b2a2-2dc85c9e929b"/>
101+
102+
1. Use the **Apply** or **Discard** buttons to address Copilot's feedback.
103+
104+
<img width="300" alt="screenshot of inline comment with buttons to address feedback" src="https://github.com/user-attachments/assets/aef73097-acaf-4f5b-a52f-52a142bb413f"/>
105+
106+
1. Commit and push the Announcement related changes to the `add-announcement-banner` branch.
107+
108+
1. With your changes pushed, wait a moment for Mona to check your work, provide feedback, and share the next lesson.
109+
110+
<details>
111+
<summary>Having trouble? 🤷</summary><br/>
112+
113+
- Copilot Review in VS Code only considers uncommitted changes. Don't commit before asking for the review.
114+
- If Copilot doesn't provide review feedback, make sure to click the correct review button for the grouping (unstaged, staged, uncommitted).
115+
- If Copilot doesn't see your changes, make sure to save the files first.
116+
117+
</details>

.github/steps/2-step.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
## Step 2: Get a Pull Request Review
2+
3+
Now that you've tested Copilot's local review capabilities and made some changes to improve the activities website, it's time to create a pull request and get Copilot's feedback on your proposed changes before they're merged into the main branch, just like one of the other teachers would. Let's see how Copilot reviews changes in the pull request process.
4+
5+
### 📖 Theory: Pull Request Code Reviews
6+
7+
GitHub Copilot analyzes your code and provides intelligent feedback with actionable suggestions you can apply instantly. Each code review consumes one [Premium Request Unit (PRU)](https://docs.github.com/en/copilot/concepts/billing/copilot-requests) from the requester.
8+
9+
> [!IMPORTANT]
10+
> Use [code review responsibly](https://docs.github.com/en/copilot/responsible-use/code-review) - Copilot is trained to be familiar with many common security concerns, but it is not meant to replace dedicated security tools, guidelines, and standards. Please use of the correct tools for the job.
11+
12+
**Key Capabilities:**
13+
14+
- **Automated Analysis**: Reviews code for quality, security, and performance issues
15+
- **Actionable Suggestions**: Provides specific recommendations with suggested code changes
16+
- **Integration**: Works seamlessly with GitHub's native pull request flow, the same as regular peer feedback
17+
- **Non-blocking**: Provides "Comment" reviews that don't block merging or count toward required approvals
18+
- **Customizable**: Supports custom instructions to align with team standards
19+
- **Secure**: Operates within GitHub's secure infrastructure
20+
21+
For more information, see the [GitHub Copilot code review documentation](https://docs.github.com/en/copilot/how-tos/use-copilot-agents/request-a-code-review).
22+
23+
### ⌨️ Activity: Request a review
24+
25+
1. If needed, open another web browser tab and navigate to this exercise repository.
26+
27+
1. Start a new pull request. Enter the following details and click the **Create pull request** button.
28+
29+
- **compare:** `add-announcement-banner`
30+
- **target:** `main`
31+
- **title:** `Add announcement banner`
32+
33+
1. In the right-side details area, find the **Reviewers** menu. Click on the **settings icon** to show a list of available reviewers and select **Copilot**.
34+
35+
<img width="300" alt="screenshot of reviewers menu" src="https://github.com/user-attachments/assets/0f9f2e86-51b7-4542-82a1-afb6a22ab3ca"/>
36+
37+
1. Wait a moment for Copilot to review the changes and add comments to your pull request. Notice an entry was added to the conversation log.
38+
39+
<img width="300" alt="new log entry - requested review from copilot" src="https://github.com/user-attachments/assets/3e522bda-e68e-4469-93f4-a7ad103cca97"/>
40+
41+
<img width="500" alt="new log entry - copilot's PR summary" src="https://github.com/user-attachments/assets/0a870950-560e-4df8-80d5-2b93f1be99ab"/>
42+
43+
1. With the review requested, wait a moment for Mona to check your work, provide feedback, and share the next lesson.
44+
45+
<details>
46+
<summary>Having trouble? 🤷</summary><br/>
47+
48+
- If Copilot doesn't appear in the reviewers list, ensure your repository has Copilot enabled
49+
- If Copilot doesn't appear in the reviewers list, check your subscription plan. It is not available for free tier.
50+
- Sometimes reviews take a minute or two to complete.
51+
52+
</details>

.github/steps/3-step.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
## Step 3: Customize Your Review
2+
3+
The school's coding standards are crucial for maintaining the activities website. You've noticed that teachers are using different visual styles and coding patterns. With such diverse programming backgrounds and priorities among your teacher-collaborators, let's customize Copilot's review behavior to align with the school's educational programming standards.
4+
5+
### 📖 Theory: Repository Custom Instructions
6+
7+
Repository custom instructions allow you to provide Copilot with context about your project standards and preferences. By creating instruction files, you can ensure Copilot's suggestions consistently follow your team's conventions and focus on your specific requirements. You can even have copilot analyze your project and [generate instructions](https://code.visualstudio.com/docs/copilot/customization/custom-instructions#_generate-an-instructions-file-for-your-workspace) for you!
8+
9+
**Types of Instructions:**
10+
11+
- **Repository-wide instructions**: Applies to all code in the repository. Ex: `.github/copilot-instructions.md`
12+
- **Path-specific instructions**: Applies to specific files to create focused criteria for different parts of your codebase. Ex: `.github/instructions/NAME.instructions.md`.
13+
14+
Instructions are written in natural language with Markdown format and typically include:
15+
16+
- Security requirements and checklists
17+
- Code standards and conventions
18+
- Performance optimization priorities
19+
- Team-specific preferences and style guides
20+
- Language-specific review criteria
21+
22+
Path-specific instruction files include [YAML front matter](https://docs.github.com/en/contributing/writing-for-github-docs/using-yaml-frontmatter) with file [glob patterns](https://code.visualstudio.com/docs/editor/glob-patterns) to target specific files and directories. Examples:
23+
24+
```yaml
25+
---
26+
applyTo: "tests/**/**,docs/*.md"
27+
---
28+
# Testing Guidelines ...
29+
```
30+
31+
```yaml
32+
---
33+
applyTo: "docs/*.md,README.md"
34+
---
35+
# Documentation Guidelines ...
36+
```
37+
38+
> [!TIP]
39+
> Repository [custom instructions](https://docs.github.com/en/copilot/how-tos/custom-instructions/adding-repository-custom-instructions-for-github-copilot) work for both local VS Code code reviews and pull request code reviews, ensuring consistency across your development workflow.
40+
41+
### ⌨️ Activity: Add general instructions
42+
43+
Let's customize Copilot's review considerations by adding custom instructions.
44+
45+
1. In VS Code, ensure you are still on the `add-announcement-banner` branch.
46+
47+
1. Create a file for general repository guidelines.
48+
49+
File location and name:
50+
51+
```txt
52+
.github/copilot-instructions.md
53+
```
54+
55+
Content:
56+
57+
```markdown
58+
## Security
59+
60+
- Validate input sanitization practices.
61+
- Search for risks that might expose user data.
62+
- Prefer loading configuration and content from the database instead of hard coded content. If absolutely necessary, load it from environment variables or a non-committed config file.
63+
64+
## Code Quality
65+
66+
- Use consistent naming conventions.
67+
- Try to reduce code duplication.
68+
- Prefer maintainability and readability over optimization.
69+
- If a method is used a lot, try to optimize it for performance.
70+
- Prefer explicit error handling over silent failures.
71+
```
72+
73+
### ⌨️ Activity: Add focused instructions
74+
75+
Let's create specific Copilot's review considerations for the frontend and backend.
76+
77+
1. Create a file for the frontend-specific guidelines.
78+
79+
> ❗️ **Important**: Make sure to put file-specific instructions in the `.github/instructions/` folder, not the `.github/` folder.
80+
81+
File location and name:
82+
83+
```txt
84+
.github/instructions/frontend.instructions.md
85+
```
86+
87+
Content:
88+
89+
```markdown
90+
---
91+
applyTo: "*.html,*.css,*.js"
92+
---
93+
94+
## Frontend Guidelines
95+
96+
- Use accessibility attributes (alt text, aria labels) and color schemes.
97+
- Use responsive design for compatibility with mobile devices.
98+
- Validate HTML structure and semantic elements
99+
```
100+
101+
1. Create a file for the backend-specific guidelines.
102+
103+
File location and name:
104+
105+
```txt
106+
.github/instructions/backend.instructions.md
107+
```
108+
109+
Content:
110+
111+
```markdown
112+
---
113+
applyTo: "backend/**/*,*.py"
114+
---
115+
116+
## Backend Guidelines
117+
118+
- All API endpoints must be defined in the `routers` folder.
119+
- Load example database content from the `database.py` file.
120+
- Error handling is only logged on the server. Do not propagate to the frontend.
121+
- Ensure all APIs are explained in the documentation.
122+
- Verify changes in the backend are reflected in the frontend (`src/static/**`). If possible breaking changes are found, mention them to the developer.
123+
```
124+
125+
1. Commit and push the instruction files.
126+
127+
> [!TIP]
128+
> VS Code has a built-in commands to help manage instructions. Try opening the command pallette and searching for `instructions`.
129+
130+
### ⌨️ Activity: Request another review
131+
132+
With our new instructions defined, Copilot now has a better idea of what is important for our project. Let's ask for another review.
133+
134+
1. In VS Code, Ensure the instructions are indeed committed and push to the repository.
135+
136+
1. In the web browser, return to the recently created pull request.
137+
138+
1. In the top right, find the **Reviewers** menu and **Re-request review** button next to **Copilot**. Click it and wait a moment for Copilot to add comments on the pull request.
139+
140+
<img width="300" alt="screenshot of re-review button" src="https://github.com/user-attachments/assets/c45aa8de-278d-46e7-bfe2-2dc6b574e11e"/>
141+
142+
> 🪧 **Note:** If you are too quick after pushing new commits, you may have to wait a moment for the button to appear, or refresh the page.
143+
144+
1. Observe that Copilot's feedback now differs from the previous review.
145+
146+
1. With the review requested, wait a moment for Mona to check your work, provide feedback, and share the next lesson.
147+
148+
<details>
149+
<summary>Having trouble? 🤷</summary><br/>
150+
151+
- If you forgot to add a custom instruction (or made a typo), try fixing the mistake and asking Copilot for another review. This will inform Mona to check your work again.
152+
153+
</details>

0 commit comments

Comments
 (0)