From 5e2060e1f31b99fe0d9407e6ada46454e9bad88c Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Tue, 7 Nov 2023 20:14:46 +0100 Subject: [PATCH] feat: add support for other vcs systems --- config.go | 14 ++++++++++++++ config_test.go | 6 +++--- handler.go | 16 +++++++++++----- templates/index.html | 2 +- templates/package.html | 2 +- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/config.go b/config.go index 439bc48..25b32fd 100644 --- a/config.go +++ b/config.go @@ -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"` } @@ -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 } diff --git a/config_test.go b/config_test.go index 0eb93e2..e7ac247 100644 --- a/config_test.go +++ b/config_test.go @@ -16,6 +16,7 @@ packages: grpc: repo: github.com/grpc/grpc-go branch: main + vcs: svn `) defer clean() @@ -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) { @@ -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) }) } } diff --git a/handler.go b/handler.go index f636359..ccf8d27 100644 --- a/handler.go +++ b/handler.go @@ -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) @@ -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 { @@ -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 { diff --git a/templates/index.html b/templates/index.html index 7ffc1a6..4d1db5d 100644 --- a/templates/index.html +++ b/templates/index.html @@ -33,7 +33,7 @@
Source: - {{ .GitURL }} + {{ .RepoURL }}
diff --git a/templates/package.html b/templates/package.html index bd56c38..6183c51 100644 --- a/templates/package.html +++ b/templates/package.html @@ -1,7 +1,7 @@ - +