diff options
-rw-r--r-- | cgitize/main.py | 10 | ||||
-rw-r--r-- | cgitize/repo.py | 14 |
2 files changed, 22 insertions, 2 deletions
diff --git a/cgitize/main.py b/cgitize/main.py index 920b769..934a2f3 100644 --- a/cgitize/main.py +++ b/cgitize/main.py @@ -86,14 +86,24 @@ class Config: return self.impl.get('GITHUB', 'username', fallback=None) @property + def github_access_token(self): + return self.impl.get('GITHUB', 'access_token', fallback=None) + + @property def bitbucket_username(self): return self.impl.get('BITBUCKET', 'username', fallback=None) + @property + def bitbucket_app_password(self): + return self.impl.get('BITBUCKET', 'app_password', fallback=None) + def set_defaults(self): Repo.DEFAULT_OWNER = self.default_owner Repo.DEFAULT_VIA_SSH = self.via_ssh GithubRepo.DEFAULT_USER = self.github_username + GithubRepo.ACCESS_TOKEN = self.github_access_token BitbucketRepo.DEFAULT_USER = self.bitbucket_username + BitbucketRepo.APP_PASSWORD = self.bitbucket_app_password @property def my_repos(self): diff --git a/cgitize/repo.py b/cgitize/repo.py index 02e283b..5c7d163 100644 --- a/cgitize/repo.py +++ b/cgitize/repo.py @@ -76,6 +76,7 @@ class HostedRepo(Repo, abc.ABC): class GithubRepo(HostedRepo): DEFAULT_USER = None + ACCESS_TOKEN = None def provider_name(self): return 'GitHub' @@ -87,7 +88,11 @@ class GithubRepo(HostedRepo): return f'ssh://git@github.com/{user}/{name}.git' def build_clone_url_https(self, user, name): - return f'https://github.com/{user}/{name}.git' + if GithubRepo.ACCESS_TOKEN is None: + auth = '' + else: + auth = f'{GithubRepo.ACCESS_TOKEN}@' + return f'https://{auth}github.com/{user}/{name}.git' def build_homepage_url(self, user, name): return f'https://github.com/{user}/{name}' @@ -95,6 +100,7 @@ class GithubRepo(HostedRepo): class BitbucketRepo(HostedRepo): DEFAULT_USER = None + APP_PASSWORD = None def provider_name(self): return 'Bitbucket' @@ -106,7 +112,11 @@ class BitbucketRepo(HostedRepo): return f'ssh://git@bitbucket.org/{user}/{name}.git' def build_clone_url_https(self, user, name): - return f'https://bitbucket.org/{user}/{name}.git' + if BitbucketRepo.APP_PASSWORD is None: + auth = '' + else: + auth = f'{user}:{Bitbucket.APP_PASSWORD}@' + return f'https://{auth}bitbucket.org/{user}/{name}.git' def build_homepage_url(self, user, name): return f'https://bitbucket.org/{user}/{name.lower()}' |