From 484f10e7a900fe7d2124147ad34031cb96e1f45e Mon Sep 17 00:00:00 2001 From: ericLemanissier Date: Tue, 28 Mar 2023 16:43:38 +0000 Subject: [PATCH] reuse tag processing logic of GitProject mostly blacklist and whitelist for tags --- ccb/upstream_project.py | 94 +++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 56 deletions(-) diff --git a/ccb/upstream_project.py b/ccb/upstream_project.py index 61f386c0..6b0df75b 100644 --- a/ccb/upstream_project.py +++ b/ccb/upstream_project.py @@ -216,14 +216,45 @@ def _valid_tags(self, tag): return False return True -class GithubReleaseProject(UpstreamProject): + +class GithubProject(GitProject): + HOMEPAGE_RE = re.compile(r"https?://github.com/([^/]+)/([^/]+)") SOURCE_URL_RE = re.compile(r"https?://github.com/([^/]+)/([^/]+)") def __init__(self, recipe): owner, repo = self._get_owner_repo(recipe) - super().__init__(recipe) + git_url = f"https://github.com/{owner}/{repo}.git" + + super().__init__(recipe, git_url) self.owner = owner self.repo = repo + + def source_url(self, version): + if version.unknown: + return None + return f"https://github.com/{self.owner}/{self.repo}/archive/{version.original}.tar.gz" + + @classmethod + def _get_owner_repo(cls, recipe): + try: + url = recipe.source()["url"] + match = cls.SOURCE_URL_RE.match(url) + if match: + return match.groups() + except Exception as exc: + logger.debug( + "%s: not supported as GitHub project because of the following exception: %s", + recipe.name, + repr(exc), + ) + + raise _Unsupported() + + +class GithubReleaseProject(GithubProject): + + def __init__(self, recipe): + super().__init__(recipe) try: with requests.Session() as client: github_token = get_github_token() @@ -243,14 +274,15 @@ def _get_url_for_version(v): if a["content_type"] == "application/gzip": return a["browser_download_url"] for a in artifacts: - if a["content_type"].startswith("application"): + if a["content_type"] == "application/x-bzip2": return a["browser_download_url"] - for a in artifacts: - return a["browser_download_url"] return f"https://github.com/{self.owner}/{self.repo}/archive/refs/tags/{v['tag_name']}.tar.gz" self.__versions = [] for v in resp.json(): - r = Version(v["tag_name"] or v["name"]) + tag_name = v["tag_name"] or v["name"] + r = Version(tag_name, fixer=self.fixer) + if not self._valid_tags(tag_name): + continue r.url = _get_url_for_version(v) self.__versions.append(r) @@ -261,22 +293,6 @@ def _get_url_for_version(v): if not self.__versions: raise _Unsupported() - @classmethod - def _get_owner_repo(cls, recipe): - try: - url = recipe.source()["url"] - match = cls.SOURCE_URL_RE.match(url) - if match: - return match.groups() - except Exception as exc: - logger.debug( - "%s: not supported as GitHub project because of the following exception: %s", - recipe.name, - repr(exc), - ) - - raise _Unsupported() - async def versions(self): return self.__versions @@ -286,40 +302,6 @@ def source_url(self, version): return version.url -class GithubProject(GitProject): - HOMEPAGE_RE = re.compile(r"https?://github.com/([^/]+)/([^/]+)") - SOURCE_URL_RE = re.compile(r"https?://github.com/([^/]+)/([^/]+)") - - def __init__(self, recipe): - owner, repo = self._get_owner_repo(recipe) - git_url = f"https://github.com/{owner}/{repo}.git" - - super().__init__(recipe, git_url) - self.owner = owner - self.repo = repo - - def source_url(self, version): - if version.unknown: - return None - return f"https://github.com/{self.owner}/{self.repo}/archive/{version.original}.tar.gz" - - @classmethod - def _get_owner_repo(cls, recipe): - try: - url = recipe.source()["url"] - match = cls.SOURCE_URL_RE.match(url) - if match: - return match.groups() - except Exception as exc: - logger.debug( - "%s: not supported as GitHub project because of the following exception: %s", - recipe.name, - repr(exc), - ) - - raise _Unsupported() - - class GitlabProject(GitProject): SOURCE_URL_RE = re.compile( r"https?://([^/]*gitlab[^/]+)/([^/]+)/([^/]+)/-/archive/"