Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3995858
D2462.id6204.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D2462.id6204.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D2462: List all repositories from a GitHub organization
Attached
Detach File
Event Timeline
Log In to Comment