Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions github-cli-examples/README.md
Original file line number Diff line number Diff line change
@@ -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.
17 changes: 17 additions & 0 deletions github-cli-examples/open_bugs.py
Original file line number Diff line number Diff line change
@@ -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']}")
Loading