aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cgitize
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2022-03-08 11:52:44 +0500
committerEgor Tensin <Egor.Tensin@gmail.com>2022-03-08 12:11:58 +0500
commit353f9be1ff8b308eb5779f5793cbc5d88b9a5e91 (patch)
tree80951940e131d99abce2aa85ffe7a03aa0b359ba /cgitize
parentfix whitespace (diff)
downloadcgitize-353f9be1ff8b308eb5779f5793cbc5d88b9a5e91.tar.gz
cgitize-353f9be1ff8b308eb5779f5793cbc5d88b9a5e91.zip
support mirroring all of org's repositories
Diffstat (limited to 'cgitize')
-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)