Skip to content

Commit

Permalink
internal/source: handle blitiri.com.ar import paths
Browse files Browse the repository at this point in the history
The source for these import paths is served by the git-arr web
viewer, which doesn't yet handle tags. Until it does, serve
the source from master.

For golang/go#44607

Change-Id: I94047a887ea6f1038ae812864ad343876b74ff8e
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/303609
Trust: Jonathan Amsterdam <[email protected]>
Run-TryBot: Jonathan Amsterdam <[email protected]>
TryBot-Result: kokoro <[email protected]>
Reviewed-by: Jamal Carvalho <[email protected]>
  • Loading branch information
jba committed Mar 22, 2021
1 parent 8be65e0 commit 7d0f1a1
Show file tree
Hide file tree
Showing 3 changed files with 1,597 additions and 1,472 deletions.
16 changes: 15 additions & 1 deletion internal/source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (i *Info) FileURL(pathname string) string {
"repo": i.repoURL,
"importPath": path.Join(strings.TrimPrefix(i.repoURL, "https://"), dir),
"commit": i.commit,
"dir": dir,
"file": path.Join(i.moduleDir, pathname),
"base": base,
})
Expand All @@ -107,6 +108,7 @@ func (i *Info) LineURL(pathname string, line int) string {
"importPath": path.Join(strings.TrimPrefix(i.repoURL, "https://"), dir),
"commit": i.commit,
"file": path.Join(i.moduleDir, pathname),
"dir": dir,
"base": base,
"line": strconv.Itoa(line),
})
Expand Down Expand Up @@ -356,6 +358,10 @@ func matchStatic(moduleOrRepoPath string) (repo, relativeModulePath string, _ ur
if strings.HasPrefix(repo, apacheDomain) {
repo = strings.Replace(repo, apacheDomain, "github.com/apache/", 1)
}
// Special case: module paths are blitiri.com.ar/go/..., but repos are blitiri.com.ar/git/r/...
if strings.HasPrefix(repo, "blitiri.com.ar/") {
repo = strings.Replace(repo, "/go/", "/git/r/", 1)
}
relativeModulePath = strings.TrimPrefix(moduleOrRepoPath, matches[0])
relativeModulePath = strings.TrimPrefix(relativeModulePath, "/")
return repo, relativeModulePath, pat.templates, pat.transformCommit, nil
Expand Down Expand Up @@ -612,7 +618,6 @@ var patterns = []struct {
// URLs anyway. See gogs/gogs#6242.
templates: giteaURLTemplates,
},

{
pattern: `^(?P<repo>dmitri\.shuralyov\.com\/.+)$`,
templates: urlTemplates{
Expand All @@ -622,6 +627,15 @@ var patterns = []struct {
Line: "https://gotools.org/{importPath}?rev={commit}#{base}-L{line}",
},
},
{
pattern: `^(?P<repo>blitiri\.com\.ar/go/.+)$`,
templates: urlTemplates{
Repo: "{repo}",
Directory: "{repo}/b/master/t/{dir}",
File: "{repo}/b/master/t/{dir}f={file}.html",
Line: "{repo}/b/master/t/{dir}f={file}.html#line-{line}",
},
},

// Patterns that match the general go command pattern, where they must have
// a ".git" repo suffix in an import path. If matching a repo URL from a meta tag,
Expand Down
12 changes: 12 additions & 0 deletions internal/source/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,15 @@ func TestModuleInfo(t *testing.T) {
"https://git.zx2c4.com/wireguard-windows/tree/go.mod?h=v0.3.4#n1",
"https://git.zx2c4.com/wireguard-windows/plain/go.mod?h=v0.3.4",
},
{
"go-source templates match blitiri.com.ar",
"blitiri.com.ar/go/log", "v1.1.0", "go.mod",
"https://blitiri.com.ar/git/r/log",
"https://blitiri.com.ar/git/r/log/b/master/t",
"https://blitiri.com.ar/git/r/log/b/master/t/f=go.mod.html",
"https://blitiri.com.ar/git/r/log/b/master/t/f=go.mod.html#line-1",
"",
},
} {
t.Run(test.desc, func(t *testing.T) {
info, err := ModuleInfo(context.Background(), &Client{client}, test.modulePath, test.version)
Expand Down Expand Up @@ -945,6 +954,9 @@ func TestURLTemplates(t *testing.T) {
// Check that templates contain the right variables.

for _, p := range patterns {
if strings.Contains(p.pattern, "blitiri") {
continue
}
check := func(tmpl string, vars ...string) {
if tmpl == "" {
return
Expand Down
Loading

0 comments on commit 7d0f1a1

Please sign in to comment.