🎨 Handle release when project is forked.

This commit is contained in:
Nikhil Badyal
2024-04-13 00:08:43 +05:30
parent bac43d4ce7
commit b6c3d3bfd9
2 changed files with 12 additions and 8 deletions
+2
View File
@@ -123,6 +123,8 @@ class APP(object):
from src.downloader.github import Github
tag, url = Github.patch_resource(url, assets_filter, config)
if tag.startswith("tags/"):
tag = tag.split("/")[-1]
elif url.startswith("local://"):
return tag, url.split("/")[-1]
if not file_name:
+10 -8
View File
@@ -57,10 +57,13 @@ class Github(Downloader):
tag_position = 3
if len(path_segments) > tag_position and path_segments[3] == "latest-prerelease":
logger.info(f"Including pre-releases/beta for {github_repo_name} selection.")
pre_ok = True
latest_tag = str(latest(f"{github_repo_owner}/{github_repo_name}", output_format="tag", pre_ok=True))
release_tag = f"tags/{latest_tag}"
else:
pre_ok = False
release_tag = str(latest(f"{github_repo_owner}/{github_repo_name}", output_format="tag", pre_ok=pre_ok))
release_tag = next(
(f"tags/{path_segments[i + 1]}" for i, segment in enumerate(path_segments) if segment == "tag"),
"latest",
)
return github_repo_owner, github_repo_name, release_tag
@staticmethod
@@ -70,7 +73,7 @@ class Github(Downloader):
release_tag: str,
asset_filter: str,
config: RevancedConfig,
) -> str:
) -> tuple[str, str]:
"""Get assets from given tag."""
api_url = f"https://api.github.com/repos/{github_repo_owner}/{github_repo_name}/releases/{release_tag}"
headers = {
@@ -92,12 +95,11 @@ class Github(Downloader):
assets_name = asset["name"]
if match := filter_pattern.search(assets_url):
logger.debug(f"Found {assets_name} to be downloaded from {assets_url}")
return match.group()
return ""
return response.json()["tag_name"], match.group()
return "", ""
@staticmethod
def patch_resource(repo_url: str, assets_filter: str, config: RevancedConfig) -> tuple[str, str]:
"""Fetch patch resource from repo url."""
repo_owner, repo_name, latest_tag = Github._extract_repo_owner_and_tag(repo_url)
tag = f"tags/{latest_tag}"
return latest_tag, Github._get_release_assets(repo_owner, repo_name, tag, assets_filter, config)
return Github._get_release_assets(repo_owner, repo_name, latest_tag, assets_filter, config)