diff options
| author | Danilo M. <danix@danix.xyz> | 2026-07-09 10:24:44 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-07-09 10:24:44 +0200 |
| commit | f2eba98dddee1e0da6acd46c8fbb1ee79fca6b70 (patch) | |
| tree | de903a31bdc8eba0397b58c352203b73cd645881 | |
| parent | e48715a01c6e63e50fda231ecc0c3b2d1213e421 (diff) | |
| download | mkhintfile-f2eba98dddee1e0da6acd46c8fbb1ee79fca6b70.tar.gz mkhintfile-f2eba98dddee1e0da6acd46c8fbb1ee79fca6b70.zip | |
feat: _detect_nvchecker_source maps forge+registry hosts
| -rwxr-xr-x | mkhint | 65 | ||||
| -rwxr-xr-x | tests/mkhint_test.sh | 41 |
2 files changed, 106 insertions, 0 deletions
@@ -843,6 +843,71 @@ _registry_name_from_url() { printf '%s' "$fallback" } +# Detect an nvchecker source from a package's DOWNLOAD/HOMEPAGE haystack. +# Args: <haystack> <prgnam>. Prints the TOML body (no [label] header). Empty +# output means "unrecognised", the caller emits the commented stub. +_detect_nvchecker_source() { + local haystack="$1" pkg="$2" + + # ── owner/repo forges ───────────────────────────────────────────────── + if [[ "$haystack" =~ (github\.com|gitlab\.com|bitbucket\.org|gitea\.com|codeberg\.org|pagure\.io)/([A-Za-z0-9._-]+)(/([A-Za-z0-9._-]+))? ]]; then + local host="${BASH_REMATCH[1]}" + local owner="${BASH_REMATCH[2]}" + local repo="${BASH_REMATCH[4]}" + repo="${repo%.git}"; owner="${owner%.git}" + case "$host" in + github.com) + printf 'source = "github"\ngithub = "%s/%s"\nuse_latest_release = true\n# use_max_tag = true # if the repo publishes no Releases\n# prefix = "v" # uncomment if tags are v-prefixed\n' "$owner" "$repo" + return 0 ;; + gitlab.com) + printf 'source = "gitlab"\ngitlab = "%s/%s"\nuse_max_tag = true\n# prefix = "v" # uncomment if tags are v-prefixed\n' "$owner" "$repo" + return 0 ;; + bitbucket.org) + printf 'source = "bitbucket"\nbitbucket = "%s/%s"\nuse_max_tag = true\n# prefix = "v" # uncomment if tags are v-prefixed\n' "$owner" "$repo" + return 0 ;; + gitea.com) + printf 'source = "gitea"\ngitea = "%s/%s"\nuse_max_tag = true\n# prefix = "v" # uncomment if tags are v-prefixed\n' "$owner" "$repo" + return 0 ;; + codeberg.org) + printf 'source = "gitea"\ngitea = "%s/%s"\nhost = "codeberg.org"\nuse_max_tag = true\n# prefix = "v" # uncomment if tags are v-prefixed\n' "$owner" "$repo" + return 0 ;; + pagure.io) + # pagure field is the repo only, on pagure.io the first path + # segment IS the repo (no owner), so it lands in $owner. + printf 'source = "pagure"\npagure = "%s"\nuse_max_tag = true\n# prefix = "v" # uncomment if tags are v-prefixed\n' "$owner" + return 0 ;; + esac + fi + + # ── language registries ─────────────────────────────────────────────── + local url; url=$(printf '%s' "$haystack" | grep -oE 'https?://[^ ]+' | head -1) + local name + case "$haystack" in + *pypi.org*|*files.pythonhosted.org*) + printf 'source = "pypi"\npypi = "%s"\n' "$pkg"; return 0 ;; + *registry.npmjs.org*|*npmjs.com*) + name=$(_registry_name_from_url "$url" "$pkg") + printf 'source = "npm"\nnpm = "%s"\n' "$name"; return 0 ;; + *rubygems.org*) + name=$(_registry_name_from_url "$url" "$pkg") + printf 'source = "gems"\ngems = "%s"\n' "$name"; return 0 ;; + *crates.io*) + name=$(_registry_name_from_url "$url" "$pkg") + printf 'source = "cratesio"\ncratesio = "%s"\n' "$name"; return 0 ;; + *metacpan.org*|*cpan.org*) + printf 'source = "cpan"\ncpan = "%s"\n' "$pkg"; return 0 ;; + *hackage.haskell.org*) + name=$(_registry_name_from_url "$url" "$pkg") + printf 'source = "hackage"\nhackage = "%s"\n' "$name"; return 0 ;; + *packagist.org*) + printf 'source = "packagist"\npackagist = "%s"\n' "$pkg"; return 0 ;; + *cran.r-project.org*) + printf 'source = "cran"\ncran = "%s"\n' "$pkg"; return 0 ;; + esac + + return 0 # empty output → caller stubs +} + # Append an nvchecker [pkg] section to NVCHECKER_CONFIG, auto-detecting the # source from the package's .info DOWNLOAD/HOMEPAGE. No-op if section exists. add_nvchecker_section() { diff --git a/tests/mkhint_test.sh b/tests/mkhint_test.sh index e000820..075f542 100755 --- a/tests/mkhint_test.sh +++ b/tests/mkhint_test.sh @@ -1974,6 +1974,47 @@ assert_contains "gems name parsed" "$nv_out" '^gems rails$' assert_contains "npm name parsed" "$nv_out" '^npm left-pad$' assert_contains "fallback to PRGNAM" "$nv_out" '^fallback mypkg$' +# ── T-NV2: _detect_nvchecker_source per host ────────────────────────────────── +echo "" +echo "T-NV2: _detect_nvchecker_source emits correct body per host" +d_out="$MOCK_BASE/nv_detect.txt" +: > "$d_out" +echo "### github" >> "$d_out" +_detect_nvchecker_source "DOWNLOAD=https://github.com/o/r/archive/v1.tar.gz" r >> "$d_out" +echo "### gitlab" >> "$d_out" +_detect_nvchecker_source "DOWNLOAD=https://gitlab.com/o/r/-/archive/1/r-1.tar.gz" r >> "$d_out" +echo "### bitbucket" >> "$d_out" +_detect_nvchecker_source "DOWNLOAD=https://bitbucket.org/o/r/get/1.tar.gz" r >> "$d_out" +echo "### gitea" >> "$d_out" +_detect_nvchecker_source "DOWNLOAD=https://gitea.com/o/r/archive/1.tar.gz" r >> "$d_out" +echo "### codeberg" >> "$d_out" +_detect_nvchecker_source "DOWNLOAD=https://codeberg.org/o/r/archive/1.tar.gz" r >> "$d_out" +echo "### pagure" >> "$d_out" +_detect_nvchecker_source "DOWNLOAD=https://pagure.io/r/archive/1/r-1.tar.gz" r >> "$d_out" +echo "### npm" >> "$d_out" +_detect_nvchecker_source "DOWNLOAD=https://registry.npmjs.org/lp/-/lp-1.tgz" lp >> "$d_out" +echo "### cran" >> "$d_out" +_detect_nvchecker_source "DOWNLOAD=https://cran.r-project.org/src/contrib/foo_1.tar.gz" foo >> "$d_out" +echo "### unknown" >> "$d_out" +_detect_nvchecker_source "DOWNLOAD=https://example.com/x.tar.gz" x >> "$d_out" +echo "### end" >> "$d_out" + +assert_contains "github source" "$d_out" 'source = "github"' +assert_contains "github latest_release" "$d_out" 'use_latest_release = true' +assert_contains "github max_tag comment" "$d_out" '# use_max_tag = true' +assert_contains "github prefix comment" "$d_out" '# prefix = "v"' +assert_contains "gitlab source" "$d_out" 'source = "gitlab"' +assert_contains "gitlab field" "$d_out" 'gitlab = "o/r"' +assert_contains "bitbucket field" "$d_out" 'bitbucket = "o/r"' +assert_contains "gitea field" "$d_out" 'gitea = "o/r"' +assert_contains "codeberg host" "$d_out" 'host = "codeberg.org"' +assert_contains "pagure field" "$d_out" 'pagure = "r"' +assert_contains "npm field" "$d_out" 'npm = "lp"' +assert_contains "cran field" "$d_out" 'cran = "foo"' +# unknown host → empty body between ### unknown and ### end +unk=$(awk '/^### unknown/{f=1;next} /^### end/{f=0} f' "$d_out") +assert_exit_code "unknown host empty body" 0 "$( [[ -z "${unk//[[:space:]]/}" ]]; echo $? )" + # ─── SUMMARY ────────────────────────────────────────────────────────────────── teardown |
