Skip to content

Commit 9ce1181

Browse files
authored
go1.25 (#333)
* go1.25 * x * x * govuln * x
1 parent 9368762 commit 9ce1181

File tree

53 files changed

+529
-256
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+529
-256
lines changed

.github/workflows/ci.yml

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,75 @@
11
name: CI
2+
23
on:
34
push:
45
branches:
56
- master
67
pull_request:
78
branches:
89
- master
10+
schedule:
11+
# Run daily at 2 AM UTC to check for new vulnerabilities
12+
- cron: "0 2 * * *"
13+
14+
permissions:
15+
contents: read
16+
17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.ref }}
19+
cancel-in-progress: true
20+
921
jobs:
1022
test:
23+
timeout-minutes: 15
1124
strategy:
1225
matrix:
13-
go-version: [1.23.x]
26+
go-version: [1.25.x, 1.24.x]
1427
os: [ubuntu-latest]
1528
runs-on: ${{ matrix.os }}
1629
steps:
17-
- uses: actions/setup-go@v3
30+
- uses: actions/checkout@v6
31+
with:
32+
persist-credentials: false
33+
34+
- uses: actions/setup-go@v6
1835
with:
1936
go-version: ${{ matrix.go-version }}
20-
- uses: actions/checkout@v3
21-
- name: Go Lint Standard
22-
uses: golangci/golangci-lint-action@v3
37+
cache: true
38+
39+
- name: golangci-lint
40+
uses: golangci/golangci-lint-action@v9
41+
with:
42+
version: v2.7.2
43+
44+
- name: Build
45+
run: go build -v ./...
46+
47+
- name: Run govulncheck
48+
uses: golang/govulncheck-action@v1
49+
with:
50+
go-version-input: ${{ matrix.go-version }}
51+
52+
- name: Test
53+
run: go test -race ./...
54+
55+
jirabot:
56+
runs-on: ubuntu-latest
57+
defaults:
58+
run:
59+
working-directory: jirabot
60+
steps:
61+
- name: Checkout
62+
uses: actions/checkout@v6
63+
64+
- name: Setup Node.js
65+
uses: actions/setup-node@v6
2366
with:
24-
version: v1.63
25-
args: "--out-${NO_FUTURE}format colored-line-number --timeout=15m"
26-
- run: go vet ./...
27-
- run: go test ./...
28-
# Copied from .travis.yml but never migrated to github actions
29-
# - language: node_js
30-
# node_js: 10
31-
# script:
32-
# - cd jirabot
33-
# - yarn
34-
# - yarn ci
67+
node-version: 25.x
68+
cache: yarn
69+
cache-dependency-path: jirabot/yarn.lock
70+
71+
- name: Install dependencies
72+
run: yarn install --frozen-lockfile
73+
74+
- name: Run jirabot CI
75+
run: yarn ci

.golangci.yml

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,65 @@
1-
linters-settings:
2-
gocritic:
3-
disabled-checks:
4-
- ifElseChain
5-
- elseif
1+
version: "2"
2+
3+
run:
4+
timeout: 5m
5+
tests: true
6+
7+
formatters:
8+
enable:
9+
- gofumpt
610

711
linters:
812
enable:
9-
- gofmt
10-
- gocritic
11-
- unconvert
12-
- revive
13-
- govet
13+
# Core recommended linters
14+
- errcheck # Checks for unchecked errors
15+
- govet # Go vet checks
16+
- ineffassign # Detects ineffectual assignments
17+
- staticcheck # Advanced static analysis
18+
- unused # Finds unused code
19+
20+
# Code quality
21+
- misspell # Finds commonly misspelled words
22+
- unconvert # Unnecessary type conversions (already enabled in original)
23+
- unparam # Finds unused function parameters
24+
- gocritic # Various checks (already enabled in original)
25+
- revive # Fast, configurable linter (already enabled in original)
26+
27+
# Security and best practices
28+
- gosec # Security-focused linter
29+
- bodyclose # Checks HTTP response body closed
30+
31+
settings:
32+
gocritic:
33+
disabled-checks:
34+
- ifElseChain
35+
- elseif
36+
37+
govet:
38+
enable-all: true
39+
disable:
40+
- shadow
41+
- fieldalignment
42+
43+
revive:
44+
enable-all-rules: false
45+
46+
exclusions:
47+
rules:
48+
# Exclude specific revive rules
49+
- linters:
50+
- revive
51+
text: "package-comments"
52+
53+
- linters:
54+
- revive
55+
text: "exported"
56+
57+
# Exclude specific staticcheck rules
58+
- linters:
59+
- staticcheck
60+
text: "ST1005"
61+
62+
# Exclude specific gocritic rules
63+
- linters:
64+
- gocritic
65+
text: "ifElseChain"

base/db.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func NewBaseOAuthDB(db *sql.DB) *BaseOAuthDB {
4444

4545
func (d *BaseOAuthDB) GetState(state string) (*OAuthRequest, error) {
4646
var oauthState OAuthRequest
47-
row := d.DB.QueryRow(`SELECT identifier, conv_id, msg_id, is_complete
47+
row := d.QueryRow(`SELECT identifier, conv_id, msg_id, is_complete
4848
FROM oauth_state
4949
WHERE state = ?`, state)
5050
err := row.Scan(&oauthState.TokenIdentifier, &oauthState.ConvID,
@@ -97,7 +97,7 @@ func NewOAuthDB(db *sql.DB) *OAuthDB {
9797
func (d *OAuthDB) GetToken(identifier string) (*oauth2.Token, error) {
9898
var token oauth2.Token
9999
var expiry int64
100-
row := d.DB.QueryRow(`SELECT access_token, token_type, refresh_token, ROUND(UNIX_TIMESTAMP(expiry))
100+
row := d.QueryRow(`SELECT access_token, token_type, refresh_token, ROUND(UNIX_TIMESTAMP(expiry))
101101
FROM oauth
102102
WHERE identifier = ?`, identifier)
103103
err := row.Scan(&token.AccessToken, &token.TokenType,

base/email.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ type Emailer interface {
1212
Send(address, subject, message string) error
1313
}
1414

15-
type DummyEmailer struct {
16-
}
15+
type DummyEmailer struct{}
1716

1817
func (d DummyEmailer) Send(_, subject, _ string) error {
1918
fmt.Printf("subject: %s\n", subject)

base/errors.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package base
22

33
import (
4-
"time"
5-
6-
"runtime/debug"
7-
84
"os"
5+
"runtime/debug"
6+
"time"
97

108
"golang.org/x/sync/errgroup"
119
)

base/http.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package base
33
import (
44
"context"
55
"net/http"
6+
"time"
67
)
78

89
type HTTPSrv struct {
@@ -15,7 +16,10 @@ func NewHTTPSrv(stats *StatsRegistry, debugConfig *ChatDebugOutputConfig) *HTTPS
1516
return &HTTPSrv{
1617
DebugOutput: NewDebugOutput("HTTPSrv", debugConfig),
1718
Stats: stats.SetPrefix("HTTPSrv"),
18-
srv: &http.Server{Addr: ":8080"},
19+
srv: &http.Server{
20+
Addr: ":8080",
21+
ReadHeaderTimeout: 10 * time.Second,
22+
},
1923
}
2024
}
2125

base/server.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,7 @@ func (s *Server) listenForMsgs(shutdownCh chan struct{}, sub *kbchat.Subscriptio
218218
}
219219
continue
220220
case strings.HasPrefix(cmd, fmt.Sprintf("!%s", feedbackCmd(s.kbc.GetUsername()))):
221-
if err := s.handleFeedback(msg); err != nil {
222-
s.Errorf("listenForMsgs: unable to handleFeedback: %v", err)
223-
}
221+
s.handleFeedback(msg)
224222
continue
225223
}
226224
}
@@ -291,7 +289,7 @@ func (s *Server) handleLogSend(msg chat1.MsgSummary) error {
291289
}
292290
outputBytes, err := io.ReadAll(output)
293291
if err != nil {
294-
s.Errorf("unable to read ouput: %v", err)
292+
s.Errorf("unable to read output: %v", err)
295293
return err
296294
}
297295
if len(outputBytes) > 0 {
@@ -345,8 +343,8 @@ func (s *Server) handlePProf(msg chat1.MsgSummary) error {
345343
// Cleanup after the file is sent.
346344
time.Sleep(time.Minute)
347345
s.Debug("cleaning up %s", outfile)
348-
if err = os.Remove(outfile); err != nil {
349-
s.Errorf("unable to clean up %s: %v", outfile, err)
346+
if rmErr := os.Remove(outfile); rmErr != nil {
347+
s.Errorf("unable to clean up %s: %v", outfile, rmErr)
350348
}
351349
}()
352350
if _, err := s.kbc.SendAttachmentByConvID(msg.ConvID, outfile, ""); err != nil {
@@ -389,7 +387,7 @@ func (s *Server) handleStack(msg chat1.MsgSummary) error {
389387
return s.kbfsDebugOutput(msg, stack, "stack")
390388
}
391389

392-
func (s *Server) handleFeedback(msg chat1.MsgSummary) error {
390+
func (s *Server) handleFeedback(msg chat1.MsgSummary) {
393391
toks := strings.Split(strings.TrimSpace(msg.Content.Text.Body), " ")
394392
if len(toks) < 3 {
395393
s.ChatEcho(msg.ConvID, "Woah there @%s, I can't deliver a blank message...not again. What did you want to say?",
@@ -400,7 +398,6 @@ func (s *Server) handleFeedback(msg chat1.MsgSummary) error {
400398
s.ChatEcho(msg.ConvID, "Roger that @%s, passed this along to my humans :robot_face:",
401399
msg.Sender.Username)
402400
}
403-
return nil
404401
}
405402

406403
func (s *Server) kbfsDebugOutput(msg chat1.MsgSummary, data []byte, operation string) error {
@@ -415,8 +412,12 @@ func (s *Server) kbfsDebugOutput(msg chat1.MsgSummary, data []byte, operation st
415412
}
416413
fileName := fmt.Sprintf("%s-%d.txt", operation, time.Now().Unix())
417414
filePath := fmt.Sprintf("/tmp/%s", fileName)
418-
defer os.Remove(filePath)
419-
if err := os.WriteFile(filePath, data, 0644); err != nil {
415+
defer func() {
416+
if rmErr := os.Remove(filePath); rmErr != nil {
417+
s.Errorf("unable to clean up %s: %v", filePath, rmErr)
418+
}
419+
}()
420+
if err := os.WriteFile(filePath, data, 0o600); err != nil {
420421
return fmt.Errorf("kbfsOutput: failed to write %s output: %s", operation, err)
421422
}
422423
if err := s.runOptions.Command("fs", "mv", filePath, folder).Run(); err != nil {

base/stats.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,18 @@ func (s *StathatBackend) Shutdown() error {
8686
func NewStatsBackend(btype StatsBackendType, config interface{}) (StatsBackend, error) {
8787
switch btype {
8888
case StathatStatsBackendType:
89-
if config, ok := config.(StathatConfig); ok {
90-
reporter := stathat.NewBatchReporter(stathat.DefaultReporter, 200*time.Millisecond)
91-
return &StathatBackend{config: config, reporter: reporter}, nil
92-
} else {
89+
cfg, ok := config.(StathatConfig)
90+
if !ok {
9391
return nil, errors.New("invalid stathat config")
9492
}
93+
reporter := stathat.NewBatchReporter(stathat.DefaultReporter, 200*time.Millisecond)
94+
return &StathatBackend{config: cfg, reporter: reporter}, nil
9595
case DummyStatsBackendType:
96-
if config, ok := config.(*ChatDebugOutputConfig); ok {
97-
return NewDummyStatsBackend(config), nil
98-
} else {
96+
cfg, ok := config.(*ChatDebugOutputConfig)
97+
if !ok {
9998
return nil, errors.New("invalid DummyStatsBackend config")
10099
}
100+
return NewDummyStatsBackend(cfg), nil
101101
default:
102102
return nil, errors.New("unknown stats registry type")
103103
}
@@ -115,11 +115,11 @@ func (r *StatsRegistry) makeFname(name string) string {
115115

116116
func (r *StatsRegistry) SetPrefix(prefix string) *StatsRegistry {
117117
prefix = r.prefix + prefix + " - "
118-
return newStatsRegistryWithPrefix(r.DebugOutput.Config(), r.backend, prefix)
118+
return newStatsRegistryWithPrefix(r.Config(), r.backend, prefix)
119119
}
120120

121121
func (r *StatsRegistry) ResetPrefix() *StatsRegistry {
122-
return NewStatsRegistryWithBackend(r.DebugOutput.Config(), r.backend)
122+
return NewStatsRegistryWithBackend(r.Config(), r.backend)
123123
}
124124

125125
func (r *StatsRegistry) Count(name string) {

elastiwatch/elastiwatch/db.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package elastiwatch
22

33
import (
44
"database/sql"
5+
"fmt"
56
"time"
67

78
"github.com/keybase/managed-bots/base"
@@ -40,7 +41,11 @@ func (d *DB) List() (res []Deferral, err error) {
4041
if err != nil {
4142
return res, err
4243
}
43-
defer rows.Close()
44+
defer func() {
45+
if cerr := rows.Close(); cerr != nil {
46+
fmt.Printf("elastiwatch: failed to close rows: %v\n", cerr)
47+
}
48+
}()
4449
for rows.Next() {
4550
var def Deferral
4651
if err := rows.Scan(&def.ID, &def.Regex, &def.Author, &def.Ctime); err != nil {

elastiwatch/elastiwatch/handler.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ type Handler struct {
2121

2222
var _ base.Handler = (*Handler)(nil)
2323

24-
func NewHandler(kbc *kbchat.API, debugConfig *base.ChatDebugOutputConfig,
25-
httpSrv *HTTPSrv, db *DB, logs *LogWatch) *Handler {
24+
func NewHandler(kbc *kbchat.API, debugConfig *base.ChatDebugOutputConfig, httpSrv *HTTPSrv, db *DB, logs *LogWatch) *Handler {
2625
return &Handler{
2726
DebugOutput: base.NewDebugOutput("Handler", debugConfig),
2827
kbc: kbc,

0 commit comments

Comments
 (0)