From e948a7f7973a9cda5d1eaa89d5e223504b0ca57e Mon Sep 17 00:00:00 2001 From: emilylange Date: Sat, 20 Apr 2024 17:38:26 +0200 Subject: [PATCH 1/3] remove broken Gogs/notabug.com support Gogs isn't Gitea. The API surface of Gogs is different from Gitea's. Additionally, notabug.com uses a multiple years old version of Gogs, which has neither `/tags` nor `/commits` implemented. The implementation we use in `version/gitea.py` simple does not work. You can check this yourself by running `nix-update libgtkflow4`, one of the few packages in nixpkgs that are hosted on notabug.com --- README.md | 1 - nix_update/update.py | 2 +- nix_update/version/__init__.py | 2 +- nix_update/version/gitea.py | 4 ++-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c98d660..3572101 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ designed to work with nixpkgs but also other package sets. - Gitea - GitHub - GitLab - - NotABug.org - PyPi - RubyGems.org - Sourcehut diff --git a/nix_update/update.py b/nix_update/update.py index 901cd42..35a870c 100644 --- a/nix_update/update.py +++ b/nix_update/update.py @@ -323,7 +323,7 @@ def update_version( elif package.parsed_url.netloc == "github.com": _, owner, repo, *_ = package.parsed_url.path.split("/") package.diff_url = f"https://github.com/{owner}/{repo.removesuffix('.git')}/compare/{package.rev}...{new_version.rev or new_version.number}" - elif package.parsed_url.netloc in ["codeberg.org", "gitea.com", "notabug.org"]: + elif package.parsed_url.netloc in ["codeberg.org", "gitea.com"]: _, owner, repo, *_ = package.parsed_url.path.split("/") 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: diff --git a/nix_update/version/__init__.py b/nix_update/version/__init__.py index 401c077..995fa5a 100644 --- a/nix_update/version/__init__.py +++ b/nix_update/version/__init__.py @@ -133,5 +133,5 @@ def fetch_latest_version( ) raise VersionError( - "Please specify the version. We can only get the latest version from codeberg/crates.io/gitea/github/gitlab/notabug/pypi/savannah/sourcehut/rubygems projects right now" + "Please specify the version. We can only get the latest version from codeberg/crates.io/gitea/github/gitlab/pypi/savannah/sourcehut/rubygems projects right now" ) diff --git a/nix_update/version/gitea.py b/nix_update/version/gitea.py index 25d068e..2fd5e5a 100644 --- a/nix_update/version/gitea.py +++ b/nix_update/version/gitea.py @@ -6,7 +6,7 @@ def fetch_gitea_versions(url: ParseResult) -> list[Version]: - if url.netloc not in ["codeberg.org", "gitea.com", "notabug.org"]: + if url.netloc not in ["codeberg.org", "gitea.com"]: return [] _, owner, repo, *_ = url.path.split("/") @@ -17,7 +17,7 @@ def fetch_gitea_versions(url: ParseResult) -> list[Version]: def fetch_gitea_snapshots(url: ParseResult, branch: str) -> list[Version]: - if url.netloc not in ["codeberg.org", "gitea.com", "notabug.org"]: + if url.netloc not in ["codeberg.org", "gitea.com"]: return [] _, owner, repo, *_ = url.path.split("/") From b03e9dc75a654f2d46a1f48b70ce7232324ff81a Mon Sep 17 00:00:00 2001 From: emilylange Date: Sat, 20 Apr 2024 18:07:36 +0200 Subject: [PATCH 2/3] fetch_gitea_snapshots: fix typo and make less expensive --- nix_update/version/gitea.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix_update/version/gitea.py b/nix_update/version/gitea.py index 2fd5e5a..f4dc63a 100644 --- a/nix_update/version/gitea.py +++ b/nix_update/version/gitea.py @@ -21,7 +21,7 @@ def fetch_gitea_snapshots(url: ParseResult, branch: str) -> list[Version]: return [] _, owner, repo, *_ = url.path.split("/") - commits_url = f"https://{url.netloc}/api/v1/repos/{owner}/{repo}/commits?sha={branch}&limit=1stat=false" + commits_url = f"https://{url.netloc}/api/v1/repos/{owner}/{repo}/commits?sha={branch}&limit=1&stat=false&verification=false&files=false" resp = urlopen(commits_url) commits = json.loads(resp.read()) From fb5c71b42223f9acf7b15c9a2af00a6ff3fc5615 Mon Sep 17 00:00:00 2001 From: emilylange Date: Sat, 20 Apr 2024 21:43:27 +0200 Subject: [PATCH 3/3] gitea: fix handling when `fetchFromGitea` falls back to `fetchgit` `fetchFromGitea` just re-uses `fetchFromGitHub`. The only difference is making `domain` a required attribute instead of defaulting to `"github.com"`. As such, it falls back to `fetchgit`, such like `fetchFromGitHub`, if any of the following is true: - fetchSubmodules - leaveDotGit - deepClose - sparseCheckout != [] - forceFetchGit When falling back to `fetchgit`, the `src.url` will end with `".git"`, which we then need to strip again from our parsed `repo` variable. `fetchFromGitHub` has the same logic to trim `".git"` unconditionally. --- nix_update/version/gitea.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nix_update/version/gitea.py b/nix_update/version/gitea.py index f4dc63a..f1eac0f 100644 --- a/nix_update/version/gitea.py +++ b/nix_update/version/gitea.py @@ -1,4 +1,5 @@ import json +import re from urllib.parse import ParseResult from urllib.request import urlopen @@ -10,6 +11,7 @@ def fetch_gitea_versions(url: ParseResult) -> list[Version]: return [] _, owner, repo, *_ = url.path.split("/") + repo = re.sub(r"\.git$", "", repo) tags_url = f"https://{url.netloc}/api/v1/repos/{owner}/{repo}/tags" resp = urlopen(tags_url) tags = json.loads(resp.read()) @@ -21,6 +23,7 @@ def fetch_gitea_snapshots(url: ParseResult, branch: str) -> list[Version]: return [] _, owner, repo, *_ = url.path.split("/") + repo = re.sub(r"\.git$", "", repo) commits_url = f"https://{url.netloc}/api/v1/repos/{owner}/{repo}/commits?sha={branch}&limit=1&stat=false&verification=false&files=false" resp = urlopen(commits_url) commits = json.loads(resp.read())