Skip to content

Commit 8b80800

Browse files
Copilotalexec
andauthored
Add example of using gh CLI to detect language via GitHub Linguist (#35)
* Initial plan * Add example of using gh to determine language parameter via GitHub Linguist Co-authored-by: alexec <1142830+alexec@users.noreply.github.com> * Add error handling and improve language detection examples Co-authored-by: alexec <1142830+alexec@users.noreply.github.com> * Improve clarity of jq default value documentation Co-authored-by: alexec <1142830+alexec@users.noreply.github.com> * Simplify language detection using gh repo view command Co-authored-by: alexec <1142830+alexec@users.noreply.github.com> * Add additional useful repository attributes from gh repo view Co-authored-by: alexec <1142830+alexec@users.noreply.github.com> * Remove additional GitHub attributes, keep only language parameter Co-authored-by: alexec <1142830+alexec@users.noreply.github.com> * Simplify documentation - remove jq prerequisite and other parameters Co-authored-by: alexec <1142830+alexec@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: alexec <1142830+alexec@users.noreply.github.com> Co-authored-by: Alex Collins <alexec@users.noreply.github.com>
1 parent 54734fa commit 8b80800

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,47 @@ $variableName # Simple variable substitution (works with alphanumeric names
11861186

11871187
Variables that are not provided via `-p` flag are replaced with empty strings.
11881188

1189+
### Determining Common Parameters
1190+
1191+
You can automate the detection of common parameters like `language` using external tools. Here's an example using the GitHub CLI (`gh`) to determine the primary programming language via GitHub Linguist:
1192+
1193+
**Example: Automatically detect language using GitHub Linguist**
1194+
1195+
```bash
1196+
# Get the primary language from the current repository
1197+
LANGUAGE=$(gh repo view --json primaryLanguage --jq .primaryLanguage.name)
1198+
1199+
# Use the detected language with coding-context
1200+
coding-context -p language="$LANGUAGE" my-task
1201+
```
1202+
1203+
This works because GitHub uses Linguist to analyze repository languages, and `gh repo view` provides direct access to the primary language detected for the current repository.
1204+
1205+
**Example with error handling:**
1206+
1207+
```bash
1208+
# Get primary language with error handling
1209+
LANGUAGE=$(gh repo view --json primaryLanguage --jq .primaryLanguage.name 2>/dev/null)
1210+
1211+
# Check if we successfully detected a language
1212+
if [ -z "$LANGUAGE" ] || [ "$LANGUAGE" = "null" ]; then
1213+
echo "Warning: Could not detect language, using default"
1214+
LANGUAGE="Go" # or your preferred default
1215+
fi
1216+
1217+
coding-context -p language="$LANGUAGE" my-task
1218+
```
1219+
1220+
**One-liner version:**
1221+
1222+
```bash
1223+
coding-context -p language="$(gh repo view --json primaryLanguage --jq .primaryLanguage.name)" my-task
1224+
```
1225+
1226+
**Prerequisites:**
1227+
- Install GitHub CLI: `brew install gh` (macOS) or `sudo apt install gh` (Ubuntu)
1228+
- Authenticate: `gh auth login`
1229+
11891230
### Directory Priority
11901231

11911232
When the same task exists in multiple directories, the first match wins:

0 commit comments

Comments
 (0)