You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We've explored how we can use GitHub Copilot to explore our project and to provide context to ensure the suggestions we receive are to the quality we expect. Now let's turn our attention to putting all this prep work into action by generating new code! We'll use GitHub Copilot to aid us in adding functionality to our website and generate the necessary unit tests.
4
7
5
8
## Scenario
@@ -43,7 +46,7 @@ Let's build our new route in our Flask backend with the help of code completion.
43
46
44
47
4. Create the route which will call the database to find all breeds, and returns a JSON array with their names and IDs. If you begin typing `@app.route`or add a comment with the requirements like `# Route to get all breeds`, you should notice italicized text generated by GitHub Copilot.
45
48
5. Select <kbd>Tab</kbd> to accept the code suggestion.
46
-
6. Navigate to [http://localhost:5100/api/breeds](http://localhost:5100/api/breeds) to validate the route.
49
+
6. Navigate to [http://localhost:5100/api/breeds][localhost-breeds] to validate the route.
47
50
48
51
> [!NOTE]
49
52
> As with the prior exercise, we don't provide specific prompts to use with Copilot, as part of the learning experience is to discover how to interact with Copilot. If you are unfamiliar with Flask or how to add routes, you can look at the routes defined above for inspiration, or ask Copilot chat for guidance!
@@ -59,8 +62,8 @@ With the route created, we want to now add the tests to ensure the code is corre
59
62
5. Type **/tests**and select <kbd>tab</kbd> to activate the command, then press <kbd>enter</kbd> to run the command. GitHub Copilot will generate the tests!
60
63
6. Select the **Apply edits** button just above the generated code suggestion to apply the changes to **test_app.py**.
61
64
7. Review and validate the code, making any necessary changes. Select **Keep** once you're satisfied.
62
-
> [!IMPORTANT]
63
-
> GitHub Copilot, like any generative AI solution, can make mistakes. Always review the generated code, making any necessary changes to ensure it's accurate and performs as expected.
65
+
> [!IMPORTANT]
66
+
> GitHub Copilot, like any generative AI solution, can make mistakes. Always review the generated code, making any necessary changes to ensure it's accurate and performs as expected.
64
67
8. Open a terminal window in your codespace orVS Code by selecting <kbd>Ctl</kbd>+<kbd>Shift</kbd>+<kbd>`</kbd>
65
68
9. Ensure the virtual server is activated by running the terminal command `source ./venv/bin/activate`
66
69
10. Navigate to the **server** folder by running the terminal command `cd server`
@@ -84,19 +87,28 @@ Adding the filters to the page will require updating a minimum of three files -
84
87
- The page should automatically refresh whenever a change is made
85
88
- Tests should be updated forany changes to the endpoint.
86
89
6. Review the code suggestions to ensure they behave the way you expect them to, making any necessary changes. Once you're satisfied, you can select **Keep** on the files individually or in Copilot Chat to accept all changes.
87
-
7. Open the page at [http://localhost:4321](http://localhost:4321) to see the updates!
90
+
7. Open the page at [http://localhost:4321][localhost] to see the updates!
88
91
8. Run the Python tests by using `python -m unittest`in the terminal as you did previously.
89
92
9. If any changes are needed, explain the required updates to GitHub Copilot and allow it to generate the new code.
90
93
91
94
> [!IMPORTANT]
92
95
> Working iteratively a normal aspect of coding with an AI pair programmer. You can always provide more context to ensure Copilot understands, make additional requests, or rephrase your original prompts.
93
96
94
97
## Summary and next steps
95
-
96
-
Congratulations! You've worked with GitHub Copilot to add new features to the website - the ability to filter the list of dogs. Let's close out by [creating a pull request with our new functionality](./7-github-flow.md)!
98
+
Congratulations! You've worked with GitHub Copilot to add new features to the website - the ability to filter the list of dogs. Let's close out by [creating a pull request with our new functionality][walkthrough-next]!
97
99
98
100
## Resources
99
-
100
-
- [Asking GitHub Copilot questions in your IDE](https://docs.github.com/en/copilot/using-github-copilot/copilot-chat/asking-github-copilot-questions-in-your-ide)
0 commit comments