def __init__(self, url, app_id, app_key): self.base_url = url self.api_url = urljoin(url, "api/v3") self.graphql_url = urljoin(url, "api/graphql") self._app_id = app_id self._app_key = app_key self.installation_map = {} self.installation_token_cache = {}
def build_file_url(self, repo_name, file_path, highlight_start, highlight_end): file_url = urljoin(self.web_url, repo_name, "tree", file_path) if highlight_start is not None: file_url = "{}#n{}".format(file_url, highlight_start) # NOTE (felix): highlighting a range is not supported by cgit return file_url
def _github_api(github_url): github_api_url = urljoin(github_url, "api/v3") # Mock necessary GitHub API endpoints requests_mock.get( "{}/app/installations".format(github_api_url), json=github_response_installations, ) requests_mock.get( "{}/installation/repositories?per_page=100".format(github_api_url), json=github_response_repositories, ) requests_mock.post( "{}/app/installations/94/access_tokens".format(github_api_url), json=github_response_access_token, )
def get_remote_url(self, repository_name): # TODO (felix): Find a better way to rebuild the url with auth values # TODO (felix): Currently, this method requires the git_host_url to # provide a schema (e.g. https://) scheme, _, url = self.git_host_url.partition("://") if self.user and self.password: auth_part = "{}:{}@".format(self.user, self.password) elif self.user: auth_part = "{}@".format(self.user) else: auth_part = "" auth_base_url = "{}://{}{}".format(scheme, auth_part, url) remote_url = urljoin(auth_base_url, repository_name) return remote_url
def url_for_directory(self, directory_path): return urljoin(self.url, "tree/master", directory_path)
def build_directory_url(self, repo_name, directory_path): directory_url = urljoin(self.web_url, repo_name, "tree", directory_path) return directory_url