Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/app-manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@4.2.2

- name: Build app-manifest container image
run: make docker/build/chat-roulette
18 changes: 9 additions & 9 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,37 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Setup Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.23

- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@4.2.2

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8
with:
version: v1.60.1
version: v2.1.6

test:
name: test
runs-on: ubuntu-22.04
steps:
- name: Setup Go
uses: actions/setup-go@v2.1.3
uses: actions/setup-go@v5
with:
go-version: 1.23

- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@4.2.2

- name: Get dependencies
run: go mod download

- name: Setup gotestsum
uses: autero1/action-gotestsum@v2.0.0
uses: autero1/action-gotestsum@7263b9d73912eec65f46337689e59fac865c425f # v2.0.0
with:
gotestsum_version: 1.12.0
gotestsum_version: 1.12.3

- name: Run tests
run: make go/testsum
Expand All @@ -59,7 +59,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@4.2.2

- name: Build chat-roulette container image
run: make docker/build/chat-roulette
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ notes/
.coverage.out
config.json
fly.toml
.lint-report.html
151 changes: 82 additions & 69 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,73 +1,86 @@
version: "2"
run:
timeout: 5m
tests: true

linters:
disable-all: true
default: none
enable:
- errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases
- gosimple # specializes in simplifying a code
- govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- ineffassign # detects when assignments to existing variables are not used
- staticcheck # is a go vet on steroids, applying a ton of static analysis checks
- unused # checks for unused constants, variables, functions and types
- asasalint # checks for pass []any as any in variadic func(...any)
- asciicheck # checks that your code does not contain non-ASCII identifiers
- bidichk # checks for dangerous unicode character sequences
- bodyclose # checks whether HTTP response body is closed successfully
- durationcheck # checks for two durations multiplied together
- errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
- exportloopref # checks for pointers to enclosing loop variables
- forbidigo # forbids identifiers
- gocritic # provides diagnostics that check for bugs, performance and style issues
- goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt
- gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod
- gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations
- goprintffuncname # checks that printf-like functions are named with f at the end
- gosec # inspects source code for security problems
- loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap)
- makezero # finds slice declarations with non-zero initial length
- nakedret # finds naked returns in functions greater than a specified function length
- nestif # reports deeply nested if statements
- nilerr # finds the code that returns nil even if it checks that the error is not nil
- nilnil # checks that there is no simultaneous return of nil error and an invalid value
- noctx # finds sending http request without context.Context
- nonamedreturns # reports all named returns
- nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL
- predeclared # finds code that shadows one of Go's predeclared identifiers
- promlinter # checks Prometheus metrics naming via promlint
- reassign # checks that package variables are not reassigned
- stylecheck # is a replacement for golint
- tenv # detects using os.Setenv instead of t.Setenv since Go1.17
- testableexamples # checks if examples are testable (have an expected output)
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
- unconvert # removes unnecessary type conversions
- unparam # reports unused function parameters
- usestdlibvars # detects the possibility to use variables/constants from the Go standard library

output:
sort-results: true

linters-settings:
misspell:
locale: US
goimports:
local-prefixes: github.com/chat-roulettte/chat-roulette
errcheck:
check-type-assertions: true
exclude-functions:
- (net/http.ResponseWriter).Write
- (*github.com/unrolled/render.Render).HTML
nestif:
min-complexity: 10

issues:
exclude:
- ifElseChain
exclude-rules:
- path: _test\.go
linters:
- bodyclose
- errcheck
- noctx
- asciicheck # checks that your code does not contain non-ASCII identifiers
- bidichk # checks for dangerous unicode character sequences
- bodyclose # checks whether HTTP response body is closed successfully
- durationcheck # checks for two durations multiplied together
- errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases
- errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
- forbidigo # forbids identifiers
- gocritic # provides diagnostics that check for bugs, performance and style issues
- gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod
- gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations
- goprintffuncname # checks that printf-like functions are named with f at the end
- gosec # inspects source code for security problems
- govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- ineffassign # detects when assignments to existing variables are not used
- loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap)
- makezero # finds slice declarations with non-zero initial length
- misspell # finds commonly misspelled English words
- nakedret # finds naked returns in functions greater than a specified function length
- nestif # reports deeply nested if statements
- nilerr # finds the code that returns nil even if it checks that the error is not nil
- nilnil # checks that there is no simultaneous return of nil error and an invalid value
- noctx # finds sending http request without context.Context
- nonamedreturns # reports all named returns
- nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL
- predeclared # finds code that shadows one of Go's predeclared identifiers
- promlinter # checks Prometheus metrics naming via promlint
- reassign # checks that package variables are not reassigned
- staticcheck # is a go vet on steroids, applying a ton of static analysis checks (covers gosimple)
- testableexamples # checks if examples are testable (have an expected output)
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
- unconvert # removes unnecessary type conversions
- unparam # reports unused function parameters
- unused # checks for unused constants, variables, functions and types
- unused # checks for unused constants, variables, functions and types
- usestdlibvars # detects the possibility to use variables/constants from the Go standard library
# - dupl # detects duplicate code fragments
settings:
errcheck:
check-type-assertions: true
exclude-functions:
- (net/http.ResponseWriter).Write
- (*github.com/unrolled/render.Render).HTML
misspell:
locale: US
nestif:
min-complexity: 10
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- bodyclose
- dupl
- errcheck
- noctx
path: _test\.go
- path: (.+)\.go$
text: ifElseChain
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- goimports
settings:
goimports:
local-prefixes:
- github.com/chat-roulettte/chat-roulette
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ go/install:
go get -v

go/tools:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.1
go install -tags 'postgres $(MIGRATIONS_SOURCE)' github.com/golang-migrate/migrate/v4/cmd/migrate@v4.18.1
go install gotest.tools/gotestsum@v1.12.0
go install github.com/miniscruff/changie@v1.19.1
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6
go install -tags 'postgres $(MIGRATIONS_SOURCE)' github.com/golang-migrate/migrate/v4/cmd/migrate@v4.18.3
go install gotest.tools/gotestsum@v1.12.3
go install github.com/miniscruff/changie@v1.22.0

go/tidy:
go mod tidy -compat=1.22
go mod tidy -compat=1.23

go/test:
go test -v --cover ./...
Expand All @@ -24,6 +24,9 @@ go/testsum:
go/lint:
golangci-lint run --allow-parallel-runners

go/lint/output-html:
golangci-lint run --allow-parallel-runners > .lint-report.html

go/run:
./scripts/go.sh run

Expand Down
4 changes: 2 additions & 2 deletions cmd/app-manifest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"github.com/akamensky/argparse"
validation "github.com/go-ozzo/ozzo-validation/v4"
"github.com/go-ozzo/ozzo-validation/v4/is"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-retryablehttp"
hclog "github.com/hashicorp/go-hclog"
retryablehttp "github.com/hashicorp/go-retryablehttp"
"github.com/spf13/viper"
"sigs.k8s.io/yaml"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/chat-roulette/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"syscall"

"github.com/akamensky/argparse"
"github.com/bincyber/go-sqlcrypter"
sqlcrypter "github.com/bincyber/go-sqlcrypter"
"github.com/bincyber/go-sqlcrypter/providers/aesgcm"
"go.opentelemetry.io/otel"

Expand Down
2 changes: 1 addition & 1 deletion internal/bot/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func getChannels(ctx context.Context, client *slack.Client, botUserID string) ([
var slackChannels []chatRouletteChannel
for _, i := range resp {
channel := chatRouletteChannel{
ChannelID: i.Conversation.ID,
ChannelID: i.ID,
Inviter: i.Creator,
}
slackChannels = append(slackChannels, channel)
Expand Down
2 changes: 1 addition & 1 deletion internal/bot/event_app_home_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
"time"

"github.com/sebdah/goldie/v2"
goldie "github.com/sebdah/goldie/v2"
"github.com/slack-go/slack"
"github.com/stretchr/testify/require"

Expand Down
2 changes: 1 addition & 1 deletion internal/bot/job_add_channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

"github.com/DATA-DOG/go-sqlmock"
sqlmock "github.com/DATA-DOG/go-sqlmock"
"github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand Down
2 changes: 1 addition & 1 deletion internal/bot/job_add_member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"testing"

"github.com/DATA-DOG/go-sqlmock"
sqlmock "github.com/DATA-DOG/go-sqlmock"
"github.com/hashicorp/go-hclog"
"github.com/slack-go/slack"
"github.com/slack-go/slack/slacktest"
Expand Down
2 changes: 1 addition & 1 deletion internal/bot/job_check_pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func CheckPair(ctx context.Context, db *gorm.DB, client *slack.Client, p *CheckP

logger := hclog.FromContext(ctx).With(
attributes.SlackChannelID, p.ChannelID,
"match_id", p.MatchID,
attributes.MatchID, p.MatchID,
)

logger.Info("checking if pair has met for chat-roulette")
Expand Down
6 changes: 3 additions & 3 deletions internal/bot/job_check_pair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"net/http/httptest"
"testing"

"github.com/DATA-DOG/go-sqlmock"
"github.com/hashicorp/go-hclog"
"github.com/sebdah/goldie/v2"
sqlmock "github.com/DATA-DOG/go-sqlmock"
hclog "github.com/hashicorp/go-hclog"
goldie "github.com/sebdah/goldie/v2"
"github.com/slack-go/slack"
"github.com/slack-go/slack/slacktest"
"github.com/stretchr/testify/assert"
Expand Down
4 changes: 2 additions & 2 deletions internal/bot/job_create_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func CreateMatch(ctx context.Context, db *gorm.DB, client *slack.Client, p *Crea
return errors.Wrap(err, message)
}

logger.Debug("added new match to the database", "match_id", newMatch.ID)
logger.Debug("added new match to the database", attributes.MatchID, newMatch.ID)

// Queue a CREATE_PAIR job for this pair
params := &CreatePairParams{
Expand All @@ -219,7 +219,7 @@ func CreateMatch(ctx context.Context, db *gorm.DB, client *slack.Client, p *Crea
return errors.Wrap(err, message)
}

logger.Info("queued CREATE_PAIR job for this match", "match_id", newMatch.ID)
logger.Info("queued CREATE_PAIR job for this match", attributes.MatchID, newMatch.ID)

return nil
}
Expand Down
6 changes: 3 additions & 3 deletions internal/bot/job_create_matches.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func CreateMatches(ctx context.Context, db *gorm.DB, client *slack.Client, p *Cr

logger := hclog.FromContext(ctx).With(
attributes.SlackChannelID, p.ChannelID,
"round_id", p.RoundID,
attributes.RoundID, p.RoundID,
)

// Wait for member jobs to completed before retrieving participants
Expand Down Expand Up @@ -96,7 +96,7 @@ func CreateMatches(ctx context.Context, db *gorm.DB, client *slack.Client, p *Cr
return err
}

logger.Info("added new match to the database", "match_id", newMatch.ID)
logger.Info("added new match to the database", attributes.MatchID, newMatch.ID)

params := &CreatePairParams{
MatchID: newMatch.ID,
Expand All @@ -114,7 +114,7 @@ func CreateMatches(ctx context.Context, db *gorm.DB, client *slack.Client, p *Cr
return errors.Wrap(err, message)
}

logger.Info("queued CREATE_PAIR job for this match", "match_id", newMatch.ID)
logger.Info("queued CREATE_PAIR job for this match", attributes.MatchID, newMatch.ID)
}

pairsCount := len(matches) - unpaired
Expand Down
4 changes: 2 additions & 2 deletions internal/bot/job_create_matches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"testing"
"time"

"github.com/DATA-DOG/go-sqlmock"
"github.com/hashicorp/go-hclog"
sqlmock "github.com/DATA-DOG/go-sqlmock"
hclog "github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"gorm.io/gorm"
Expand Down
2 changes: 1 addition & 1 deletion internal/bot/job_create_pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func CreatePair(ctx context.Context, db *gorm.DB, client *slack.Client, p *Creat

logger := hclog.FromContext(ctx).With(
attributes.SlackChannelID, p.ChannelID,
"match_id", p.MatchID,
attributes.MatchID, p.MatchID,
)

logger.Info("creating chat-roulette pair")
Expand Down
Loading
Loading