diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2025-02-06 23:47:51 +0100 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2025-02-06 23:47:51 +0100 |
commit | 30d722da053fb4007b897cb201418b4fed544ace (patch) | |
tree | 264bb54efdf7d5d42736436772c4f21951ac19d8 | |
parent | e8265117372cf262ce7cb4f6ce3b61f19373aee6 (diff) | |
download | cerrado-0.0.20.tar.gz cerrado-0.0.20.tar.bz2 cerrado-0.0.20.zip |
feat: Add option for remove ".git" suffixv0.0.20
-rw-r--r-- | config.example.scfg | 5 | ||||
-rw-r--r-- | pkg/config/config.go | 40 | ||||
-rw-r--r-- | pkg/config/config_test.go | 4 |
3 files changed, 39 insertions, 10 deletions
diff --git a/config.example.scfg b/config.example.scfg index 3ba8959..2ed13cd 100644 --- a/config.example.scfg +++ b/config.example.scfg @@ -16,8 +16,13 @@ aes-key 8XHptZxSWCGs1m7QzztX5zNQ7D9NiQevVX0DaUTNMbDpRwFzoJiB0U7K6O/kqIt01jJVgzBU # alphabetical-desc # lastcommit-asc # lastcommit-desc +# default: unordered order-by lastcommit-asc +# removes ".git" suffix from the name of the repository. +# default: false +remove-suffix true + # repository section is order dependent where the first repository has priority # in case of conflict. Repository has also priority over scan. The order # between scan and repository is irrelevant which means that all repository diff --git a/pkg/config/config.go b/pkg/config/config.go index 60a3444..9dbf449 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -9,6 +9,7 @@ import ( "path" "path/filepath" "strconv" + "strings" "git.gabrielgio.me/cerrado/pkg/u" "git.sr.ht/~emersion/go-scfg" @@ -41,14 +42,15 @@ type ( // configuration represents file configuration. // fields needs to be exported to cmp to work configuration struct { - Scans []*scan - RootReadme string - ListenAddr string - Passphrase string - SyntaxHighlight string AESKey string + ListenAddr string OrderBy string + Passphrase string + RemoveSuffix bool Repositories []*GitRepositoryConfiguration + RootReadme string + Scans []*scan + SyntaxHighlight string } // This is a per repository configuration. @@ -65,13 +67,14 @@ type ( // This holds all the function necessary to ask for configuration // information. ConfigurationRepository struct { - rootReadme string - listenAddr string - passphrase []byte aesKey []byte - syntaxHighlight string + listenAddr string orderBy OrderBy + passphrase []byte + removeSuffix bool repositories []*GitRepositoryConfiguration + rootReadme string + syntaxHighlight string } ) @@ -93,6 +96,7 @@ func LoadConfigurationRepository(configPath string) (*ConfigurationRepository, e repositories: config.Repositories, rootReadme: config.RootReadme, syntaxHighlight: config.SyntaxHighlight, + removeSuffix: config.RemoveSuffix, orderBy: parseOrderBy(config.OrderBy), } @@ -172,8 +176,14 @@ func (c *ConfigurationRepository) expandOnScanPath(scanPath string, public bool) fullPath := path.Join(scanPath, e.Name()) if !c.repoExits(fullPath) { + + name := e.Name() + if c.removeSuffix { + name = strings.TrimSuffix(name, ".git") + } + c.repositories = append(c.repositories, &GitRepositoryConfiguration{ - Name: e.Name(), + Name: name, Path: fullPath, Public: public, }) @@ -234,6 +244,11 @@ func parse(r io.Reader) (*configuration, error) { return nil, err } + err = setRemoveSuffix(block, &config.RemoveSuffix) + if err != nil { + return nil, err + } + err = setRepositories(block, &config.Repositories) if err != nil { return nil, err @@ -349,6 +364,11 @@ func setListenAddr(block scfg.Block, listenAddr *string) error { return setString(scanDir, listenAddr) } +func setRemoveSuffix(block scfg.Block, remove *bool) error { + scanDir := block.Get("remove-suffix") + return setBool(scanDir, remove) +} + func setScan(block scfg.Block, scans *[]*scan) error { for _, scanDir := range block.GetAll("scan") { s := &scan{} diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index cc58ce9..949238e 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -110,6 +110,8 @@ listen-addr unix://var/run/cerrado/cerrado.sock passphrase $2a$14$VnB/ZcB1DUDkMnosRA6Y7.dj8h5eroslDxTeXlLwfQX/x86mh6WAq aes-key 8XHptZxSWCGs1m7QzztX5zNQ7D9NiQevVX0DaUTNMbDpRwFzoJiB0U7K6O/kqIt01jJVgzBUfiR8ES46ZLLb4w== syntax-highlight monokailight +order-by lastcommit-desc +remove-suffix true scan "/srv/git" { public true @@ -134,6 +136,8 @@ repository /srv/git/cerrado.git { Passphrase: "$2a$14$VnB/ZcB1DUDkMnosRA6Y7.dj8h5eroslDxTeXlLwfQX/x86mh6WAq", AESKey: "8XHptZxSWCGs1m7QzztX5zNQ7D9NiQevVX0DaUTNMbDpRwFzoJiB0U7K6O/kqIt01jJVgzBUfiR8ES46ZLLb4w==", SyntaxHighlight: "monokailight", + OrderBy: "lastcommit-desc", + RemoveSuffix: true, Repositories: []*GitRepositoryConfiguration{ { Name: "linux.git", |