aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2021-03-29 00:19:13 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2021-03-29 00:45:48 +0300
commit6b37ae836a9334ca00dd01bf959fa97ba7a825d4 (patch)
tree490dc229947266dd913a318f97fcdf7e9f66ff72
parentadd docs/ (diff)
downloadcgitize-6b37ae836a9334ca00dd01bf959fa97ba7a825d4.tar.gz
cgitize-6b37ae836a9334ca00dd01bf959fa97ba7a825d4.zip
support access tokens for GitHub/Bitbucket
-rw-r--r--cgitize/main.py10
-rw-r--r--cgitize/repo.py14
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()}'