HYPERFLEET-878 - refactor: rewrite commitlint as Go binary with container support#4
Merged
rafabene merged 3 commits intoopenshift-hyperfleet:mainfrom Apr 14, 2026
Merged
Conversation
…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
713a4e1 to
29acf93
Compare
- 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
29acf93 to
1745321
Compare
|
/lgtm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
shortSHA()helper to prevent panic on 7-char SHAsvalidatePRinto smaller, testable functions (validateCommits,validatePRTitle,printSummary)cmd.Context()for proper cancellation propagationt.Setenv()andt.Chdir()fmt.Sscanferror inGetPRTitleFromEnvpkg/github/client.goTest plan
go test -v -race ./...)go build ./...)echo "feat: test" | go run ./cmd/hyperfleet-hooks commitlintpre-commit install --hook-type commit-msg && git commitCloses HYPERFLEET-878
Supersedes #2