aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/rosa/rosa.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-04-13 15:23:41 +0900
committerOphestra <cat@gensokyo.uk>2026-04-13 18:02:57 +0900
commit83b0e32c550bf47eea826be7403183bf8f412850 (patch)
treeabfe8a5c2aec066a705ba92405b8366ebcd973b2 /internal/rosa/rosa.go
parenteeaf26e7a24c5c51c64fc333284015224e851e8c (diff)
internal/rosa: helpers for common url formats
This cleans up call site of NewPackage. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/rosa/rosa.go')
-rw-r--r--internal/rosa/rosa.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/internal/rosa/rosa.go b/internal/rosa/rosa.go
index 556ed44b..c70774d2 100644
--- a/internal/rosa/rosa.go
+++ b/internal/rosa/rosa.go
@@ -4,6 +4,7 @@ package rosa
import (
"errors"
"log"
+ "path"
"runtime"
"slices"
"strconv"
@@ -603,3 +604,54 @@ cd '/usr/src/` + name + `/'
})...,
)
}
+
+// newTar wraps [pkg.NewHTTPGetTar] with a simpler function signature.
+func newTar(url, checksum string, compression uint32) pkg.Artifact {
+ return pkg.NewHTTPGetTar(nil, url, mustDecode(checksum), compression)
+}
+
+// newFromCPAN is a helper for downloading release from CPAN.
+func newFromCPAN(author, name, version, checksum string) pkg.Artifact {
+ return newTar(
+ "https://cpan.metacpan.org/authors/id/"+
+ author[:1]+"/"+author[:2]+"/"+author+"/"+
+ name+"-"+version+".tar.gz",
+ checksum,
+ pkg.TarGzip,
+ )
+}
+
+// newFromGitLab is a helper for downloading source from GitLab.
+func newFromGitLab(domain, suffix, ref, checksum string) pkg.Artifact {
+ return newTar(
+ "https://"+domain+"/"+suffix+"/-/archive/"+
+ ref+"/"+path.Base(suffix)+"-"+
+ strings.ReplaceAll(ref, "/", "-")+".tar.bz2",
+ checksum,
+ pkg.TarBzip2,
+ )
+}
+
+// newFromGitHub is a helper for downloading source from Microsoft Github.
+func newFromGitHub(suffix, tag, checksum string) pkg.Artifact {
+ return newTar(
+ "https://github.com/"+suffix+
+ "/archive/refs/tags/"+tag+".tar.gz",
+ checksum,
+ pkg.TarGzip,
+ )
+}
+
+// newFromGitHubRelease is a helper for downloading release tarball from
+// Microsoft Github.
+func newFromGitHubRelease(
+ suffix, tag, name, checksum string,
+ compression uint32,
+) pkg.Artifact {
+ return newTar(
+ "https://github.com/"+suffix+
+ "/releases/download/"+tag+"/"+name,
+ checksum,
+ compression,
+ )
+}