aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2021-08-02 09:42:14 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2021-08-02 09:42:14 +0300
commit7badc1c6ba77c3afbe94a66cfd4b5f63e207e539 (patch)
tree75f7e0755160772e4deeecd756359b094403a788
parentcgitize.repo: discard empty descriptions (diff)
downloadcgitize-7badc1c6ba77c3afbe94a66cfd4b5f63e207e539.tar.gz
cgitize-7badc1c6ba77c3afbe94a66cfd4b5f63e207e539.zip
support skipping some of user's repositories
-rw-r--r--cgitize/bitbucket.py6
-rw-r--r--cgitize/config.py30
-rw-r--r--cgitize/github.py6
-rw-r--r--examples/cgitize.toml4
4 files changed, 34 insertions, 12 deletions
diff --git a/cgitize/bitbucket.py b/cgitize/bitbucket.py
index eaa8bb5..052d2c1 100644
--- a/cgitize/bitbucket.py
+++ b/cgitize/bitbucket.py
@@ -8,6 +8,8 @@ import logging
from atlassian.bitbucket.cloud import Cloud
from requests.exceptions import HTTPError
+from cgitize.repo import Repo
+
class Bitbucket:
def __init__(self, username=None, password=None):
@@ -33,3 +35,7 @@ class Bitbucket:
except HTTPError:
logging.error("Couldn't fetch user repositories: %s", user.name)
raise
+
+ @staticmethod
+ def convert_repo(repo, *args, **kwargs):
+ return Repo.from_bitbucket(repo, *args, **kwargs)
diff --git a/cgitize/config.py b/cgitize/config.py
index 9f515c9..036b855 100644
--- a/cgitize/config.py
+++ b/cgitize/config.py
@@ -119,6 +119,10 @@ class User:
def dir(self):
return self._impl.get('dir')
+ @property
+ def skip(self):
+ return self._impl.get('skip', [])
+
class HostedRepo:
def __init__(self, impl):
@@ -155,23 +159,25 @@ class Config:
for r in self.repositories.enum_repositories():
yield Repo.from_config(r, self)
- def _parse_github_repositories(self):
- github = GitHub(self.github.access_token)
- for r in self.github.repositories.enum_repositories():
+ def _parse_hosted_repositories(self, cfg, api):
+ for r in cfg.repositories.enum_repositories():
r = HostedRepo(r)
- yield Repo.from_github(github.get_repo(r), self, r.dir)
- for u in self.github.users.enum_users():
+ yield api.convert_repo(api.get_repo(r), self, r.dir)
+ for u in cfg.users.enum_users():
u = User(u)
- yield from (Repo.from_github(r, self, u.dir) for r in github.get_user_repos(u))
+ for r in api.get_user_repos(u):
+ r = api.convert_repo(r, self, u.dir)
+ if r.name in u.skip:
+ continue
+ yield r
+
+ def _parse_github_repositories(self):
+ github = GitHub(self.github.access_token)
+ return self._parse_hosted_repositories(self.github, github)
def _parse_bitbucket_repositories(self):
bitbucket = Bitbucket(self.bitbucket.username, self.bitbucket.app_password)
- for r in self.bitbucket.repositories.enum_repositories():
- r = HostedRepo(r)
- yield Repo.from_bitbucket(bitbucket.get_repo(r), self, r.dir)
- for u in self.bitbucket.users.enum_users():
- u = User(u)
- yield from (Repo.from_bitbucket(r, self, u.dir) for r in bitbucket.get_user_repos(u))
+ return self._parse_hosted_repositories(self.bitbucket, bitbucket)
def parse_repositories(self):
yield from self._parse_explicit_repositories()
diff --git a/cgitize/github.py b/cgitize/github.py
index a5754af..761b2b7 100644
--- a/cgitize/github.py
+++ b/cgitize/github.py
@@ -7,6 +7,8 @@ import logging
from github import Github, GithubException
+from cgitize.repo import Repo
+
class GitHub:
def __init__(self, access_token):
@@ -25,3 +27,7 @@ class GitHub:
except GithubException:
logging.error("Couldn't fetch user repositories: %s", user.name)
raise
+
+ @staticmethod
+ def convert_repo(repo, *args, **kwargs):
+ return Repo.from_github(repo, *args, **kwargs)
diff --git a/examples/cgitize.toml b/examples/cgitize.toml
index d0cf0c0..3a798d5 100644
--- a/examples/cgitize.toml
+++ b/examples/cgitize.toml
@@ -25,6 +25,8 @@ name = "egor-tensin"
# To avoid directory name clashes with other repositories, you can specify a
# subdirectory to put that user's repositories to.
dir = "github-dir"
+# Repositories to skip:
+#skip = ["repo1", "repo2"]
# Some random repositories hosted on GitHub:
[github.repositories.lens]
@@ -49,6 +51,8 @@ name = "egor-tensin"
# To avoid directory name clashes with other repositories, you can specify a
# subdirectory to put that user's repositories to.
dir = "bitbucket-dir"
+# Repositories to skip:
+#skip = ["repo1", "repo2"]
# Some random repositories hosted on Bitbucket:
[bitbucket.repositories.cef]