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.
This commit is contained in:
emilylange 2024-04-20 21:43:27 +02:00 committed by mergify[bot]
parent b03e9dc75a
commit fb5c71b422

View File

@ -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())