From a0b4232e4150656e02fef9d3d22d558b977d6c47 Mon Sep 17 00:00:00 2001 From: Hazumi Ichijo Date: Fri, 30 Aug 2024 01:19:02 +0900 Subject: [PATCH 1/2] Setup golangci-lint --- .github/workflows/go.yml | 12 ++++++++++++ .golangci.yml | 4 ++++ 2 files changed, 16 insertions(+) create mode 100644 .golangci.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index b3b0cb3..66adc6c 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -106,3 +106,15 @@ jobs: - uses: actions/checkout@v4 - name: Check Renovate config run: npx --yes --package renovate -- renovate-config-validator --strict + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.60 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..da58587 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,4 @@ +linters: + disable: + - errcheck + From 66ad72962ec799f7b1cf7620df99a3357d690b7b Mon Sep 17 00:00:00 2001 From: Hazumi Ichijo Date: Fri, 30 Aug 2024 01:21:02 +0900 Subject: [PATCH 2/2] Fix --- cmd/cmd.go | 7 +++++-- cmd/schedule/apply.go | 2 +- cmd/schedule/render.go | 2 +- domain/issue/domain.go | 9 ++++++--- repo/issue.go | 1 - 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 613d2b2..943dd45 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -74,10 +74,13 @@ func NewConfig() (Config, error) { pflag.StringP("check-before-create-issue", "", "", "") viper.AutomaticEnv() - viper.BindPFlags(pflag.CommandLine) + err := viper.BindPFlags(pflag.CommandLine) + if err != nil { + return Config{}, errors.WithStack(err) + } var cfg Config pflag.Parse() - err := viper.Unmarshal(&cfg) + err = viper.Unmarshal(&cfg) return cfg, errors.WithStack(err) } diff --git a/cmd/schedule/apply.go b/cmd/schedule/apply.go index 0840b0f..95f47c4 100644 --- a/cmd/schedule/apply.go +++ b/cmd/schedule/apply.go @@ -20,7 +20,7 @@ func NewApplyCommand(ctx context.Context, templateFilePath string, srv schedule. RunE: func(_ *cobra.Command, args []string) error { b, err := os.ReadFile(templateFilePath) if err != nil { - errors.WithStack(err) + return errors.WithStack(err) } templateFile := string(b) diff --git a/cmd/schedule/render.go b/cmd/schedule/render.go index 3edf5d1..0eee45d 100644 --- a/cmd/schedule/render.go +++ b/cmd/schedule/render.go @@ -20,7 +20,7 @@ func NewRenderCommand(ctx context.Context, templateFilePath string, srv schedule zap.L().Debug("template path", zap.String("templateFilePath", templateFilePath)) b, err := os.ReadFile(templateFilePath) if err != nil { - errors.WithStack(err) + return errors.WithStack(err) } templateFile := string(b) diff --git a/domain/issue/domain.go b/domain/issue/domain.go index f3fa2b1..37bb2f8 100644 --- a/domain/issue/domain.go +++ b/domain/issue/domain.go @@ -80,14 +80,14 @@ func (is *issueServiceImpl) render(ctx context.Context, templateIssueURL string) if err != nil { return types.Issue{}, errors.Wrap(err, "Failed to render title") } - title := string(tw.Bytes()) + title := tw.String() bw := bytes.NewBufferString("") err = bodyTmpl.Execute(bw, TemplateData{CurrentTime: is.ct, LastIssue: lastIssue, AddDay: func(d int) time.Time { return is.ct.AddDate(0, 0, d) }}) if err != nil { return types.Issue{}, errors.Wrap(err, "Failed to render body") } - body := string(bw.Bytes()) + body := bw.String() if lastIssue.URL == nil { return types.Issue{}, errors.New("Invalid last issue passed(empty URL)") @@ -126,7 +126,10 @@ func (is *issueServiceImpl) Create(ctx context.Context, templateURL string) (typ if err != nil { return types.Issue{}, errors.WithStack(err) } - f.Chmod(0755) + err = f.Chmod(0755) + if err != nil { + return types.Issue{}, errors.WithStack(err) + } f.Close() out, err := exec.Command("sh", f.Name()).Output() diff --git a/repo/issue.go b/repo/issue.go index 5889fa3..3fa2728 100644 --- a/repo/issue.go +++ b/repo/issue.go @@ -135,7 +135,6 @@ func (ir *issueRepositoryImpl) FindLastIssue(ctx context.Context, templateIssue var ( // State closed = "closed" - open = "open" ) func (ir *issueRepositoryImpl) CloseByURL(ctx context.Context, issueURL string) error {