Skip to content

Commit b3b3d65

Browse files
Copilotbrunoborges
andcommitted
Add JBang prerequisites and usage instructions to all cookbook recipes
Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com>
1 parent e2467d1 commit b3b3d65

6 files changed

Lines changed: 118 additions & 23 deletions

File tree

src/site/markdown/cookbook/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
This folder hosts short, practical recipes for using the GitHub Copilot SDK with Java. Each recipe is concise, copy‑pasteable, and points to fuller examples and tests.
44

5+
## Prerequisites
6+
7+
All cookbook examples can be run directly using [JBang](https://www.jbang.dev/), which allows you to run Java code without a full project setup.
8+
9+
**Install JBang:**
10+
11+
```bash
12+
# macOS (using Homebrew)
13+
brew install jbangdev/tap/jbang
14+
15+
# Linux/macOS (using curl)
16+
curl -Ls https://sh.jbang.dev | bash -s - app setup
17+
18+
# Windows (using Scoop)
19+
scoop install jbang
20+
```
21+
22+
For other installation methods, see the [JBang installation guide](https://www.jbang.dev/download/).
23+
524
## Recipes
625

726
- [Error Handling](error-handling.md): Handle errors gracefully including connection failures, timeouts, and cleanup.

src/site/markdown/cookbook/error-handling.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,33 @@
22

33
Handle errors gracefully in your Copilot SDK applications.
44

5+
## Prerequisites
6+
7+
Install [JBang](https://www.jbang.dev/) to run these examples:
8+
9+
```bash
10+
# macOS (using Homebrew)
11+
brew install jbangdev/tap/jbang
12+
13+
# Linux/macOS (using curl)
14+
curl -Ls https://sh.jbang.dev | bash -s - app setup
15+
16+
# Windows (using Scoop)
17+
scoop install jbang
18+
```
19+
520
## Example scenario
621

722
You need to handle various error conditions like connection failures, timeouts, and invalid responses.
823

924
## Basic error handling
1025

26+
**Usage:**
27+
```bash
28+
jbang BasicErrorHandling.java
29+
```
30+
31+
**Code:**
1132
```java
1233
//DEPS io.github.copilot-community-sdk:copilot-sdk:${project.version}
1334
import com.github.copilot.sdk.*;

src/site/markdown/cookbook/managing-local-files.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,33 @@
22

33
Use Copilot to intelligently organize files in a folder based on their metadata.
44

5+
## Prerequisites
6+
7+
Install [JBang](https://www.jbang.dev/) to run these examples:
8+
9+
```bash
10+
# macOS (using Homebrew)
11+
brew install jbangdev/tap/jbang
12+
13+
# Linux/macOS (using curl)
14+
curl -Ls https://sh.jbang.dev | bash -s - app setup
15+
16+
# Windows (using Scoop)
17+
scoop install jbang
18+
```
19+
520
## Example scenario
621

722
You have a folder with many files and want to organize them into subfolders based on metadata like file type, creation date, size, or other attributes. Copilot can analyze the files and suggest or execute a grouping strategy.
823

924
## Example code
1025

26+
**Usage:**
27+
```bash
28+
jbang ManagingLocalFiles.java
29+
```
30+
31+
**Code:**
1132
```java
1233
//DEPS io.github.copilot-community-sdk:copilot-sdk:${project.version}
1334
import com.github.copilot.sdk.*;

src/site/markdown/cookbook/multiple-sessions.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,33 @@
22

33
Manage multiple independent conversations simultaneously.
44

5+
## Prerequisites
6+
7+
Install [JBang](https://www.jbang.dev/) to run these examples:
8+
9+
```bash
10+
# macOS (using Homebrew)
11+
brew install jbangdev/tap/jbang
12+
13+
# Linux/macOS (using curl)
14+
curl -Ls https://sh.jbang.dev | bash -s - app setup
15+
16+
# Windows (using Scoop)
17+
scoop install jbang
18+
```
19+
520
## Example scenario
621

722
You need to run multiple conversations in parallel, each with its own context and history.
823

924
## Java
1025

26+
**Usage:**
27+
```bash
28+
jbang MultipleSessions.java
29+
```
30+
31+
**Code:**
1132
```java
1233
//DEPS io.github.copilot-community-sdk:copilot-sdk:${project.version}
1334
import com.github.copilot.sdk.*;

src/site/markdown/cookbook/persisting-sessions.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,33 @@
22

33
Save and restore conversation sessions across application restarts.
44

5+
## Prerequisites
6+
7+
Install [JBang](https://www.jbang.dev/) to run these examples:
8+
9+
```bash
10+
# macOS (using Homebrew)
11+
brew install jbangdev/tap/jbang
12+
13+
# Linux/macOS (using curl)
14+
curl -Ls https://sh.jbang.dev | bash -s - app setup
15+
16+
# Windows (using Scoop)
17+
scoop install jbang
18+
```
19+
520
## Example scenario
621

722
You want users to be able to continue a conversation even after closing and reopening your application.
823

924
## Creating a session with a custom ID
1025

26+
**Usage:**
27+
```bash
28+
jbang PersistingSessions.java
29+
```
30+
31+
**Code:**
1132
```java
1233
//DEPS io.github.copilot-community-sdk:copilot-sdk:${project.version}
1334
import com.github.copilot.sdk.*;

src/site/markdown/cookbook/pr-visualization.md

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,33 @@
22

33
Build an interactive CLI tool that visualizes pull request age distribution for a GitHub repository using Copilot's built-in capabilities.
44

5-
## Example scenario
5+
## Prerequisites
66

7-
You want to understand how long PRs have been open in a repository. This tool detects the current Git repo or accepts a repo as input, then lets Copilot fetch PR data via the GitHub MCP Server and generate a chart image.
7+
Install [JBang](https://www.jbang.dev/) to run this example:
88

9-
## Prerequisites
9+
```bash
10+
# macOS (using Homebrew)
11+
brew install jbangdev/tap/jbang
1012

11-
Add the following dependency to your `pom.xml`:
13+
# Linux/macOS (using curl)
14+
curl -Ls https://sh.jbang.dev | bash -s - app setup
1215

13-
```xml
14-
<dependency>
15-
<groupId>io.github.copilot-community-sdk</groupId>
16-
<artifactId>copilot-sdk</artifactId>
17-
<version>1.0.8</version>
18-
</dependency>
16+
# Windows (using Scoop)
17+
scoop install jbang
1918
```
2019

20+
## Example scenario
21+
22+
You want to understand how long PRs have been open in a repository. This tool detects the current Git repo or accepts a repo as input, then lets Copilot fetch PR data via the GitHub MCP Server and generate a chart image.
23+
2124
## Usage
2225

2326
```bash
2427
# Auto-detect from current git repo
25-
java PRVisualization.java
28+
jbang PRVisualization.java
2629

2730
# Specify a repo explicitly
28-
java PRVisualization.java github/copilot-sdk
31+
jbang PRVisualization.java github/copilot-sdk
2932
```
3033

3134
## Full example: PRVisualization.java
@@ -222,14 +225,3 @@ public class PRVisualization {
222225
| Flexibility | Fixed logic | **AI decides best approach** |
223226
| Chart types | What you coded | **Any type Copilot can generate** |
224227
| Data grouping | Hardcoded buckets | **Intelligent grouping** |
225-
226-
## Running with JBang
227-
228-
You can also run this example directly with JBang:
229-
230-
```bash
231-
//DEPS io.github.copilot-community-sdk:copilot-sdk:${project.version}
232-
233-
# Then run:
234-
jbang PRVisualization.java github/copilot-sdk
235-
```

0 commit comments

Comments
 (0)