diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2021-03-29 00:19:13 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2021-03-29 00:45:48 +0300 |
commit | 6b37ae836a9334ca00dd01bf959fa97ba7a825d4 (patch) | |
tree | 490dc229947266dd913a318f97fcdf7e9f66ff72 | |
parent | add docs/ (diff) | |
download | cgitize-6b37ae836a9334ca00dd01bf959fa97ba7a825d4.tar.gz cgitize-6b37ae836a9334ca00dd01bf959fa97ba7a825d4.zip |
support access tokens for GitHub/Bitbucket
Diffstat (limited to '')
-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()}' |