Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support latest commit on branch #10

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions autoupdate_app_sources/autoupdate_app_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ def get_latest_version_and_asset(
upstream = autoupdate.get("upstream", self.main_upstream)
version_re = autoupdate.get("version_regex", None)
allow_prereleases = autoupdate.get("allow_prereleases", False)
branch_name = autoupdate.get("branch", None)
_, remote_type, revision_type = strategy.split("_")

api: Union[GithubAPI, GitlabAPI, GiteaForgejoAPI, DownloadPageAPI]
Expand Down Expand Up @@ -550,8 +551,12 @@ def get_latest_version_and_asset(
raise ValueError(
"For the latest commit strategies, only asset = 'tarball' is supported"
)
commits = api.commits()
latest_commit = commits[0]
latest_commit = None
if branch_name is None:
commits = api.commits()
latest_commit = commits[0]
else:
latest_commit = api.tip_of_branch(branch_name)
latest_tarball = api.url_for_ref(latest_commit["sha"], RefType.commits)
# Let's have the version as something like "2023.01.23"
latest_commit_date = datetime.strptime(
Expand Down
24 changes: 24 additions & 0 deletions autoupdate_app_sources/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def commits(self) -> list[dict[str, Any]]:
"""Get a list of commits for project."""
return self.internal_api(f"repos/{self.upstream_repo}/commits")

def tip_of_branch(self, branch: str) -> Any:
"""Get SHA of commit that's tip of provided branch"""
return self.internal_api(f"repos/{self.upstream_repo}/branches/{branch}")["commit"]

def releases(self) -> list[dict[str, Any]]:
"""Get a list of releases for project."""
return self.internal_api(f"repos/{self.upstream_repo}/releases?per_page=100")
Expand Down Expand Up @@ -116,6 +120,16 @@ def commits(self) -> list[dict[str, Any]]:
)
]

def tip_of_branch(self, branch: str) -> Any:
"""Get SHA of commit that's tip of provided branch"""
commit = self.internal_api(
f"projects/{self.project_id}/repository/branches/{branch}"
)["commit"]
return {
"sha": commit["id"],
"commit": {"author": {"date": commit["committed_date"]}},
}

def releases(self) -> list[dict[str, Any]]:
"""Get a list of releases for project."""
releases = self.internal_api(f"projects/{self.project_id}/releases")
Expand Down Expand Up @@ -192,6 +206,16 @@ def commits(self) -> list[dict[str, Any]]:
"""Get a list of commits for project."""
return self.internal_api(f"repos/{self.project_path}/commits")

def tip_of_branch(self, branch: str) -> Any:
"""Get SHA of commit that's tip of provided branch"""
commit = self.internal_api(f"repos/{self.project_path}/branches/{branch}")[
"commit"
]
return {
"sha": commit["id"],
"commit": {"author": {"date": commit["timestamp"]}},
}

def releases(self) -> list[dict[str, Any]]:
"""Get a list of releases for project."""
return self.internal_api(f"repos/{self.project_path}/releases")
Expand Down