Skip to content

Commit

Permalink
reuse tag processing logic of GitProject
Browse files Browse the repository at this point in the history
mostly blacklist and whitelist for tags
  • Loading branch information
ericLemanissier committed Mar 28, 2023
1 parent 58fb090 commit 484f10e
Showing 1 changed file with 38 additions and 56 deletions.
94 changes: 38 additions & 56 deletions ccb/upstream_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)

Expand All @@ -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

Expand All @@ -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/"
Expand Down

0 comments on commit 484f10e

Please sign in to comment.