Skip to content

Commit

Permalink
Merge pull request #228 from lilyinstarlight/feature/version-prefixed…
Browse files Browse the repository at this point in the history
…-unstable-versions

prefix unstable version numbers with latest release per current guidelines
  • Loading branch information
Mic92 authored Mar 6, 2024
2 parents 37e9b32 + 5ef0425 commit ff99539
Show file tree
Hide file tree
Showing 9 changed files with 611 additions and 395 deletions.
6 changes: 5 additions & 1 deletion nix_update/version/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@ def fetch_bitbucket_snapshots(url: ParseResult, branch: str) -> list[Version]:
commits_url = f'https://{url.netloc}/!api/2.0/repositories/{owner}/{repo}/refs?q=name="{branch}"'
resp = urlopen(commits_url)
ref = json.loads(resp.read())["values"][0]["target"]

versions = fetch_bitbucket_versions(url)
latest_version = versions[0].number if versions else "0"

date = ref["date"][:10] # to YYYY-MM-DD
return [Version(f"unstable-{date}", rev=ref["hash"])]
return [Version(f"{latest_version}-unstable-{date}", rev=ref["hash"])]
5 changes: 4 additions & 1 deletion nix_update/version/gitea.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ def fetch_gitea_snapshots(url: ParseResult, branch: str) -> list[Version]:
if commit is None:
return []

versions = fetch_gitea_versions(url)
latest_version = versions[0].number if versions else "0"

date = commit["commit"]["committer"]["date"][:10]
return [Version(f"unstable-{date}", rev=commit["sha"])]
return [Version(f"{latest_version}-unstable-{date}", rev=commit["sha"])]
5 changes: 4 additions & 1 deletion nix_update/version/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def fetch_github_snapshots(url: ParseResult, branch: str) -> list[Version]:
tree = ET.fromstring(resp.read())
commits = tree.findall(".//{http://www.w3.org/2005/Atom}entry")

versions = fetch_github_versions(url)
latest_version = versions[0].number if versions else "0"

for entry in commits:
link = entry.find("{http://www.w3.org/2005/Atom}link")
updated = entry.find("{http://www.w3.org/2005/Atom}updated")
Expand All @@ -56,6 +59,6 @@ def fetch_github_snapshots(url: ParseResult, branch: str) -> list[Version]:
url = urlparse(link.attrib["href"])
commit = url.path.rsplit("/", maxsplit=1)[-1]
date = updated.text.split("T", maxsplit=1)[0]
return [Version(f"unstable-{date}", rev=commit)]
return [Version(f"{latest_version}-unstable-{date}", rev=commit)]

return []
13 changes: 10 additions & 3 deletions nix_update/version/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,15 @@ def fetch_gitlab_snapshots(url: ParseResult, branch: str) -> list[Version]:
info(f"fetch {gitlab_url}")
resp = urllib.request.urlopen(gitlab_url)
commits = json.load(resp)

versions = fetch_gitlab_versions(url)
latest_version = versions[0].number if versions else "0"

for commit in commits:
date = datetime.strptime(commit["committed_date"], "%Y-%m-%dT%H:%M:%S.000%z")
date -= date.utcoffset() # type: ignore[operator]
return [Version(date.strftime("unstable-%Y-%m-%d"), rev=commit["id"])]
commit_date = datetime.strptime(
commit["committed_date"], "%Y-%m-%dT%H:%M:%S.000%z"
)
commit_date -= commit_date.utcoffset() # type: ignore[operator]
date = commit_date.strftime("%Y-%m-%d")
return [Version(f"{latest_version}-unstable-{date}", rev=commit["id"])]
return []
385 changes: 0 additions & 385 deletions tests/test_branch.atom

This file was deleted.

8 changes: 5 additions & 3 deletions tests/test_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@


def fake_urlopen(url: str) -> BinaryIO:
del url
return open(TEST_ROOT.joinpath("test_branch.atom"), "rb")
if url.endswith("releases.atom"):
return open(TEST_ROOT.joinpath("test_branch_releases.atom"), "rb")
else:
return open(TEST_ROOT.joinpath("test_branch_commits_master.atom"), "rb")


def test_branch(helpers: conftest.Helpers) -> None:
Expand All @@ -27,5 +29,5 @@ def test_branch(helpers: conftest.Helpers) -> None:
"(.*)",
"master",
).number
== "unstable-2021-12-13"
== "1.2.0-unstable-2024-02-19"
)
Loading

0 comments on commit ff99539

Please sign in to comment.