-
Notifications
You must be signed in to change notification settings - Fork 6
fix(ci): lint integration commits on dispatch #1806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ScriptedAlchemy
merged 1 commit into
master
from
cursor/batch-merge-commit-hygiene-29ef
Sep 19, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| #!/usr/bin/env bash | ||
| # Lint the commits a CI event is admitting. | ||
| # | ||
| # A master push lints github.event.before..HEAD, which is how an integration | ||
| # merge is judged after it lands. workflow_dispatch is the admission path for | ||
| # that integration branch, so it lints the same not-yet-on-the-default-branch | ||
| # range. Already published history is not rejudged: a dispatch of the default | ||
| # branch has an empty range. | ||
| set -euo pipefail | ||
|
|
||
| script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) | ||
| project_root=$(cd "${script_dir}/.." && pwd) | ||
| repository=${REPOSITORY:-$project_root} | ||
| event=${EVENT_NAME:-} | ||
| head=${HEAD_SHA:-} | ||
| zero_sha=0000000000000000000000000000000000000000 | ||
|
|
||
| if [[ -z $event || -z $head ]]; then | ||
| echo "usage: EVENT_NAME=<push|workflow_dispatch> HEAD_SHA=<sha> [BEFORE_SHA=<sha>] [DEFAULT_BRANCH=<name>] [REPOSITORY=<path>] $0" >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| lint_range() { | ||
| local base=$1 | ||
| node "${script_dir}/lint-commit-range.mjs" --repository "$repository" "$base" "$head" | ||
| } | ||
|
|
||
| lint_root_commit() { | ||
| git -C "$repository" show --no-patch --format=%B "$head" | ( | ||
| cd "$project_root" | ||
| npm run --silent lint:commit -- | ||
| ) | ||
| } | ||
|
|
||
| resolve_default_branch() { | ||
| local branch=$1 | ||
| local remote_ref="refs/remotes/origin/${branch}" | ||
| if git -C "$repository" remote get-url origin >/dev/null 2>&1; then | ||
| git -C "$repository" fetch --no-tags --quiet origin \ | ||
| "+refs/heads/${branch}:${remote_ref}" >/dev/null | ||
| fi | ||
| if git -C "$repository" rev-parse --verify --quiet "$remote_ref" >/dev/null; then | ||
| echo "$remote_ref" | ||
| return 0 | ||
| fi | ||
| if git -C "$repository" rev-parse --verify --quiet "refs/heads/${branch}" >/dev/null; then | ||
| echo "refs/heads/${branch}" | ||
| return 0 | ||
| fi | ||
| echo "commit lint: default branch ${branch} is not available" >&2 | ||
| return 1 | ||
| } | ||
|
|
||
| case "$event" in | ||
| push) | ||
| before=${BEFORE_SHA:-} | ||
| if [[ -z $before ]]; then | ||
| echo "commit lint: push requires BEFORE_SHA" >&2 | ||
| exit 2 | ||
| fi | ||
| if [[ $before == "$zero_sha" ]]; then | ||
| if git -C "$repository" rev-parse --verify --quiet "${head}^" >/dev/null; then | ||
| lint_range "${head}^" | ||
| else | ||
| lint_root_commit | ||
| fi | ||
| else | ||
| lint_range "$before" | ||
| fi | ||
| ;; | ||
| workflow_dispatch) | ||
| default_branch=${DEFAULT_BRANCH:-} | ||
| if [[ -z $default_branch ]]; then | ||
| echo "commit lint: workflow_dispatch requires DEFAULT_BRANCH" >&2 | ||
| exit 2 | ||
| fi | ||
| upstream=$(resolve_default_branch "$default_branch") | ||
| base=$(git -C "$repository" merge-base "$head" "$upstream") | ||
| lint_range "$base" | ||
| ;; | ||
| *) | ||
| echo "commit lint: unsupported event ${event}" >&2 | ||
| exit 2 | ||
| ;; | ||
| esac | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the resolved upstream ref itself as the left side of the lint range. When the dispatch head and default branch have a criss-cross history, they can have multiple best common ancestors;
git merge-base -hexplicitly says that--alloutputs all common ancestors, while this invocation selects only one. Consequently,base..headcan include a different common ancestor that is already published on the default branch and reject the dispatch for its old message, contrary to the stated no-rejudging behavior.upstream..headdirectly selects exactly the commits reachable from the proposed head but not from the default branch.Useful? React with 👍 / 👎.