Skip to content

HYPERFLEET-878 - refactor: rewrite commitlint as Go binary with container support#4

Merged
rafabene merged 3 commits intoopenshift-hyperfleet:mainfrom
rafabene:HYPERFLEET-878
Apr 14, 2026
Merged

HYPERFLEET-878 - refactor: rewrite commitlint as Go binary with container support#4
rafabene merged 3 commits intoopenshift-hyperfleet:mainfrom
rafabene:HYPERFLEET-878

Conversation

@rafabene
Copy link
Copy Markdown
Contributor

@rafabene rafabene commented Apr 9, 2026

Summary

  • Rewrite commit message validator from Node.js to Go for better performance and simplified deployment
  • Add GitHub SDK integration for PR title validation (replaces gh CLI dependency)
  • Migrate from git CLI to go-git SDK, reducing container image from 115 MB to 32.2 MB
  • Support both local pre-commit hooks and Prow CI environments
  • Address all review feedback from PR HYPERFLEET-878 - feat: pre-commit hooks registry with commitlint with Go binary #2:
    • Add shortSHA() helper to prevent panic on 7-char SHAs
    • Refactor validatePR into smaller, testable functions (validateCommits, validatePRTitle, printSummary)
    • Use cmd.Context() for proper cancellation propagation
    • Fix test isolation with t.Setenv() and t.Chdir()
    • Wrap fmt.Sscanf error in GetPRTitleFromEnv
    • Add unit tests for pkg/github/client.go
    • Fix MD040 violations in documentation

Test plan

  • All existing tests pass (go test -v -race ./...)
  • New GitHub client tests cover error paths (invalid repo format, missing env vars, invalid PULL_NUMBER)
  • Build succeeds (go build ./...)
  • Manual: echo "feat: test" | go run ./cmd/hyperfleet-hooks commitlint
  • Manual: pre-commit install --hook-type commit-msg && git commit

Closes HYPERFLEET-878
Supersedes #2

yasun1 added 2 commits April 7, 2026 18:24
…iner support

Replaces the Node.js-based commit validation with a Go implementation for
better performance and simplified cross-component deployment.

- Implement commit message validator in Go with comprehensive test coverage
- Add GitHub SDK integration for PR title validation (replaces gh CLI dependency)
- Support both local pre-commit hooks and Prow CI environments
- Build container image for reuse across all HyperFleet components
- Add commit range detection with PULL_REFS priority for Prow accuracy
- Create unified CLI with --pr flag for CI mode
- Include comprehensive documentation for local and CI usage
- Add Makefile with build, test, lint, and validation targets

update
This refactoring eliminates the external git binary dependency by using
the go-git pure Go implementation, enabling a smaller container image
and improving portability.

Key changes:
- Replace git CLI commands with go-git SDK for commit validation
- Reduce final image size from 115 MB to 32.2 MB using ubi9-micro base
- Add comprehensive unit tests (33.6% coverage) for commit operations
- Fix context.Context anti-pattern in GitHub API client
- Add .dockerignore to optimize build context
- Consolidate repository operations to single open (performance)
- Implement proper error handling with sentinel errors
@rafabene rafabene force-pushed the HYPERFLEET-878 branch 7 times, most recently from 713a4e1 to 29acf93 Compare April 10, 2026 14:12
- Add shortSHA() helper to prevent panic on 7-char SHAs
- Refactor validatePR into validateCommits, validatePRTitle, printSummary
- Use cmd.Context() instead of context.Background() for cancellation
- Fix test isolation with t.Setenv() and t.Chdir()
- Wrap fmt.Sscanf error in GetPRTitleFromEnv
- Add unit tests for pkg/github/client.go
- Fix MD040 violations in docs/commitlint.md
@rh-amarin
Copy link
Copy Markdown

/lgtm

@rafabene rafabene merged commit bfe1cfb into openshift-hyperfleet:main Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants