Skip to content

Conversation

@pfeifferj
Copy link
Member

@pfeifferj pfeifferj commented Sep 6, 2025

adding pre-commit hooks and a make target to lint the codebase

- Add comprehensive pre-commit configuration for Go, Markdown, and shell scripts
- Include end-of-file fixing, trailing whitespace removal, and Go formatting
- Add lint target to Makefile that runs pre-commit hooks
- Fix end-of-file issues in .pre-commit-config.yaml and www/style.large.css
- Remove trailing whitespace from USAGE.md and DOCS.md
- Format Go code with gofmt in database.go
- Update import aliases with goimports in api.go and errors.go
- Clean up go.mod dependencies with go mod tidy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait why are we deleting old version hashes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhh bumping this

Copy link
Member

@5HT2 5HT2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR! I mostly have a few questions but it otherwise looks good

github.com/go-redis/redis/v8 v8.11.5
github.com/joho/godotenv v1.5.1
github.com/nitishm/go-rejson/v4 v4.2.0
github.com/redis/go-redis/v9 v9.6.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there breaking changes from v8 to v9 / have you tested the following steps basically

  1. running an existing build
  2. upgrading
  3. rebuilding
  4. running new redis client version

I can do it for you if not

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested my deployment and lgtm

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I did however write my own containerfile using vendor deps instead of make deps)

FROM golang:1.23-alpine AS builder

RUN mkdir -p /heartbeat/config
ADD . /heartbeat
WORKDIR /heartbeat

# Install make, git and other build dependencies
RUN apk add --no-cache make git

ENV PATH "${PATH}:${GOPATH}/bin"
RUN go mod tidy
RUN go mod download
RUN go build -ldflags "-X main.gitCommitHash=6034c5f" -o heartbeat .

FROM alpine:3.18
RUN apk add --no-cache ca-certificates
WORKDIR /app

# Copy the binary, config directory, and www assets
COPY --from=builder /heartbeat/heartbeat /app/heartbeat
COPY --from=builder /heartbeat/config /app/config
COPY --from=builder /heartbeat/www /app/www

EXPOSE 8080
CMD ["/app/heartbeat"]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I do actually need to test this on my end.
How does yours connect to DB?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have this as a post-commit hook or a CI lint instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like having the option to lint code myself before committing, and then ci only does a simple pass/fail but doesn't actively lint itself. does this make sense?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these seem kind of excessive like... detect-private-key?

Is this relevant to heartbeat or is that generic "oops the user committed a private key"?

And check-json + check-yaml aren't applicable as we don't have either of those.

Mixed LF is not strictly enforced but is going to be immediately noticable before committing (i.e., your diff is garbled).


Could we please cut this down to just the Go projects? Related, I haven't had formatter errors with qtpl templates I think we can just fmt them too.

I am unable to reproduce the goimports changes btw

Comment on lines +35 to +42
lint:
@echo "Running pre-commit hooks..."
@if command -v pre-commit >/dev/null 2>&1; then \
pre-commit run --all-files; \
else \
echo "pre-commit not found. Install with: pip install pre-commit"; \
exit 1; \
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not want Python dependencies, can we convert whatever the pre-commit hook is supposed to be doing into a POSIX SH / Bash script?

I can write it, just let me know what it should be doing if not obvious.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah totally doable tbh. pre-commit basically just runs linters/formatters on staged files before commit. the main sauce is:

  1. grab staged files w/ git diff --cached --name-only
  2. filter by extension (.go, .md, whatever)
  3. run your tools on those files as per the config file
  4. exit 1 if any fail

the tricky bit pre-commit handles is the stash dance - it stashes unstaged changes so you're ONLY checking what's actually being committed:

@5HT2 5HT2 added the enhancement New feature or request label Sep 7, 2025
@pfeifferj pfeifferj changed the title feature: pre commit hooks for linting feat: pre commit hooks for linting Sep 23, 2025
Copy link
Member

5HT2 commented Oct 16, 2025

Oh shoot bump reminder to myself to do this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhh bumping this

github.com/go-redis/redis/v8 v8.11.5
github.com/joho/godotenv v1.5.1
github.com/nitishm/go-rejson/v4 v4.2.0
github.com/redis/go-redis/v9 v9.6.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I do actually need to test this on my end.
How does yours connect to DB?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these seem kind of excessive like... detect-private-key?

Is this relevant to heartbeat or is that generic "oops the user committed a private key"?

And check-json + check-yaml aren't applicable as we don't have either of those.

Mixed LF is not strictly enforced but is going to be immediately noticable before committing (i.e., your diff is garbled).


Could we please cut this down to just the Go projects? Related, I haven't had formatter errors with qtpl templates I think we can just fmt them too.

I am unable to reproduce the goimports changes btw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants