Skip to content

fix: lint push events using event payload commits instead of full history - #20

Merged
richardmoe merged 1 commit into
mainfrom
fix/push-lint-event-payload
Aug 12, 2026
Merged

richardmoe merged 1 commit into
mainfrom
fix/push-lint-event-payload

Conversation

@richardmoe

Copy link
Copy Markdown
Contributor

Problem

On push events in tagless repositories (like ps-terraform-config), semrel lint fell through to ListCommitsSinceTag(nil) which walked the entire commit history. In ps-terraform-config this meant linting all 2927 commits and finding 1705 violations in historical commits that predate conventional commit adoption.

The recent fix in #17 (2992c59) fixed the pull_request path to use GITHUB_BASE_REF→HEAD, but the push path was unchanged. Any consumer repo that:

  • triggers the reusable commitlint workflow on push events, AND
  • has no release tags

would fail every push-event lint check.

Failing run: https://github.com/nrkno/ps-terraform-config/actions/runs/31571178223/job/94033318956?pr=1976

Root cause

msg="lint range" event=push from="" to=HEAD commit_count=2927
...
error="1705 commit violation(s) found"

On push, fromRef resolved to empty (no tags), so lint fell through to the bootstrap path (ListCommitsSinceTag(nil)), linting the entire repository history.

Fix

Read the pushed commits directly from the GitHub event payload (GITHUB_EVENT_PATH) on push events. This validates exactly the commits included in the push, not the entire repository history.

Fallback preserved: when the event payload is unavailable or unreadable, semrel falls back to the previous tag-based range. Explicit --from-ref always overrides automatic detection.

Changes

File Change
internal/env/env.go PushCommit type + loadPushPayload() — parses push event JSON
internal/cli/cli.go Push lint routes through event payload; commitsFromPushPayload() helper
internal/env/env_test.go 2 tests: payload parsing + missing-file graceful degradation
internal/cli/cli_test.go 3 tests: payload used, violations fail, --from-ref overrides
integration_test.go E2E: payload wins over bad repo history
docs/api-reference.md Updated range table + explanatory note
docs/configuration.md Updated --from-ref and GITHUB_EVENT_NAME descriptions
docs/log.md Dated entry
CHANGELOG.md New fix entry

Verification

go test -race -count=1 ./...                    # all OK
go test -race -count=1 -tags integration ./...   # all OK
go vet ./...                                     # clean
go build ./cmd/semrel                            # clean

…tory

On push events in tagless repositories, semrel lint fell through to
ListCommitsSinceTag(nil) which walked the entire commit history,
failing on historical non-conventional commits. This affected every
consumer repo that triggers lint on push events without any release
tags (e.g. ps-terraform-config with 2927 commits / 1705 violations).

Fix by reading the pushed commits directly from the GitHub event
payload (GITHUB_EVENT_PATH) on push events. This validates exactly
the commits included in the push, not the entire repository history.

Fallback behaviour is preserved: when the event payload is unavailable
or unreadable, semrel falls back to the previous tag-based range.
Explicit --from-ref always overrides automatic detection.

Changes:
- env: add PushCommit type and loadPushPayload() to parse push event JSON
- cli: route push-event lint through event payload commits
- cli: add commitsFromPushPayload() helper
- docs: update lint range documentation for push-event semantics
@richardmoe
richardmoe force-pushed the fix/push-lint-event-payload branch from 679b0fd to d3d93d4 Compare August 12, 2026 08:19
@richardmoe
richardmoe merged commit 9ad7b06 into main Aug 12, 2026
5 checks passed
@richardmoe
richardmoe deleted the fix/push-lint-event-payload branch August 12, 2026 08:23
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.

1 participant