From 1d77f3d3fdf5cb650a0e8b0732cbc63ec4da66bd Mon Sep 17 00:00:00 2001 From: moson-mo Date: Fri, 19 May 2023 13:06:30 +0200 Subject: [PATCH] chore: Arch git migration and repo changes * fetch PKGBUILD files from Archlinux Gitlab instead of Github * change list of official repositories https://archlinux.org/news/git-migration-announcement/ Signed-off-by: moson-mo --- internal/pacseek/pkgbuild.go | 23 +++++++++++++++++------ internal/pacseek/ui.go | 4 ++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/internal/pacseek/pkgbuild.go b/internal/pacseek/pkgbuild.go index d859520..dfdf80e 100644 --- a/internal/pacseek/pkgbuild.go +++ b/internal/pacseek/pkgbuild.go @@ -4,11 +4,20 @@ import ( "fmt" "io" "net/http" + "regexp" "strings" "github.com/moson-mo/pacseek/internal/util" ) +// regex replacements for Gitlab URL's +// https://gitlab.archlinux.org/archlinux/devtools/-/blob/b519c8128e59e5431e2854b322e8b3a0088643cc/src/lib/api/gitlab.sh#L87 +var gitlabRepl = map[string]*regexp.Regexp{ + `$1-$2`: regexp.MustCompile(`([a-zA-Z0-9]+)\+([a-zA-Z]+)`), + `plus`: regexp.MustCompile(`\+`), + `-`: regexp.MustCompile(`[^a-zA-Z0-9_\-\.]`), +} + // download the PKGBUILD file func getPkgbuildContent(url string) (string, error) { resp, err := http.Get(url) @@ -28,16 +37,18 @@ func getPkgbuildContent(url string) (string, error) { // composes the URL to a PKGBUILD file func getPkgbuildUrl(source, base string) string { if util.SliceContains(getArchRepos(), source) { - repo := "packages" - if strings.Contains(source, "community") || - source == "multilib" { - repo = "community" - } - return fmt.Sprintf(UrlRepoPkgbuild, repo, base) + return fmt.Sprintf(UrlRepoPkgbuild, encodePackageGitlabUrl(base)) } return fmt.Sprintf(UrlAurPkgbuild, base) } +func encodePackageGitlabUrl(pkgname string) string { + for rep, regex := range gitlabRepl { + pkgname = regex.ReplaceAllString(pkgname, rep) + } + return pkgname +} + // returns command to download and display PKGBUILD func (ps *UI) getPkgbuildCommand(source, base string) string { return strings.Replace(ps.conf.ShowPkgbuildCommand, "{url}", getPkgbuildUrl(source, base), -1) diff --git a/internal/pacseek/ui.go b/internal/pacseek/ui.go index f5e7cf5..4172692 100644 --- a/internal/pacseek/ui.go +++ b/internal/pacseek/ui.go @@ -19,7 +19,7 @@ const ( UrlAurPkgbuild = "https://raw.githubusercontent.com/archlinux/aur/%s/PKGBUILD" UrlPackage = "https://archlinux.org/packages/%s/%s/%s" UrlArmPackage = "https://archlinuxarm.org/packages/%s/%s" - UrlRepoPkgbuild = "https://raw.githubusercontent.com/archlinux/svntogit-%s/packages/%s/trunk/PKGBUILD" + UrlRepoPkgbuild = "https://gitlab.archlinux.org/archlinux/packaging/packages/%s/-/raw/main/PKGBUILD" UrlAurMaintainer = "https://aur.archlinux.org/packages?SeB=m&K=%s" @@ -147,7 +147,7 @@ func (ps *UI) Start() error { // getArchRepos returns a list of Arch Linux repositories func getArchRepos() []string { - return []string{"core", "community", "community-testing", "extra", "kde-unstable", "multilib", "multilib-testing", "testing"} + return []string{"core", "core-testing", "extra", "extra-testing", "multilib", "multilib-testing", "kde-unstable"} } // getArchArmRepos returns a list of Arch Linux ARM repositories