diff options
Diffstat (limited to 'pkg/config')
| -rw-r--r-- | pkg/config/config.go | 40 | ||||
| -rw-r--r-- | pkg/config/config_test.go | 4 | 
2 files changed, 34 insertions, 10 deletions
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",  | 
