about summary refs log tree commit diff stats
path: root/internal
diff options
context:
space:
mode:
authorAlan Pearce2024-05-20 23:31:29 +0200
committerAlan Pearce2024-05-20 23:31:29 +0200
commit8e8c5c9cc35ef9b3de9b8d43919f27a39a1d75d3 (patch)
tree33cc9205737c833488991500ae850f97829658fb /internal
parent4ac6e917aafa02825bef4f213b2c41fd902a4baf (diff)
downloadsearchix-8e8c5c9cc35ef9b3de9b8d43919f27a39a1d75d3.tar.lz
searchix-8e8c5c9cc35ef9b3de9b8d43919f27a39a1d75d3.tar.zst
searchix-8e8c5c9cc35ef9b3de9b8d43919f27a39a1d75d3.zip
refactor: make repository URLs by Repo.Type (currently no change)
"currently no change" because only GitHub repos are supported, but
more ready to support other types
Diffstat (limited to 'internal')
-rw-r--r--internal/importer/package.go6
-rw-r--r--internal/importer/utils.go35
2 files changed, 29 insertions, 12 deletions
diff --git a/internal/importer/package.go b/internal/importer/package.go
index 5e9ad26..3fee8d7 100644
--- a/internal/importer/package.go
+++ b/internal/importer/package.go
@@ -225,6 +225,10 @@ func (i *PackageIngester) Process(parent context.Context) (<-chan nix.Importable
 				pkgSet = ""
 			}
 
+			url, err := makeRepoURL(i.source.Repo, subpath, line)
+			if err != nil {
+				errs <- err
+			}
 			results <- &nix.Package{
 				Name:            i.pkg.Name,
 				Attribute:       kv.Key,
@@ -239,7 +243,7 @@ func (i *PackageIngester) Process(parent context.Context) (<-chan nix.Importable
 				Platforms:       i.pkg.Meta.Platforms,
 				Licenses:        licenses,
 				Maintainers:     maintainers,
-				Definition:      makeRepoURL(i.source.Repo, subpath, line),
+				Definition:      url,
 			}
 		}
 	}()
diff --git a/internal/importer/utils.go b/internal/importer/utils.go
index 3977c2e..425b7bd 100644
--- a/internal/importer/utils.go
+++ b/internal/importer/utils.go
@@ -36,23 +36,36 @@ func ValueTypeToString(valueType jstream.ValueType) string {
 	return "very strange"
 }
 
-func makeRepoURL(repo config.Repository, subPath string, line string) string {
-	ref := repo.Revision
-	if ref == "" {
-		ref = "master"
-	}
-	url, _ := url.JoinPath("https://github.com/", repo.Owner, repo.Repo, "blob", ref, subPath)
-	if line != "" {
-		url = url + "#L" + line
-	}
+func makeRepoURL(repo config.Repository, subPath string, line string) (string, error) {
+	switch repo.Type {
+	case config.GitHub:
+		ref := repo.Revision
+		if ref == "" {
+			ref = "master"
+		}
+		url, _ := url.JoinPath("https://github.com/", repo.Owner, repo.Repo, "blob", ref, subPath)
+		if line != "" {
+			url = url + "#L" + line
+		}
 
-	return url
+		return url, nil
+	default:
+		return "", errors.Errorf(
+			"don't know how to generate a repository URL for %s",
+			repo.Type.String(),
+		)
+	}
 }
 
 func MakeChannelLink(repo config.Repository, subPath string) (*nix.Link, error) {
+	url, err := makeRepoURL(repo, subPath, "")
+	if err != nil {
+		return nil, err
+	}
+
 	return &nix.Link{
 		Name: fmt.Sprintf("<%s/%s>", repo.Repo, subPath),
-		URL:  makeRepoURL(repo, subPath, ""),
+		URL:  url,
 	}, nil
 }