From aef35b10d05dd7be3805f2183a82d63512d8c63d Mon Sep 17 00:00:00 2001 From: Leodanis Pozo Ramos Date: Fri, 30 Oct 2026 16:17:13 +0000 Subject: [PATCH] Sample code for: GitHub CLI Examples: Work With GitHub From Your Terminal Co-Authored-By: Claude Opus 5.5 --- github-cli-examples/README.md | 15 +++++++++++++++ github-cli-examples/open_bugs.py | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 github-cli-examples/README.md create mode 100644 github-cli-examples/open_bugs.py diff --git a/github-cli-examples/README.md b/github-cli-examples/README.md new file mode 100644 index 0000000000..f3961bf4fb --- /dev/null +++ b/github-cli-examples/README.md @@ -0,0 +1,15 @@ +# GitHub CLI Examples + +`open_bugs.py` lists the newest open issues labeled `bug` in a public +GitHub repository by calling `gh issue list --json` from Python. + +## Run + +Install [GitHub CLI](https://cli.github.com/), run `gh auth login`, and then: + +```console +$ python open_bugs.py +$ python open_bugs.py realpython/reader +``` + +The script uses only the standard library and makes read-only calls. diff --git a/github-cli-examples/open_bugs.py b/github-cli-examples/open_bugs.py new file mode 100644 index 0000000000..59f08f61f1 --- /dev/null +++ b/github-cli-examples/open_bugs.py @@ -0,0 +1,17 @@ +import json +import subprocess +import sys + +repo = sys.argv[1] if len(sys.argv) > 1 else "cli/cli" +command = ["gh", "issue", "list", "-R", repo, "--label", "bug", "--limit", "5"] + +result = subprocess.run( + [*command, "--json", "number,title,url"], + stdout=subprocess.PIPE, + text=True, + check=True, +) + +for issue in json.loads(result.stdout): + print(f"#{issue['number']}: {issue['title']}") + print(f" {issue['url']}")