Skip to content

Commit

Permalink
run "make fmt" (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
GRbit authored Aug 11, 2024
1 parent 54cb4ea commit 8da11eb
Show file tree
Hide file tree
Showing 42 changed files with 151 additions and 97 deletions.
18 changes: 11 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
help: ## Show this help.
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'

fmt:
gofumpt -l -w -extra .
gci write --custom-order -s standard -s 'Prefix(github.com/ddworken/hishtory)' -s default .

local-install: ## Build and install hishtory locally from the current directory
go build; ./hishtory install

Expand All @@ -9,7 +13,7 @@ forcetest: ## Force running all tests without a test cache
make test

test: ## Run all tests
TZ='America/Los_Angeles' HISHTORY_TEST=1 HISHTORY_SKIP_INIT_IMPORT=1 gotestsum --packages ./... --rerun-fails=10 --rerun-fails-max-failures=30 --format testname --jsonfile /tmp/testrun.json --post-run-command "go run client/posttest/main.go export" -- -p 1 -timeout 90m
TZ='America/Los_Angeles' HISHTORY_TEST=1 HISHTORY_SKIP_INIT_IMPORT=1 gotestsum --packages ./... --rerun-fails=10 --rerun-fails-max-failures=30 --format testname --jsonfile /tmp/testrun.json --post-run-command "go run client/posttest/main.go export" -- -p 1 -timeout 90m

ftest: ## Run a specific test specified via `make ftest FILTER=TestParam/testTui/color`
go clean -testcache
Expand All @@ -23,26 +27,26 @@ release: ## [ddworken only] Release the latest version on Github
expr `cat VERSION` + 1 > VERSION
git add VERSION
git commit -m "Release v0.`cat VERSION`" --no-verify
git push
git push
gh release create v0.`cat VERSION` --generate-notes
git push && git push --tags

build-static: ## [ddworken only] Build the server for hishtory.dev
build-static: ## [ddworken only] Build the server for hishtory.dev
ssh server "cd ~/code/hishtory/; git pull; docker build --build-arg GOARCH=amd64 --tag gcr.io/dworken-k8s/hishtory-static --file backend/web/caddy/Dockerfile ."

build-api: ## [ddworken only] Build the API for api.hishtory.dev
build-api: ## [ddworken only] Build the API for api.hishtory.dev
rm hishtory server || true
docker build --build-arg GOARCH=amd64 --tag gcr.io/dworken-k8s/hishtory-api --file backend/server/Dockerfile .

deploy-static: ## [ddworken only] Build and deploy the server for hishtory.dev
deploy-static: ## [ddworken only] Build and deploy the server for hishtory.dev
deploy-static: build-static
ssh server "docker push gcr.io/dworken-k8s/hishtory-static"
ssh monoserver "cd ~/infra/ && docker compose pull hishtory-static && docker compose rm -svf hishtory-static && docker compose up -d hishtory-static"

deploy-api: ## [ddworken only] Build and deploy the API server for api.hishtory.dev
deploy-api: ## [ddworken only] Build and deploy the API server for api.hishtory.dev
deploy-api: build-api
docker push gcr.io/dworken-k8s/hishtory-api
ssh monoserver "cd ~/infra/ && docker compose pull hishtory-api && docker compose up -d --no-deps hishtory-api"

deploy: ## [ddworken only] Build and deploy all backend services
deploy: ## [ddworken only] Build and deploy all backend services
deploy: release deploy-static deploy-api
1 change: 1 addition & 0 deletions backend/server/internal/database/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/ddworken/hishtory/shared"

"github.com/jackc/pgx/v4/stdlib"
_ "github.com/lib/pq"
sqltrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql"
Expand Down
1 change: 1 addition & 0 deletions backend/server/internal/database/historyentries.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/ddworken/hishtory/shared"

"gorm.io/gorm"
)

Expand Down
2 changes: 1 addition & 1 deletion backend/server/internal/database/usagedata.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (db *DB) UpdateUsageDataForNumEntriesHandled(ctx context.Context, userId, d
return nil
}

func (db *DB) UpdateUsageDataClientVersion(ctx context.Context, userID, deviceID string, version string) error {
func (db *DB) UpdateUsageDataClientVersion(ctx context.Context, userID, deviceID, version string) error {
tx := db.DB.WithContext(ctx).Exec("UPDATE usage_data SET version = ? WHERE user_id = ? AND device_id = ?", version, userID, deviceID)

if tx.Error != nil {
Expand Down
1 change: 1 addition & 0 deletions backend/server/internal/release/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/ddworken/hishtory/shared/testutils"

"github.com/stretchr/testify/require"
)

Expand Down
2 changes: 1 addition & 1 deletion backend/server/internal/server/api_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ddworken/hishtory/backend/server/internal/database"
"github.com/ddworken/hishtory/shared"
"github.com/ddworken/hishtory/shared/ai"

"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

Expand Down Expand Up @@ -195,7 +196,6 @@ func (s *Server) apiGetPendingDumpRequestsHandler(w http.ResponseWriter, r *http

func (s *Server) apiDownloadHandler(w http.ResponseWriter, r *http.Request) {
err := json.NewEncoder(w).Encode(s.updateInfo)

if err != nil {
panic(fmt.Errorf("failed to JSON marshall the update info: %w", err))
}
Expand Down
8 changes: 4 additions & 4 deletions backend/server/internal/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import (
"time"

"github.com/ddworken/hishtory/backend/server/internal/database"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gorm.io/gorm"

"github.com/ddworken/hishtory/client/data"
"github.com/ddworken/hishtory/shared"
"github.com/ddworken/hishtory/shared/testutils"

"github.com/go-test/deep"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gorm.io/gorm"
)

var DB *database.DB
Expand Down
11 changes: 7 additions & 4 deletions backend/server/internal/server/srv.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"strings"
"time"

"github.com/DataDog/datadog-go/statsd"
"github.com/ddworken/hishtory/backend/server/internal/database"
"github.com/ddworken/hishtory/shared"

"github.com/DataDog/datadog-go/statsd"
httptrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/net/http"
)

Expand All @@ -27,8 +28,10 @@ type Server struct {
updateInfo shared.UpdateInfo
}

type CronFn func(ctx context.Context, db *database.DB, stats *statsd.Client) error
type Option func(*Server)
type (
CronFn func(ctx context.Context, db *database.DB, stats *statsd.Client) error
Option func(*Server)
)

func WithStatsd(statsd *statsd.Client) Option {
return func(s *Server) {
Expand Down Expand Up @@ -154,7 +157,7 @@ func (s *Server) handleNonCriticalError(err error) {
}
}

func (s *Server) updateUsageData(ctx context.Context, version string, remoteAddr string, userId, deviceId string, numEntriesHandled int, isQuery bool) error {
func (s *Server) updateUsageData(ctx context.Context, version, remoteAddr, userId, deviceId string, numEntriesHandled int, isQuery bool) error {
if !s.trackUsageData {
return nil
}
Expand Down
15 changes: 8 additions & 7 deletions backend/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"os"
"time"

"github.com/DataDog/datadog-go/statsd"
"github.com/ddworken/hishtory/backend/server/internal/database"
"github.com/ddworken/hishtory/backend/server/internal/release"
"github.com/ddworken/hishtory/backend/server/internal/server"

"github.com/DataDog/datadog-go/statsd"
_ "github.com/lib/pq"
"gorm.io/gorm"
"gorm.io/gorm/logger"
Expand All @@ -21,10 +22,8 @@ const (
StatsdSocket = "unix:///var/run/datadog/dsd.socket"
)

var (
// Filled in via ldflags with the latest released version as of the server getting built
ReleaseVersion string
)
// Filled in via ldflags with the latest released version as of the server getting built
var ReleaseVersion string

func isTestEnvironment() bool {
return os.Getenv("HISHTORY_TEST") != ""
Expand Down Expand Up @@ -104,8 +103,10 @@ func OpenDB() (*database.DB, error) {
return db, nil
}

var LAST_USER_STATS_RUN = time.Unix(0, 0)
var LAST_DEEP_CLEAN = time.Unix(0, 0)
var (
LAST_USER_STATS_RUN = time.Unix(0, 0)
LAST_DEEP_CLEAN = time.Unix(0, 0)
)

func cron(ctx context.Context, db *database.DB, stats *statsd.Client) error {
// Determine the latest released version of hishtory to serve via the /api/v1/download
Expand Down
14 changes: 7 additions & 7 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ import (
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/google/uuid"
"gorm.io/gorm"

"github.com/ddworken/hishtory/client/cmd"
"github.com/ddworken/hishtory/client/data"
"github.com/ddworken/hishtory/client/hctx"
"github.com/ddworken/hishtory/client/lib"
"github.com/ddworken/hishtory/shared"
"github.com/ddworken/hishtory/shared/ai"
"github.com/ddworken/hishtory/shared/testutils"

"github.com/google/go-cmp/cmp"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"gorm.io/gorm"
)

func skipSlowTests() bool {
Expand Down Expand Up @@ -1244,7 +1244,7 @@ func TestStripBashTimePrefix(t *testing.T) {
homedir, err := os.UserHomeDir()
require.NoError(t, err)
f, err := os.OpenFile(path.Join(homedir, data.GetHishtoryPath(), "config.sh"),
os.O_APPEND|os.O_WRONLY, 0644)
os.O_APPEND|os.O_WRONLY, 0o644)
require.NoError(t, err)
defer f.Close()
_, err = f.WriteString("\nexport HISTTIMEFORMAT='%F %T '\n")
Expand All @@ -1263,7 +1263,7 @@ func TestStripBashTimePrefix(t *testing.T) {
homedir, err = os.UserHomeDir()
require.NoError(t, err)
f, err = os.OpenFile(path.Join(homedir, data.GetHishtoryPath(), "config.sh"),
os.O_APPEND|os.O_WRONLY, 0644)
os.O_APPEND|os.O_WRONLY, 0o644)
require.NoError(t, err)
defer f.Close()
_, err = f.WriteString("\nexport HISTTIMEFORMAT='[%c] '\n")
Expand Down Expand Up @@ -2995,7 +2995,7 @@ func testMultipleUsers(t *testing.T, tester shellTester) {
func createSyntheticImportEntries(t testing.TB, numSyntheticEntries int) {
homedir, err := os.UserHomeDir()
require.NoError(t, err)
f, err := os.OpenFile(path.Join(homedir, ".bash_history"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
f, err := os.OpenFile(path.Join(homedir, ".bash_history"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
require.NoError(t, err)
defer f.Close()
for i := 1; i <= numSyntheticEntries; i++ {
Expand Down
1 change: 1 addition & 0 deletions client/cmd/configAdd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/ddworken/hishtory/client/hctx"
"github.com/ddworken/hishtory/client/lib"

"github.com/spf13/cobra"
)

Expand Down
2 changes: 2 additions & 0 deletions client/cmd/configDelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/ddworken/hishtory/client/hctx"
"github.com/ddworken/hishtory/client/lib"

"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -57,6 +58,7 @@ var deleteCustomColumnsCmd = &cobra.Command{
lib.CheckFatalError(hctx.SetConfig(config))
},
}

var deleteDisplayedColumnCommand = &cobra.Command{
Use: "displayed-columns",
Aliases: []string{"displayed-column"},
Expand Down
2 changes: 2 additions & 0 deletions client/cmd/configGet.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/ddworken/hishtory/client/hctx"
"github.com/ddworken/hishtory/client/lib"

"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -41,6 +42,7 @@ var getHighlightMatchesCmd = &cobra.Command{
fmt.Println(config.HighlightMatches)
},
}

var getDefaultFilterCmd = &cobra.Command{
Use: "default-filter",
Short: "The default filter that is applied to all search queries",
Expand Down
1 change: 1 addition & 0 deletions client/cmd/configKeyBindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/ddworken/hishtory/client/hctx"
"github.com/ddworken/hishtory/client/lib"

"github.com/spf13/cobra"
)

Expand Down
2 changes: 2 additions & 0 deletions client/cmd/configSet.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/ddworken/hishtory/client/hctx"
"github.com/ddworken/hishtory/client/lib"

"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -102,6 +103,7 @@ var setEnableAiCompletionCmd = &cobra.Command{
lib.CheckFatalError(hctx.SetConfig(config))
},
}

var setPresavingCmd = &cobra.Command{
Use: "presaving",
Short: "Enable 'presaving' of shell entries that never finish running",
Expand Down
1 change: 1 addition & 0 deletions client/cmd/enableDisable.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/ddworken/hishtory/client/hctx"
"github.com/ddworken/hishtory/client/lib"

"github.com/spf13/cobra"
)

Expand Down
1 change: 1 addition & 0 deletions client/cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/ddworken/hishtory/client/hctx"
"github.com/ddworken/hishtory/client/lib"

"github.com/spf13/cobra"
)

Expand Down
13 changes: 8 additions & 5 deletions client/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ import (
"github.com/ddworken/hishtory/client/hctx"
"github.com/ddworken/hishtory/client/lib"
"github.com/ddworken/hishtory/shared"

"github.com/google/uuid"
"github.com/spf13/cobra"
"gorm.io/gorm"
)

var offlineInit *bool
var forceInit *bool
var offlineInstall *bool
var skipConfigModification *bool
var (
offlineInit *bool
forceInit *bool
offlineInstall *bool
skipConfigModification *bool
)

var installCmd = &cobra.Command{
Use: "install",
Expand Down Expand Up @@ -581,7 +584,7 @@ func stripLines(filePath, lines string) error {
ret += "\n"
}
}
return os.WriteFile(filePath, []byte(ret), 0644)
return os.WriteFile(filePath, []byte(ret), 0o644)
}

func setup(userSecret string, isOffline bool) error {
Expand Down
1 change: 1 addition & 0 deletions client/cmd/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/ddworken/hishtory/client/data"
"github.com/ddworken/hishtory/client/hctx"
"github.com/ddworken/hishtory/shared/testutils"

"github.com/stretchr/testify/require"
)

Expand Down
3 changes: 2 additions & 1 deletion client/cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ddworken/hishtory/client/hctx"
"github.com/ddworken/hishtory/client/lib"
"github.com/ddworken/hishtory/client/tui"

"github.com/fatih/color"
"github.com/muesli/termenv"
"github.com/rodaine/table"
Expand Down Expand Up @@ -171,7 +172,7 @@ func DisplayResults(ctx context.Context, results []*data.HistoryEntry, numResult

numRows := 0

var seenCommands = make(map[string]bool)
seenCommands := make(map[string]bool)

for _, entry := range results {
if config.FilterDuplicateCommands && entry != nil {
Expand Down
1 change: 1 addition & 0 deletions client/cmd/redact.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ddworken/hishtory/client/hctx"
"github.com/ddworken/hishtory/client/lib"
"github.com/ddworken/hishtory/shared"

"github.com/spf13/cobra"
)

Expand Down
1 change: 1 addition & 0 deletions client/cmd/reupload.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"github.com/ddworken/hishtory/client/hctx"
"github.com/ddworken/hishtory/client/lib"

"github.com/spf13/cobra"
)

Expand Down
Loading

0 comments on commit 8da11eb

Please sign in to comment.