about summary refs log tree commit diff stats
path: root/internal
diff options
context:
space:
mode:
authorAlan Pearce2024-05-20 23:14:40 +0200
committerAlan Pearce2024-05-20 23:15:54 +0200
commite70431d68dced8754e94228753359b2130fd075a (patch)
treeebed321c0447c0f96214065f2800d2eebb208f7c /internal
parent319b79cd7d72c6a49137ef50fa06e807e7a89c2b (diff)
downloadsearchix-e70431d68dced8754e94228753359b2130fd075a.tar.lz
searchix-e70431d68dced8754e94228753359b2130fd075a.tar.zst
searchix-e70431d68dced8754e94228753359b2130fd075a.zip
refactor: make declaration/definition URLs from Source.Repo
Diffstat (limited to 'internal')
-rw-r--r--internal/importer/options.go2
-rw-r--r--internal/importer/package.go3
-rw-r--r--internal/importer/utils.go22
3 files changed, 8 insertions, 19 deletions
diff --git a/internal/importer/options.go b/internal/importer/options.go
index 8ce684c..4089f62 100644
--- a/internal/importer/options.go
+++ b/internal/importer/options.go
@@ -124,7 +124,7 @@ func (i *OptionIngester) Process(parent context.Context) (<-chan nix.Importable,
 				switch decl := reflect.ValueOf(decl); decl.Kind() {
 				case reflect.String:
 					s := decl.String()
-					link, err := MakeChannelLink(i.source.Channel, i.source.Repo.Revision, s)
+					link, err := MakeChannelLink(i.source.Repo, s)
 					if err != nil {
 						errs <- errors.WithMessagef(err,
 							"could not make a channel link for channel %s, revision %s and subpath %s",
diff --git a/internal/importer/package.go b/internal/importer/package.go
index dbc5854..5e9ad26 100644
--- a/internal/importer/package.go
+++ b/internal/importer/package.go
@@ -115,7 +115,6 @@ func (i *PackageIngester) Process(parent context.Context) (<-chan nix.Importable
 		defer close(errs)
 		defer cancel()
 
-		userRepo := i.source.Repo.Owner + "/" + i.source.Repo.Repo
 	outer:
 		for mv := range i.dec.Stream() {
 			var err error
@@ -240,7 +239,7 @@ func (i *PackageIngester) Process(parent context.Context) (<-chan nix.Importable
 				Platforms:       i.pkg.Meta.Platforms,
 				Licenses:        licenses,
 				Maintainers:     maintainers,
-				Definition:      makeGitHubFileURL(userRepo, "", subpath, line),
+				Definition:      makeRepoURL(i.source.Repo, subpath, line),
 			}
 		}
 	}()
diff --git a/internal/importer/utils.go b/internal/importer/utils.go
index 1c0d3af..3977c2e 100644
--- a/internal/importer/utils.go
+++ b/internal/importer/utils.go
@@ -36,11 +36,12 @@ func ValueTypeToString(valueType jstream.ValueType) string {
 	return "very strange"
 }
 
-func makeGitHubFileURL(userRepo string, ref string, subPath string, line string) string {
+func makeRepoURL(repo config.Repository, subPath string, line string) string {
+	ref := repo.Revision
 	if ref == "" {
 		ref = "master"
 	}
-	url, _ := url.JoinPath("https://github.com/", userRepo, "blob", ref, subPath)
+	url, _ := url.JoinPath("https://github.com/", repo.Owner, repo.Repo, "blob", ref, subPath)
 	if line != "" {
 		url = url + "#L" + line
 	}
@@ -48,21 +49,10 @@ func makeGitHubFileURL(userRepo string, ref string, subPath string, line string)
 	return url
 }
 
-// make configurable?
-var channelRepoMap = map[string]string{
-	"nixpkgs":      "NixOS/nixpkgs",
-	"nix-darwin":   "LnL7/nix-darwin",
-	"home-manager": "nix-community/home-manager",
-}
-
-func MakeChannelLink(channel string, ref string, subPath string) (*nix.Link, error) {
-	if channelRepoMap[channel] == "" {
-		return nil, fmt.Errorf("don't know what repository relates to channel <%s>", channel)
-	}
-
+func MakeChannelLink(repo config.Repository, subPath string) (*nix.Link, error) {
 	return &nix.Link{
-		Name: fmt.Sprintf("<%s/%s>", channel, subPath),
-		URL:  makeGitHubFileURL(channelRepoMap[channel], ref, subPath, ""),
+		Name: fmt.Sprintf("<%s/%s>", repo.Repo, subPath),
+		URL:  makeRepoURL(repo, subPath, ""),
 	}, nil
 }