From 30824356e7a3b923e370a41b2ae24a029a99555a Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Thu, 27 Dec 2018 15:45:19 +0100 Subject: [PATCH] chore: fix lint errors --- cli/cmd_airtable.go | 7 +++++-- cli/cmd_db.go | 6 +++++- cli/cmd_graph.go | 5 ++++- cli/cmd_pull.go | 5 ++++- cli/cmd_run.go | 6 +++++- cli/cmd_web.go | 26 ++++++++++++++++++-------- cli/root.go | 2 ++ main.go | 8 ++++++-- pkg/issues/github.go | 8 ++------ pkg/issues/gitlab.go | 9 ++++++--- pkg/issues/models.go | 26 +++++++++++++------------- pkg/issues/target.go | 3 +-- 12 files changed, 71 insertions(+), 40 deletions(-) diff --git a/cli/cmd_airtable.go b/cli/cmd_airtable.go index 51bab74c..974a163a 100644 --- a/cli/cmd_airtable.go +++ b/cli/cmd_airtable.go @@ -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" ) @@ -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 { @@ -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) } diff --git a/cli/cmd_db.go b/cli/cmd_db.go index ad3ab169..cb6a0902 100644 --- a/cli/cmd_db.go +++ b/cli/cmd_db.go @@ -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" ) @@ -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 { diff --git a/cli/cmd_graph.go b/cli/cmd_graph.go index b92d0c2c..0504481d 100644 --- a/cli/cmd_graph.go +++ b/cli/cmd_graph.go @@ -16,6 +16,7 @@ import ( "github.com/spf13/pflag" "github.com/spf13/viper" "go.uber.org/zap" + "moul.io/depviz/pkg/issues" ) @@ -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 { diff --git a/cli/cmd_pull.go b/cli/cmd_pull.go index fdcd5dd3..b2b4d14a 100644 --- a/cli/cmd_pull.go +++ b/cli/cmd_pull.go @@ -9,6 +9,7 @@ import ( "github.com/spf13/pflag" "github.com/spf13/viper" "go.uber.org/zap" + "moul.io/depviz/pkg/issues" ) @@ -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 { diff --git a/cli/cmd_run.go b/cli/cmd_run.go index 2dceff28..d43a8eb2 100644 --- a/cli/cmd_run.go +++ b/cli/cmd_run.go @@ -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" ) @@ -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 { diff --git a/cli/cmd_web.go b/cli/cmd_web.go index 9278df0f..dd35bccd 100644 --- a/cli/cmd_web.go +++ b/cli/cmd_web.go @@ -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" ) @@ -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 { @@ -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 } @@ -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 } } @@ -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") 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 } } diff --git a/cli/root.go b/cli/root.go index 18b5ee3d..e98d6ba9 100644 --- a/cli/root.go +++ b/cli/root.go @@ -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" ) diff --git a/main.go b/main.go index c8a5d36c..ba0155ef 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/pkg/issues/github.go b/pkg/issues/github.go index 2732b2af..f5c50faa 100644 --- a/pkg/issues/github.go +++ b/pkg/issues/github.go @@ -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(), @@ -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{ @@ -99,7 +95,7 @@ func fromGithubRepositoryURL(input string) *Repository { Base: Base{ ID: "github", // FIXME: support multiple github instances }, - Driver: GithubDriver, + Driver: string(GithubDriver), }, } } diff --git a/pkg/issues/gitlab.go b/pkg/issues/gitlab.go index 04603895..846e78da 100644 --- a/pkg/issues/gitlab.go +++ b/pkg/issues/gitlab.go @@ -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{ @@ -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, @@ -184,7 +187,7 @@ func fromGitlabRepositoryURL(input string) *Repository { ID: "gitlab", // FIXME: support multiple gitlab instances }, URL: providerURL, - Driver: GitlabDriver, + Driver: string(GitlabDriver), }, } } diff --git a/pkg/issues/models.go b/pkg/issues/models.go index fb163341..562d2cb6 100644 --- a/pkg/issues/models.go +++ b/pkg/issues/models.go @@ -30,7 +30,7 @@ func copyFields(cache airtabledb.DB, src reflect.Value, dst reflect.Value) { dFV := dst.Field(i) dSF := dT.Field(i) fieldName := dSF.Name - // Recursively copy the embeded struct Base. + // Recursively copy the embedded struct Base. if fieldName == "Base" { copyFields(cache, src, dFV) continue @@ -103,9 +103,9 @@ type Repository struct { OwnerID string `json:"owner-id"` } -func (p Repository) ToRecord(cache airtabledb.DB) airtabledb.Record { +func (r Repository) ToRecord(cache airtabledb.DB) airtabledb.Record { record := airtabledb.RepositoryRecord{} - toRecord(cache, p, &record) + toRecord(cache, r, &record) return record } @@ -122,8 +122,8 @@ type ProviderDriver string const ( UnknownProviderDriver ProviderDriver = "unknown" - GithubDriver = "github" - GitlabDriver = "gitlab" + GithubDriver ProviderDriver = "github" + GitlabDriver ProviderDriver = "gitlab" ) type Provider struct { @@ -168,9 +168,9 @@ type Milestone struct { RepositoryID string `json:"repository-id"` } -func (p Milestone) ToRecord(cache airtabledb.DB) airtabledb.Record { +func (m Milestone) ToRecord(cache airtabledb.DB) airtabledb.Record { record := airtabledb.MilestoneRecord{} - toRecord(cache, p, &record) + toRecord(cache, m, &record) return record } @@ -227,9 +227,9 @@ func (i Issue) String() string { return string(out) } -func (p Issue) ToRecord(cache airtabledb.DB) airtabledb.Record { +func (i Issue) ToRecord(cache airtabledb.DB) airtabledb.Record { record := airtabledb.IssueRecord{} - toRecord(cache, p, &record) + toRecord(cache, i, &record) return record } @@ -247,9 +247,9 @@ type Label struct { Description string `json:"description"` } -func (p Label) ToRecord(cache airtabledb.DB) airtabledb.Record { +func (l Label) ToRecord(cache airtabledb.DB) airtabledb.Record { record := airtabledb.LabelRecord{} - toRecord(cache, p, &record) + toRecord(cache, l, &record) return record } @@ -282,9 +282,9 @@ type Account struct { ProviderID string `json:"provider-id"` } -func (p Account) ToRecord(cache airtabledb.DB) airtabledb.Record { +func (a Account) ToRecord(cache airtabledb.DB) airtabledb.Record { record := airtabledb.AccountRecord{} - toRecord(cache, p, &record) + toRecord(cache, a, &record) return record } diff --git a/pkg/issues/target.go b/pkg/issues/target.go index 02ce2089..f53f7f5a 100644 --- a/pkg/issues/target.go +++ b/pkg/issues/target.go @@ -60,8 +60,7 @@ func ParseTargets(inputs []string) (Targets, error) { str = str + "/issues/" + issue } - target := string(str) - targetMap[target] = target + targetMap[str] = str } targets := []string{} for _, target := range targetMap {