mirror of
https://github.com/Mic92/nix-update.git
synced 2024-09-11 02:25:32 +03:00
bitbucket.org support for versions and snapshots
This commit is contained in:
parent
f6f45655e7
commit
a10f7c047f
@ -314,6 +314,9 @@ def update_version(
|
||||
package.diff_url = f"https://{package.parsed_url.netloc}/{owner}/{repo}/compare/{package.rev}...{new_version.rev or new_version.number}"
|
||||
elif GITLAB_API.match(package.parsed_url.geturl()) and package.src_homepage:
|
||||
package.diff_url = f"{package.src_homepage}-/compare/{package.rev}...{new_version.rev or new_version.number}"
|
||||
elif package.parsed_url.netloc in ["bitbucket.org", "bitbucket.io"]:
|
||||
_, owner, repo, *_ = package.parsed_url.path.split("/")
|
||||
package.diff_url = f"https://{package.parsed_url.netloc}/{owner}/{repo}/branches/compare/{new_version.rev or new_version.number}%0D{package.rev}"
|
||||
|
||||
return replace_version(package)
|
||||
|
||||
|
@ -5,6 +5,7 @@ from typing import Protocol
|
||||
from urllib.parse import ParseResult
|
||||
|
||||
from ..errors import VersionError
|
||||
from .bitbucket import fetch_bitbucket_snapshots, fetch_bitbucket_versions
|
||||
from .crate import fetch_crate_versions
|
||||
from .gitea import fetch_gitea_snapshots, fetch_gitea_versions
|
||||
from .github import fetch_github_snapshots, fetch_github_versions
|
||||
@ -39,12 +40,14 @@ fetchers: list[Callable[[ParseResult], list[Version]]] = [
|
||||
fetch_rubygem_versions,
|
||||
fetch_savannah_versions,
|
||||
fetch_sourcehut_versions,
|
||||
fetch_bitbucket_versions,
|
||||
]
|
||||
|
||||
branch_snapshots_fetchers: list[SnapshotFetcher] = [
|
||||
fetch_gitea_snapshots,
|
||||
fetch_github_snapshots,
|
||||
fetch_gitlab_snapshots,
|
||||
fetch_bitbucket_snapshots,
|
||||
]
|
||||
|
||||
|
||||
|
30
nix_update/version/bitbucket.py
Normal file
30
nix_update/version/bitbucket.py
Normal file
@ -0,0 +1,30 @@
|
||||
import json
|
||||
from urllib.parse import ParseResult
|
||||
from urllib.request import urlopen
|
||||
|
||||
from .version import Version
|
||||
|
||||
|
||||
def fetch_bitbucket_versions(url: ParseResult) -> list[Version]:
|
||||
if url.netloc not in ["bitbucket.org", "bitbucket.io"]:
|
||||
return []
|
||||
|
||||
_, owner, repo, *_ = url.path.split("/")
|
||||
# paging controlled by pagelen parameter, by default it is 10
|
||||
tags_url = f"https://{url.netloc}/!api/2.0/repositories/{owner}/{repo}/refs/tags?sort=-target.date"
|
||||
resp = urlopen(tags_url)
|
||||
tags = json.loads(resp.read())["values"]
|
||||
return [Version(tag["name"]) for tag in tags]
|
||||
|
||||
|
||||
def fetch_bitbucket_snapshots(url: ParseResult, branch: str) -> list[Version]:
|
||||
if url.netloc not in ["bitbucket.org", "bitbucket.io"]:
|
||||
return []
|
||||
|
||||
_, owner, repo, *_ = url.path.split("/")
|
||||
# seems to ignore pagelen parameter (always returns one entry)
|
||||
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"]
|
||||
date = ref["date"][:10] # to YYYY-MM-DD
|
||||
return [Version(f"unstable-{date}", rev=ref["hash"])]
|
Loading…
Reference in New Issue
Block a user