Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add a lint step in CI #153

Merged
merged 2 commits into from
Dec 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ jobs:
steps:
- checkout
- run: go get -v -t -d ./...
- run: go test -v ./...
- run: make install
- run: make test
- run: curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.12.2
- run: PATH="$PATH:$(pwd)/bin" make lint
34 changes: 34 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
run:
deadline: 1m
tests: false
#skip-files:
# - ".*\\.gen\\.go"

linters-settings:
golint:
min-confidence: 0
maligned:
suggest-new: true
goconst:
min-len: 5
min-occurrences: 4
misspell:
locale: US

linters:
disable-all: true
enable:
- goconst
- misspell
- deadcode
- misspell
- structcheck
- errcheck
- unused
- varcheck
- staticcheck
- unconvert
- gofmt
- goimports
- golint
- ineffassign
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ install:
test:
go test -v ./...

.PHONY: lint
lint:
golangci-lint run --verbose ./...

.PHONY: update_examples
update_examples:
for dir in $(sort $(dir $(wildcard examples/*/*))); do (cd $$dir && make); done
Expand Down
7 changes: 5 additions & 2 deletions cli/cmd_airtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/spf13/pflag"
"github.com/spf13/viper"
"go.uber.org/zap"

"moul.io/depviz/pkg/airtabledb"
"moul.io/depviz/pkg/issues"
)
Expand Down Expand Up @@ -70,7 +71,9 @@ func (cmd *airtableCommand) ParseFlags(flags *pflag.FlagSet) {
flags.StringVarP(&cmd.opts.Token, "airtable-token", "", "", "Airtable token")
flags.BoolVarP(&cmd.opts.DestroyInvalidRecords, "airtable-destroy-invalid-records", "", false, "Destroy invalid records")

viper.BindPFlags(flags)
if err := viper.BindPFlags(flags); err != nil {
zap.L().Warn("find to bind flags using Viper", zap.Error(err))
}
}

func (cmd *airtableCommand) NewCobraCommand(dc map[string]DepvizCommand) *cobra.Command {
Expand Down Expand Up @@ -118,7 +121,7 @@ func airtableSync(opts *airtableOptions) error {
zap.L().Debug("fetch db entries", zap.Int("count", len(loadedIssues)))

issueFeatures := make([]map[string]issues.Feature, airtabledb.NumTables)
for i, _ := range issueFeatures {
for i := range issueFeatures {
issueFeatures[i] = make(map[string]issues.Feature)
}

Expand Down
6 changes: 5 additions & 1 deletion cli/cmd_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"go.uber.org/zap"

"moul.io/depviz/pkg/issues"
)

Expand Down Expand Up @@ -37,7 +39,9 @@ func (cmd *dbCommand) NewCobraCommand(dc map[string]DepvizCommand) *cobra.Comman
}

func (cmd *dbCommand) ParseFlags(flags *pflag.FlagSet) {
viper.BindPFlags(flags)
if err := viper.BindPFlags(flags); err != nil {
zap.L().Warn("find to bind flags using Viper", zap.Error(err))
}
}

func (cmd *dbCommand) dbDumpCommand() *cobra.Command {
Expand Down
5 changes: 4 additions & 1 deletion cli/cmd_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/spf13/pflag"
"github.com/spf13/viper"
"go.uber.org/zap"

"moul.io/depviz/pkg/issues"
)

Expand Down Expand Up @@ -60,7 +61,9 @@ func (cmd *graphCommand) ParseFlags(flags *pflag.FlagSet) {
flags.StringVarP(&cmd.opts.Output, "output", "o", "-", "output file ('-' for stdout, dot)")
flags.StringVarP(&cmd.opts.Format, "format", "f", "", "output file format (if empty, will determine thanks to output extension)")
//flags.BoolVarP(&opts.Preview, "preview", "p", false, "preview result")
viper.BindPFlags(flags)
if err := viper.BindPFlags(flags); err != nil {
zap.L().Warn("find to bind flags using Viper", zap.Error(err))
}
}

func (cmd *graphCommand) NewCobraCommand(dc map[string]DepvizCommand) *cobra.Command {
Expand Down
5 changes: 4 additions & 1 deletion cli/cmd_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/spf13/pflag"
"github.com/spf13/viper"
"go.uber.org/zap"

"moul.io/depviz/pkg/issues"
)

Expand Down Expand Up @@ -40,7 +41,9 @@ func (cmd *pullCommand) LoadDefaultOptions() error {
func (cmd *pullCommand) ParseFlags(flags *pflag.FlagSet) {
flags.StringVarP(&cmd.opts.GithubToken, "github-token", "", "", "GitHub Token with 'issues' access")
flags.StringVarP(&cmd.opts.GitlabToken, "gitlab-token", "", "", "GitLab Token with 'issues' access")
viper.BindPFlags(flags)
if err := viper.BindPFlags(flags); err != nil {
zap.L().Warn("find to bind flags using Viper", zap.Error(err))
}
}

func (cmd *pullCommand) NewCobraCommand(dc map[string]DepvizCommand) *cobra.Command {
Expand Down
6 changes: 5 additions & 1 deletion cli/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"go.uber.org/zap"

"moul.io/depviz/pkg/issues"
)

Expand Down Expand Up @@ -36,7 +38,9 @@ func (cmd *runCommand) LoadDefaultOptions() error {
func (cmd *runCommand) ParseFlags(flags *pflag.FlagSet) {
flags.BoolVarP(&cmd.opts.NoPull, "no-pull", "", false, "do not pull new issues before running")
flags.StringSliceVarP(&cmd.opts.AdditionalPulls, "additional-pulls", "", []string{}, "additional pull that won't necessarily be displayed on the graph")
viper.BindPFlags(flags)
if err := viper.BindPFlags(flags); err != nil {
zap.L().Warn("find to bind flags using Viper", zap.Error(err))
}
}

func (cmd *runCommand) NewCobraCommand(dc map[string]DepvizCommand) *cobra.Command {
Expand Down
26 changes: 18 additions & 8 deletions cli/cmd_web.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"go.uber.org/zap"

"moul.io/depviz/pkg/issues"
)

Expand Down Expand Up @@ -47,7 +49,9 @@ func (cmd *webCommand) LoadDefaultOptions() error {
func (cmd *webCommand) ParseFlags(flags *pflag.FlagSet) {
flags.StringVarP(&cmd.opts.Bind, "bind", "b", ":2020", "web server bind address")
flags.BoolVarP(&cmd.opts.ShowRoutes, "show-routes", "", false, "display available routes and quit")
viper.BindPFlags(flags)
if err := viper.BindPFlags(flags); err != nil {
zap.L().Warn("find to bind flags using Viper", zap.Error(err))
}
}

func (cmd *webCommand) NewCobraCommand(dc map[string]DepvizCommand) *cobra.Command {
Expand All @@ -67,7 +71,7 @@ func (cmd *webCommand) NewCobraCommand(dc map[string]DepvizCommand) *cobra.Comma
func webListIssues(w http.ResponseWriter, r *http.Request) {
issues, err := issues.Load(db, nil)
if err != nil {
render.Render(w, r, ErrRender(err))
_ = render.Render(w, r, ErrRender(err))
return
}

Expand All @@ -80,7 +84,7 @@ func webListIssues(w http.ResponseWriter, r *http.Request) {
}

if err := render.RenderList(w, r, list); err != nil {
render.Render(w, r, ErrRender(err))
_ = render.Render(w, r, ErrRender(err))
return
}
}
Expand All @@ -105,26 +109,32 @@ func webGraphviz(r *http.Request) (string, error) {
func webDotIssues(w http.ResponseWriter, r *http.Request) {
out, err := webGraphviz(r)
if err != nil {
render.Render(w, r, ErrRender(err))
_ = render.Render(w, r, ErrRender(err))
return
}

w.Write([]byte(out))
_, _ = w.Write([]byte(out))
}

func webImageIssues(w http.ResponseWriter, r *http.Request) {
out, err := webGraphviz(r)
if err != nil {
render.Render(w, r, ErrRender(err))
_ = render.Render(w, r, ErrRender(err))
return
}

binary, err := exec.LookPath("dot")
if err != nil {
_ = render.Render(w, r, ErrRender(err))
return
}

cmd := exec.Command("dot", "-Tsvg")
cmd := exec.Command(binary, "-Tsvg") // guardrails-disable-line
cmd.Stdin = bytes.NewBuffer([]byte(out))
cmd.Stdout = w

if err := cmd.Run(); err != nil {
render.Render(w, r, ErrRender(err))
_ = render.Render(w, r, ErrRender(err))
return
}
}
Expand Down
2 changes: 2 additions & 0 deletions cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import (
"strings"

"github.com/jinzhu/gorm"
_ "github.com/mattn/go-sqlite3" // required by gorm
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

"moul.io/depviz/pkg/issues"
"moul.io/zapgorm"
)
Expand Down
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import (
"fmt"
"os"

_ "github.com/mattn/go-sqlite3"
"go.uber.org/zap"

"moul.io/depviz/cli"
)

func main() {
defer zap.L().Sync()
defer func() {
if err := zap.L().Sync(); err != nil {
panic(err)
}
}()
rootCmd := cli.NewRootCommand()
if err := rootCmd.Execute(); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%v\n", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/airtabledb/airtabledb.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package airtabledb
package airtabledb // import "moul.io/depviz/pkg/airtabledb"

import (
"encoding/json"
Expand Down
1 change: 1 addition & 0 deletions pkg/issues/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package issues // import "moul.io/depviz/pkg/issues"
8 changes: 2 additions & 6 deletions pkg/issues/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func fromGithubUser(input *github.User) *Account {
Base: Base{
ID: "github", // FIXME: support multiple github instances
},
Driver: GithubDriver,
Driver: string(GithubDriver),
},
URL: input.GetURL(),
Location: input.GetLocation(),
Expand All @@ -85,10 +85,6 @@ func fromGithubUser(input *github.User) *Account {
}
}

func fromGithubRepository(input *github.Repository) *Repository {
panic("not implemented")
}

func fromGithubRepositoryURL(input string) *Repository {
return &Repository{
Base: Base{
Expand All @@ -99,7 +95,7 @@ func fromGithubRepositoryURL(input string) *Repository {
Base: Base{
ID: "github", // FIXME: support multiple github instances
},
Driver: GithubDriver,
Driver: string(GithubDriver),
},
}
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/issues/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import (
func gitlabPull(target Target, wg *sync.WaitGroup, token string, db *gorm.DB, out chan []*Issue) {
defer wg.Done()
client := gitlab.NewClient(nil, token)
client.SetBaseURL(fmt.Sprintf("%s/api/v4", target.ProviderURL()))
if err := client.SetBaseURL(fmt.Sprintf("%s/api/v4", target.ProviderURL())); err != nil {
zap.L().Error("failed to configure GitLab client", zap.Error(err))
return
}
total := 0
gitlabOpts := &gitlab.ListProjectIssuesOptions{
ListOptions: gitlab.ListOptions{
Expand Down Expand Up @@ -150,7 +153,7 @@ func fromGitlabFakeUser(provider *Provider, input gitlabFakeUser) *Account {
Base: Base{
ID: "gitlab", // FIXME: support multiple gitlab instances
},
Driver: GitlabDriver,
Driver: string(GitlabDriver),
},
// Email:
FullName: name,
Expand Down Expand Up @@ -184,7 +187,7 @@ func fromGitlabRepositoryURL(input string) *Repository {
ID: "gitlab", // FIXME: support multiple gitlab instances
},
URL: providerURL,
Driver: GitlabDriver,
Driver: string(GitlabDriver),
},
}
}
Expand Down
Loading