Page MenuHomeDevCentral

D2462.id6204.diff
No OneTemporary

D2462.id6204.diff

diff --git a/README.md b/README.md
new file mode 100644
--- /dev/null
+++ b/README.md
@@ -0,0 +1,8 @@
+## Nasqueron Devtools
+
+This repository hosts small tools and utilities to manage development-related
+tasks.
+
+### GitHub
+
+* **list-repositories:** allow to list all repos from an org account, see T615
diff --git a/github/list-repositories.py b/github/list-repositories.py
new file mode 100755
--- /dev/null
+++ b/github/list-repositories.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+
+
+import requests
+import sys
+
+
+# -------------------------------------------------------------
+# GitHub API methods
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def query_api_repositories_for_names(github_account, page, repositories):
+ url = f"https://api.github.com/orgs/{github_account}/repos?page={page}"
+
+ response = requests.get(url)
+ if response.status_code != 200:
+ raise RuntimeError(
+ f"HTTP error {response.status_code}: {response.text}")
+
+ new_repositories = [repo["name"] for repo in response.json()]
+
+ if len(new_repositories) == 0:
+ # We've all of them.
+ return repositories
+
+ return query_api_repositories_for_names(
+ github_account, page + 1, repositories + new_repositories)
+
+
+def get_all_repositories_names(github_account):
+ return query_api_repositories_for_names(github_account, 1, [])
+
+
+# -------------------------------------------------------------
+# Application entry point
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def run(github_account):
+ for repository in get_all_repositories_names(github_account):
+ print(repository)
+
+
+if __name__ == "__main__":
+ try:
+ run(sys.argv[1])
+ except IndexError:
+ print("Usage:", sys.argv[0], "<GitHub org account>", file=sys.stderr)
+ sys.exit(2)

File Metadata

Mime Type
text/plain
Expires
Sun, Jan 12, 09:39 (20 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2346432
Default Alt Text
D2462.id6204.diff (1 KB)

Event Timeline