aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cgit
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-08-23 10:13:59 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2023-08-23 10:23:02 +0200
commit5ffe1fb9f036fbd81b5e1b1fa191bd7560aa9f5c (patch)
treef4dd9d2dce555fddbbe526a9c7d42858160ba6aa /cgit
parentexample/cgitize.toml: add a couple of comments (diff)
downloadcgitize-5.0.0.tar.gz
cgitize-5.0.0.zip
fetch private GitHub user repositoriesv5.0.0
This is in line with how it works for Bitbucket & GitLab.
Diffstat (limited to '')
-rw-r--r--cgitize/config.py22
-rw-r--r--cgitize/github.py10
2 files changed, 27 insertions, 5 deletions
diff --git a/cgitize/config.py b/cgitize/config.py
index af7c195..d4e660a 100644
--- a/cgitize/config.py
+++ b/cgitize/config.py
@@ -89,6 +89,10 @@ class GitHubSection(ServiceSection):
return self._get_config_or_env('token', 'CGITIZE_GITHUB_TOKEN')
@property
+ def username(self):
+ return self._get_config_or_env('username', 'CGITIZE_GITHUB_USERNAME')
+
+ @property
def url_auth(self):
return self.token
@@ -103,7 +107,11 @@ class GitHubSection(ServiceSection):
yield repo
def connect_to_service(self):
- return GitHub(self.token)
+ username = self.username
+ token = self.token
+ if (username is None) != (token is None):
+ raise RuntimeError('please set either both the GitHub username & token, or neither')
+ return GitHub(username, token)
def two_part_url_auth(username, password):
@@ -126,7 +134,11 @@ class BitbucketSection(ServiceSection):
return two_part_url_auth(self.username, self.token)
def connect_to_service(self):
- return Bitbucket(self.username, self.token)
+ username = self.username
+ token = self.token
+ if (username is None) != (token is None):
+ raise RuntimeError('please set either both the Bitbucket username & token, or neither')
+ return Bitbucket(username, token)
class GitLabSection(ServiceSection):
@@ -143,7 +155,11 @@ class GitLabSection(ServiceSection):
return two_part_url_auth(self.username, self.token)
def connect_to_service(self):
- return GitLab(self.token)
+ username = self.username
+ token = self.token
+ if (username is None) != (token is None):
+ raise RuntimeError('please set either both the GitLab username & token, or neither')
+ return GitLab(token)
class UsersSection(Section):
diff --git a/cgitize/github.py b/cgitize/github.py
index b3dcc19..9948a33 100644
--- a/cgitize/github.py
+++ b/cgitize/github.py
@@ -11,7 +11,8 @@ from cgitize.repo import Repo
class GitHub:
- def __init__(self, token):
+ def __init__(self, username, token):
+ self._username = username
self._impl = Github(token)
def get_repo(self, repo):
@@ -23,7 +24,12 @@ class GitHub:
def get_user_repos(self, user):
try:
- return self._impl.get_user(user.name).get_repos()
+ if user.name == self._username:
+ # To get private repositories, get_user() must be called
+ # without arguments:
+ return self._impl.get_user().get_repos(affiliation='owner')
+ else:
+ return self._impl.get_user(user.name).get_repos()
except GithubException:
logging.error("Couldn't fetch user repositories: %s", user.name)
raise