Skip to content

Commit

Permalink
chore: fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Dec 27, 2018
1 parent b8de45b commit 267b3aa
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
- 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: make lint
- run: PATH="$PATH:$(pwd)/bin" make lint
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
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
26 changes: 13 additions & 13 deletions pkg/issues/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -122,8 +122,8 @@ type ProviderDriver string

const (
UnknownProviderDriver ProviderDriver = "unknown"
GithubDriver = "github"
GitlabDriver = "gitlab"
GithubDriver ProviderDriver = "github"
GitlabDriver ProviderDriver = "gitlab"
)

type Provider struct {
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/issues/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 267b3aa

Please sign in to comment.