Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import logging as log # for verbose output
from .BitBucketRepoSession import BitBucketRepoSession
from .GitHubRepoSession import GitHubRepoSession
from .GitLabRepoSession import GitLabRepoSession
from .LocalVersionSession import LocalVersionSession
from .MercurialRepoSession import MercurialRepoSession
from .SourceForgeRepoSession import SourceForgeRepoSession
class HolderFactory:
HOLDERS = {
'github': GitHubRepoSession,
'gitlab': GitLabRepoSession,
'bitbucket': BitBucketRepoSession,
'hg': MercurialRepoSession,
'sf': SourceForgeRepoSession,
'local': LocalVersionSession
}
@staticmethod
# go through subclasses in order to find the one that is hodling a given project
# repo is either complete URL or a name allowing to identify a single project
def get_instance_for_repo(repo):
holder_class = HolderFactory.HOLDERS['github']
hostname = None
known_repo = None
for k, sc in HolderFactory.HOLDERS.items():
known_repo = sc.is_official_for_repo(repo)
if known_repo:
def __init__(self, repo, hostname):
super(GitLabRepoSession, self).__init__()
self.pa_token = os.getenv("GITLAB_PA_TOKEN")
self.hostname = hostname
if not self.hostname:
self.hostname = self.DEFAULT_HOSTNAME
if self.pa_token:
log.info('Using Personal Access token.')
self.headers.update({'Private-Token': "{}".format(self.pa_token)})
self.api_base = 'https://{}/api/v4'.format(self.hostname)
self.repo = repo
self.repo_id = self.repo.replace('/', '%2F')