Skip to content

Commit 57269b4

Browse files
authored
Merge pull request #2 from GitHub-Insight-ANZ-Lab/tasks/dev
add dev container and revise instructions
2 parents 350f31a + 85b11cc commit 57269b4

File tree

2 files changed

+64
-22
lines changed

2 files changed

+64
-22
lines changed

.devcontainer/devcontainer.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"image": "mcr.microsoft.com/devcontainers/universal:2",
3+
"features": {
4+
"ghcr.io/devcontainers/features/java:1": {
5+
"version": "17"
6+
}
7+
},
8+
"hostRequirements": {
9+
"cpus": 2
10+
},
11+
"waitFor": "onCreateCommand",
12+
// "updateContentCommand": "",
13+
"postCreateCommand": "",
14+
"customizations": {
15+
"codespaces": {
16+
"openFiles": []
17+
},
18+
"vscode": {
19+
"extensions": [
20+
"vscjava.vscode-java-debug",
21+
"vscjava.vscode-java-pack",
22+
"ms-azuretools.vscode-docker"
23+
]
24+
}
25+
}
26+
}

README.md

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Try different things and see what GitHub Copilot can do for you, like generating
88

99
> Make sure GitHub Copilot is configure and enabled for the current laguage, just check the status bar on the bottom right corner of VS Code.
1010
11+
> If you are running this exercise in local environment, please make sure JDK 18 and above is installed.
12+
13+
> If you are running this exercise in GitHub Codespaces, the java environment is already setup.
14+
1115
## Instructions
1216

1317
The `copilot-demo` folder contains the Maven project and Maven installer.
@@ -19,17 +23,17 @@ The `copilot-demo` folder contains the Maven project and Maven installer.
1923

2024
To run Copilot inline on Windows you press `Ctrl + i` (Windows) / `⌘ + i` (Mac)
2125

22-
To run the tests open a terminal in the `copilot-demo` folder and run:
26+
To run the app open a terminal in the `copilot-demo` folder and run:
2327

2428
```sh
25-
./mvnw test
29+
./mvnw package
30+
./mvnw spring-boot:run
2631
```
2732

28-
To run the app open a terminal in the `copilot-demo` folder and run:
33+
To run the tests open a terminal in the `copilot-demo` folder and run:
2934

3035
```sh
31-
./mvnw package
32-
./mvnw spring-boot:run
36+
./mvnw test
3337
```
3438

3539
### Unix Note
@@ -41,13 +45,26 @@ Please run the following to give it execute permissions.
4145
chmod +x ./mvnw
4246
```
4347

44-
### Exercise 1: Introduction
48+
### Exercise 1: Write a GET Request
4549

4650
For this exercise we will be adding a new endpoint to handle a simple GET request.
4751

4852
- Move to the `src/main/.../DemoController.java` file
49-
- Start writing the code to handle a simple GET request based on the javadoc comment. Just press enter and wait a couple of seconds, Copilot will generate the code for you.
53+
- Start writing the code to handle a simple GET request based on the javadoc comment.
54+
- Just press enter and wait a couple of seconds, Copilot will generate the code for you.
5055
- Alternatively, you can test the Copilot inline feature by pressing `ctrl/⌘ + i`. Then write in the text box the desired behaviour.
56+
57+
You can now run the application and then test it with curl.
58+
59+
1. Run the spring app: `./mvnw spring-boot:run`
60+
2. Test with curl: `curl -v http://localhost:8080/hello?key=world`
61+
3. If you are using GitHub `Codespaces`, replace localhost:8080 with actual `Codespaces` url.
62+
63+
64+
### Exercise 2: Write a Test Case
65+
66+
There is an existing unit test `src/test/.../CopilotDemoApplicationTests.java`, run below command to test it.
67+
5168
- run `./mvnw test`
5269
- If the test passed you should see something like this:
5370

@@ -66,11 +83,6 @@ For this exercise we will be adding a new endpoint to handle a simple GET reques
6683
[INFO] ------------------------------------------------------------------------
6784
```
6885

69-
You can now run the application and then test it with curl.
70-
71-
1. Run the spring app: `./mvnw spring-boot:run`
72-
2. Test with curl: `curl -v http://localhost:8080/hello?key=world`
73-
7486
Let's now create a new unit test for the case when no key is provided in the request.
7587

7688
- Move to `src/test/.../CopilotDemoApplicationTests.java`
@@ -92,15 +104,11 @@ Let's now create a new unit test for the case when no key is provided in the req
92104
[INFO] ------------------------------------------------------------------------
93105
```
94106

95-
### Exercise 2: Building new functionalities
96-
97-
For this exercise, the code can either but in their own controller, or you can reuse the existing `DemoController.java`
107+
### Exercise 3: Building more functionalities
98108

99-
Add the following endpoints using the help of Copilot.
109+
For this exercise, the code can either but in their own controller, or you can reuse the existing `DemoController.java`.
100110

101-
Additionally, create a unit test that validates the operation.
102-
103-
From now on, you will have to create the unit tests for every new operation. Wasn't it easy with Copilot?
111+
Add the following endpoints using the help of Copilot, then also create the unit tests for every new operation. It is pretty easy with Copilot !
104112

105113
- **/daysbetweendates**:
106114

@@ -140,6 +148,12 @@ From now on, you will have to create the unit tests for every new operation. Was
140148
> Paste the above information and make it as detailed as possible in the Copilot chat text box.
141149
> Copilot will use by default the open file as context in order to generate the suggestion.
142150
151+
152+
### Exercise 4: Building more integrations
153+
154+
We have tried out write coding for a few simple tasks earlier. Now let's explore more complex integrations.
155+
156+
143157
- **/tellmeajoke**:
144158

145159
- Make a call to the joke api and return a random joke - <https://api.chucknorris.io/jokes/random>
@@ -183,19 +197,21 @@ From now on, you will have to create the unit tests for every new operation. Was
183197
- Return a random country from the array
184198
- Return the country and its iso code
185199

186-
### Exercise 3: Document the code
200+
### Exercise 5: Document the code
187201

188202
Documenting code is always a boring and painful task. However, we can use Copilot to document it for us. In the chat, ask Copilot to add javadoc to all of your files.
189203

190-
### Exercise 4: Verify Tests
204+
You can use `@workspaces` to write documentation for the whole repo.
205+
206+
### Exercise 6: Verify Tests
191207

192208
Have you been building your Unit Tests along the way? If not this is the perfect time to take a breather and get Copilot to write some unit tests for you!
193209

194210
We will create automated tests to check that the functionality of the previous endpoints is correctly implemented. The tests should be together in the `CopilotDemoApplicationTests.java` file.
195211

196212
You can leverage Copilot to run the tests. There is a `/tests` command that you can directly run from Copilot Chat or by selecting the piece of code you want to create tests for and using the Copilot inline feature.
197213

198-
### Exercise 5: Create a Dockerfile
214+
### Exercise 7: Create a Dockerfile
199215

200216
Use the Dockerfile provided to create a docker image of the application. There are some comments in the Dockerfile that will help you to complete the exercise.
201217

0 commit comments

Comments
 (0)