diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..5f104d0 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,9 @@ +kind: pipeline +name: default + +steps: + - name: lint + image: golang:1.12 + commands: + - make lint + - make golangci-lint \ No newline at end of file diff --git a/.golangci b/.golangci new file mode 100644 index 0000000..9b9f213 --- /dev/null +++ b/.golangci @@ -0,0 +1,25 @@ +linters: + enable: + - gosimple + - deadcode + - typecheck + - govet + - errcheck + - staticcheck + - unused + - structcheck + - varcheck + - golint + - dupl + - gofmt + - misspell + - gocritic + enable-all: false + disable-all: true + fast: false + +linters-settings: + gocritic: + disabled-checks: + - ifElseChain + - singleCaseSwitch # Every time this occured in the code, there was no other way. \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..949c567 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +.PHONY: golangci-lint +golangci-lint: + @hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ + curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.16.0; \ + fi + golangci-lint run + +.PHONY: lint +lint: + @hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ + go get -u golang.org/x/lint/golint; \ + fi + golint ./... diff --git a/cmd/run.go b/cmd/run.go index 0b35490..850e079 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -1,11 +1,11 @@ // staletea // Copyright (C) 2019 Jonas Franz -// +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -21,12 +21,13 @@ import ( "github.com/urfave/cli" ) +// CmdRun is the command to start the webserver var CmdRun = cli.Command{ Action: run, - Name: "run", + Name: "run", Flags: []cli.Flag{ cli.StringFlag{ - Name: "address", + Name: "address", Value: ":3030", }, }, @@ -34,4 +35,4 @@ var CmdRun = cli.Command{ func run(ctx *cli.Context) error { return web.StartServer(ctx.String("address")) -} \ No newline at end of file +} diff --git a/config/config.go b/config/config.go index 9149226..adaf32b 100644 --- a/config/config.go +++ b/config/config.go @@ -39,6 +39,7 @@ func (k Key) setDefault(defaultValue interface{}) { viper.SetDefault(string(k), defaultValue) } +// This block contains all config keys const ( DaysUntilStale Key = "daysUntilStale" DaysUntilClose Key = "daysUntilClose" @@ -61,6 +62,7 @@ const ( SessionSecret Key = "session_secret" ) +// SetupConfig fills all default values, reads the config and/or writes the default config. func SetupConfig() error { DaysUntilStale.setDefault(60) DaysUntilClose.setDefault(7) @@ -90,7 +92,9 @@ func SetupConfig() error { viper.AddConfigPath(".") if err := viper.SafeWriteConfigAs("config.yml"); err != nil { if os.IsNotExist(err) { - err = viper.WriteConfigAs("config.yml") + if err := viper.WriteConfigAs("config.yml"); err != nil { + return err + } } } return viper.ReadInConfig() diff --git a/models/repository.go b/models/repository.go index 5432966..77048f9 100644 --- a/models/repository.go +++ b/models/repository.go @@ -16,6 +16,7 @@ package models +// Repository represents a Gitea repository indexed at the local database type Repository struct { ID int64 `xorm:"pk"` Owner string `xorm:"unique(owner_name)"` diff --git a/models/user.go b/models/user.go index cda8882..a815f6f 100644 --- a/models/user.go +++ b/models/user.go @@ -18,6 +18,7 @@ package models import "golang.org/x/oauth2" +// User represents a signed in oauth2 gitea user saved in a session type User struct { ID int64 Username string diff --git a/utils/secret.go b/utils/secret.go index c3837d3..2397d8b 100644 --- a/utils/secret.go +++ b/utils/secret.go @@ -21,6 +21,7 @@ import ( "encoding/base64" ) +// NewSecret will generate a random string of the given length func NewSecret(length int) (string, error) { secret := make([]byte, length) if _, err := rand.Read(secret); err != nil { diff --git a/web/router.go b/web/router.go index c1e7cd2..48b2239 100644 --- a/web/router.go +++ b/web/router.go @@ -23,6 +23,7 @@ import ( "github.com/gin-gonic/gin" ) +// StartServer will start the webserver at the given addresses func StartServer(addr ...string) error { r := gin.Default() store := cookie.NewStore([]byte(config.SessionSecret.Get().(string)))