Fix bugs, replace unreliable git validation#5
Merged
petetomasik merged 19 commits intomainfrom Mar 13, 2026
Merged
Conversation
pzeballos
approved these changes
Mar 12, 2026
Contributor
There was a problem hiding this comment.
LGTM
I would suggest considering splitting the logic (like, validate_env, fetch_branch, check_commit_ancestry), and the log output could be standardized with a prefix for clarity.
For example something like:
PLUGIN_LOG_PREFIX="[branch-commit-plugin]"
log_info() {
echo "$PLUGIN_LOG_PREFIX INFO: $1" >&2
}
log_warn() {
echo "$PLUGIN_LOG_PREFIX WARNING: $1" >&2
}
log_error() {
echo "$PLUGIN_LOG_PREFIX ERROR: $1" >&2
}
validate_env() {
if [[ "${BUILDKITE_SOURCE:-}" != "ui" ]]; then
exit 0
fi
if [[ -z "${BUILDKITE_BRANCH:-}" ]]; then
log_error "BUILDKITE_BRANCH environment variable is not set."
exit 1
fi
if [[ -z "${BUILDKITE_COMMIT:-}" ]]; then
log_error "BUILDKITE_COMMIT environment variable is not set."
exit 1
fi
}
validate_mode() {
local mode="$1"
if [[ "$mode" != "warn" && "$mode" != "strict" ]]; then
log_error "Invalid mode '$mode'. Must be 'warn' or 'strict'."
exit 1
fi
}
...
But it's not a blocker; it's just to reduce complexity, make the script safer (by reducing repetition) and easier to extend
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.
Commit Branch→Branch Commit), description typo, removed invalidrequired: mandatoryfield, addedenum/defaultconstraints tomodePLUGIN_PREFIXfromCOMMIT_BRANCHtoBRANCH_COMMIT, removed 4 unused list functionsset -euo pipefail, quoted all variables (shell injection fix), sourcedlib/plugin.bashviaDIR=pattern, addedBUILDKITE_COMMITvalidation, mode validation, and stderr output. Replaced unreliablegit name-revwithgit merge-base --is-ancestorfor shallow/partial clone compatibility. Handles fetch failures gracefullywith distinct error messages
tests/command.bats(wrong hook, wrong env vars, no stubs), createdtests/post-checkout.batswith 10 passing tests covering both modes, early exits, missing env vars, shallow/non-shallow repos, branch mismatch, and fetch failurestemplatetobranch-commit, shellcheck glob fromlib/**tolib/*.bashmodeas optional withstrictdefault, added shallow clone behavior note, replaced placeholder content with actual developing/contributing sections