aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cgit
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--cgitize/config.py31
-rw-r--r--cgitize/github.py7
2 files changed, 35 insertions, 3 deletions
diff --git a/cgitize/config.py b/cgitize/config.py
index ce139ea..925dee7 100644
--- a/cgitize/config.py
+++ b/cgitize/config.py
@@ -68,7 +68,6 @@ class ServiceSection(Section, ABC):
r = HostedRepo(r)
yield api.convert_repo(api.get_repo(r), cfg, r.dir)
for u in self.users.enum_users():
- u = User(u)
for r in api.get_user_repos(u):
r = api.convert_repo(r, cfg, u.dir)
if r.name in u.skip:
@@ -81,6 +80,10 @@ class ServiceSection(Section, ABC):
class GitHubSection(ServiceSection):
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.orgs = OrgsSection(self.impl.get('organizations', {}))
+
@property
def access_token(self):
return self._get_config_or_env('access_token', 'CGITIZE_GITHUB_ACCESS_TOKEN')
@@ -89,6 +92,16 @@ class GitHubSection(ServiceSection):
def url_auth(self):
return self.access_token
+ def enum_repositories(self, cfg):
+ yield from super().enum_repositories(cfg)
+ api = self.connect_to_service()
+ for org in self.orgs.enum_orgs():
+ for repo in api.get_org_repos(org):
+ repo = api.convert_repo(repo, cfg, org.dir)
+ if repo.name in org.skip:
+ continue
+ yield repo
+
def connect_to_service(self):
return GitHub(self.access_token)
@@ -135,7 +148,12 @@ class GitLabSection(ServiceSection):
class UsersSection(Section):
def enum_users(self):
- return self.impl.values()
+ return map(User, self.impl.values())
+
+
+class OrgsSection(Section):
+ def enum_orgs(self):
+ return map(Org, self.impl.values())
class RepositoriesSection(Section):
@@ -146,7 +164,7 @@ class RepositoriesSection(Section):
class User:
def __init__(self, impl):
if 'name' not in impl:
- raise ValueError("every user must have 'name'")
+ raise ValueError("every user must have a 'name'")
self._impl = impl
@property
@@ -162,6 +180,13 @@ class User:
return self._impl.get('skip', [])
+class Org(User):
+ def __init__(self, impl):
+ if 'name' not in impl:
+ raise ValueError("every organization must have a 'name'")
+ self._impl = impl
+
+
class HostedRepo:
def __init__(self, impl):
if 'id' not in impl:
diff --git a/cgitize/github.py b/cgitize/github.py
index 761b2b7..5bbf8d8 100644
--- a/cgitize/github.py
+++ b/cgitize/github.py
@@ -28,6 +28,13 @@ class GitHub:
logging.error("Couldn't fetch user repositories: %s", user.name)
raise
+ def get_org_repos(self, org):
+ try:
+ return self._impl.get_organization(org.name).get_repos()
+ except GithubException:
+ logging.error("Couldn't fetch organization repositories: %s", org.name)
+ raise
+
@staticmethod
def convert_repo(repo, *args, **kwargs):
return Repo.from_github(repo, *args, **kwargs)