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']}")