Skip to content

Commit

Permalink
feat: add support for other vcs systems (#128)
Browse files Browse the repository at this point in the history
Adds support to other VCS systems as per the specification.
Defaults to `git` for backwards compatibility.
Renames the internally used `.GitURL` to `.RepoURL` for clarity.
  • Loading branch information
hacdias authored Nov 7, 2023
1 parent 35e7777 commit 550450a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
14 changes: 14 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ type PackageConfig struct {
// Defaults to the URL specified in the top-level config.
URL string `yaml:"url"`

// VCS is the version control system of this module.
//
// Defaults to git.
VCS string `yaml:"vcs"`

// Desc is a plain text description of this module.
Desc string `yaml:"description"`
}
Expand Down Expand Up @@ -73,5 +78,14 @@ func Parse(path string) (*Config, error) {
c.Godoc.Host = host
}

// Set default values for the packages.
for name, pkg := range c.Packages {
if pkg.VCS == "" {
pkg.VCS = "git"
}

c.Packages[name] = pkg
}

return &c, err
}
6 changes: 3 additions & 3 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ packages:
grpc:
repo: github.com/grpc/grpc-go
branch: main
vcs: svn
`)
defer clean()
Expand All @@ -28,8 +29,7 @@ packages:

pkg, ok := config.Packages["grpc"]
assert.True(t, ok)

assert.Equal(t, pkg, PackageConfig{Repo: "github.com/grpc/grpc-go"})
assert.Equal(t, PackageConfig{Repo: "github.com/grpc/grpc-go", VCS: "svn"}, pkg)
}

func TestParsePackageLevelURL(t *testing.T) {
Expand Down Expand Up @@ -83,7 +83,7 @@ packages:

pkg, ok := config.Packages["grpc"]
assert.True(t, ok)
assert.Equal(t, PackageConfig{Repo: "github.com/grpc/grpc-go"}, pkg)
assert.Equal(t, PackageConfig{Repo: "github.com/grpc/grpc-go", VCS: "git"}, pkg)
})
}
}
16 changes: 11 additions & 5 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ func CreateHandler(config *Config) http.Handler {
Desc: pkg.Desc,
ModulePath: modulePath,
DocURL: docURL,
GitURL: pkg.Repo,
VCS: pkg.VCS,
RepoURL: pkg.Repo,
}
pkgs = append(pkgs, pkg)

Expand Down Expand Up @@ -90,8 +91,11 @@ type sallyPackage struct {
// URL at which documentation for the package can be found.
DocURL string

// URL at which the Git repository is hosted.
GitURL string
// Version control system used by the package.
VCS string

// URL at which the repository is hosted.
RepoURL string
}

type indexHandler struct {
Expand Down Expand Up @@ -169,11 +173,13 @@ func (h *packageHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

err := packageTemplate.Execute(w, struct {
ModulePath string
GitURL string
VCS string
RepoURL string
DocURL string
}{
ModulePath: h.Pkg.ModulePath,
GitURL: h.Pkg.GitURL,
VCS: h.Pkg.VCS,
RepoURL: h.Pkg.RepoURL,
DocURL: h.Pkg.DocURL + relPath,
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</div>
<div class="five columns">
<span class="inline-header">Source:</span>
<a href="//{{ .GitURL }}">{{ .GitURL }}</a>
<a href="//{{ .RepoURL }}">{{ .RepoURL }}</a>
</div>
<div class="two columns">
<a href="{{ .DocURL }}">
Expand Down
2 changes: 1 addition & 1 deletion templates/package.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta name="go-import" content="{{ .ModulePath }} git https://{{ .GitURL }}">
<meta name="go-import" content="{{ .ModulePath }} {{ .VCS }} https://{{ .RepoURL }}">
<meta http-equiv="refresh" content="0; url={{ .DocURL }}">
</head>
<body>
Expand Down

0 comments on commit 550450a

Please sign in to comment.