fix(ci): CI 安装 golangci-lint 并修复 make lint 全部 11 处报告(errcheck/gosec/misspell)
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
5a7aa6cdb8
commit
9b4f890208
|
|
@ -20,6 +20,9 @@ jobs:
|
||||||
- name: Build
|
- name: Build
|
||||||
run: go build ./...
|
run: go build ./...
|
||||||
|
|
||||||
|
- name: Install golangci-lint
|
||||||
|
run: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6
|
||||||
|
|
||||||
- name: Lint
|
- name: Lint
|
||||||
run: make lint
|
run: make lint
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,9 @@ linters:
|
||||||
- misspell # spelling mistakes in identifiers
|
- misspell # spelling mistakes in identifiers
|
||||||
|
|
||||||
settings:
|
settings:
|
||||||
|
misspell:
|
||||||
|
ignore-rules:
|
||||||
|
- creater # GitLink API/DB 字段拼写(creater_id),非笔误
|
||||||
gosec:
|
gosec:
|
||||||
excludes:
|
excludes:
|
||||||
- G104 # errcheck already handles unchecked errors
|
- G104 # errcheck already handles unchecked errors
|
||||||
|
|
@ -57,3 +60,6 @@ linters:
|
||||||
# apiInt: intentional uint64->int truncation for API response parsing
|
# apiInt: intentional uint64->int truncation for API response parsing
|
||||||
- linters: [gosec]
|
- linters: [gosec]
|
||||||
text: "G115: integer overflow conversion uint64 -> int"
|
text: "G115: integer overflow conversion uint64 -> int"
|
||||||
|
# apiInt: same intentional truncation for uint on 32-bit platforms
|
||||||
|
- linters: [gosec]
|
||||||
|
text: "G115: integer overflow conversion uint -> int"
|
||||||
|
|
|
||||||
|
|
@ -268,9 +268,9 @@ func runCommand(cliBin string, args []string, apply bool) CommandResult {
|
||||||
if !apply {
|
if !apply {
|
||||||
return CommandResult{Command: command, Status: "planned"}
|
return CommandResult{Command: command, Status: "planned"}
|
||||||
}
|
}
|
||||||
cmd := exec.Command(cliBin, args...)
|
cmd := exec.Command(cliBin, args...) // #nosec G204 -- cliBin 与 args 由用户配置显式给出,CLI 包装器的预期行为
|
||||||
if strings.HasSuffix(strings.ToLower(cliBin), ".cmd") || strings.HasSuffix(strings.ToLower(cliBin), ".bat") {
|
if strings.HasSuffix(strings.ToLower(cliBin), ".cmd") || strings.HasSuffix(strings.ToLower(cliBin), ".bat") {
|
||||||
cmd = exec.Command("cmd", append([]string{"/c", cliBin}, args...)...)
|
cmd = exec.Command("cmd", append([]string{"/c", cliBin}, args...)...) // #nosec G204
|
||||||
}
|
}
|
||||||
var stdout, stderr bytes.Buffer
|
var stdout, stderr bytes.Buffer
|
||||||
cmd.Stdout = &stdout
|
cmd.Stdout = &stdout
|
||||||
|
|
@ -318,7 +318,7 @@ func writeOutputs(config ProjectConfig, outputDir string, now time.Time) (Output
|
||||||
owner := config.Repository.Owner
|
owner := config.Repository.Owner
|
||||||
repo := config.Repository.Name
|
repo := config.Repository.Name
|
||||||
prefix := fmt.Sprintf("%s_%s_%s", safeName(owner), safeName(repo), now.UTC().Format("20060102_150405"))
|
prefix := fmt.Sprintf("%s_%s_%s", safeName(owner), safeName(repo), now.UTC().Format("20060102_150405"))
|
||||||
if err := os.MkdirAll(outputDir, 0o755); err != nil {
|
if err := os.MkdirAll(outputDir, 0o750); err != nil {
|
||||||
return OutputPaths{}, err
|
return OutputPaths{}, err
|
||||||
}
|
}
|
||||||
files := plannedFiles(config)
|
files := plannedFiles(config)
|
||||||
|
|
@ -367,7 +367,7 @@ func writeOutputs(config ProjectConfig, outputDir string, now time.Time) (Output
|
||||||
paths.Files: filesJSON,
|
paths.Files: filesJSON,
|
||||||
}
|
}
|
||||||
for path, data := range writes {
|
for path, data := range writes {
|
||||||
if err := os.WriteFile(path, data, 0o644); err != nil {
|
if err := os.WriteFile(path, data, 0o600); err != nil {
|
||||||
return OutputPaths{}, err
|
return OutputPaths{}, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -455,7 +455,7 @@ func main() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
commandLogPath := filepath.Join(opts.OutputDir, fmt.Sprintf("command_log_%s.json", now.UTC().Format("20060102_150405")))
|
commandLogPath := filepath.Join(opts.OutputDir, fmt.Sprintf("command_log_%s.json", now.UTC().Format("20060102_150405")))
|
||||||
if err := os.WriteFile(commandLogPath, commandLogJSON, 0o644); err != nil {
|
if err := os.WriteFile(commandLogPath, commandLogJSON, 0o600); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "写入命令日志失败: %v\n", err)
|
fmt.Fprintf(os.Stderr, "写入命令日志失败: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,11 +44,11 @@ func openDB(path string) (*sql.DB, error) {
|
||||||
return nil, fmt.Errorf("open database: %w", err)
|
return nil, fmt.Errorf("open database: %w", err)
|
||||||
}
|
}
|
||||||
if _, err := db.Exec("PRAGMA journal_mode=WAL"); err != nil {
|
if _, err := db.Exec("PRAGMA journal_mode=WAL"); err != nil {
|
||||||
db.Close()
|
_ = db.Close()
|
||||||
return nil, fmt.Errorf("set WAL mode: %w", err)
|
return nil, fmt.Errorf("set WAL mode: %w", err)
|
||||||
}
|
}
|
||||||
if _, err := db.Exec(schemaSQL); err != nil {
|
if _, err := db.Exec(schemaSQL); err != nil {
|
||||||
db.Close()
|
_ = db.Close()
|
||||||
return nil, fmt.Errorf("init schema: %w", err)
|
return nil, fmt.Errorf("init schema: %w", err)
|
||||||
}
|
}
|
||||||
return db, nil
|
return db, nil
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ func Shortcuts(translators ...*i18n.Translator) []*common.Shortcut {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer func() { _ = db.Close() }()
|
||||||
|
|
||||||
repoID, err := getOrCreateRepo(db, ctx.Repo, ctx.Owner)
|
repoID, err := getOrCreateRepo(db, ctx.Repo, ctx.Owner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -390,7 +390,7 @@ func Shortcuts(translators ...*i18n.Translator) []*common.Shortcut {
|
||||||
"approved": "approved", "rejected": "rejected", "common": "commented",
|
"approved": "approved", "rejected": "rejected", "common": "commented",
|
||||||
}[status]
|
}[status]
|
||||||
summary := fmt.Sprintf("## Review: %s\n\n%s", statusLabel, content)
|
summary := fmt.Sprintf("## Review: %s\n\n%s", statusLabel, content)
|
||||||
ctx.CallAPI("POST", fmt.Sprintf("/v1/%s/%s/issues/%d/journals", ctx.Owner, ctx.Repo, issueID),
|
_, _ = ctx.CallAPI("POST", fmt.Sprintf("/v1/%s/%s/issues/%d/journals", ctx.Owner, ctx.Repo, issueID),
|
||||||
map[string]interface{}{"notes": summary})
|
map[string]interface{}{"notes": summary})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue