Suggested Improvements
1. Handle Case Where No .ST-pre-commit-config.yaml Files Exist
In get_smoked_config_paths, if no .ST-pre-commit-config.yaml files are found, the script exits immediately:
paths=$(git ls-files | grep '\.ST-pre-commit-config\.yaml$') || { echo "No .ST-pre-commit-config.yaml files found!"; exit 1; }
Improvement:
Use lm "ERROR" for consistent logging:
if [[ -z "$paths" ]]; then
lm "ERROR" "❌ No .ST-pre-commit-config.yaml files found! Exiting."
exit 1
fi
2. Improved Error Message for Missing Chunks
In compare_repo_chunks, if the chunks don't match, it logs both the expected and found chunks. For readability, format them nicely:
lm "DEBUG" "Expected chunk: $(echo "$pre_commit_chunk" | sed 's/^/ /')"
lm "DEBUG" "Found chunk: $(echo "$st_pre_commit_chunk" | sed 's/^/ /')"
This indents the multi-line chunks to make them easier to read.
3. Add a Final Summary Report
Add a summary of the results after compare_repo_chunks to provide a clear overview:
summary_report() {
local total_repos="${#repo_matches[@]}"
local successful=0
local failed=0
for key in "${!repo_matches[@]}"; do
IFS=',' read -r _ count <<< "${repo_matches[$key]}"
if (( count == 1 )); then
successful=$((successful + 1))
else
failed=$((failed + 1))
fi
done
lm "INFO" "### Summary Report:"
lm "INFO" "- **Total repos checked:** $total_repos"
lm "INFO" "- **Successful matches:** $successful"
lm "INFO" "- **Failed or missing matches:** $failed"
}
Call it at the end of main():
4. Ensure Output is Sorted Consistently
When looping over arrays (like repo_matches), consider sorting the keys to ensure consistent output:
for key in $(printf "%s\n" "${!repo_matches[@]}" | sort); do
...
done
5. Add Edge Case Logging for Missing repos Block
If .pre-commit-config.yaml doesn’t contain a repos: block, log an error:
if [[ -z "$repos_chunk" ]]; then
lm "ERROR" "❌ No repos found in .pre-commit-config.yaml! Exiting."
exit 1
fi
Potential New Features
1. Auto-Fix Mode
Optionally replace mismatched chunks if --auto-fix is passed:
if [[ "$AUTO_FIX" == true ]]; then
cp "$path" "$path.bak"
awk -v repo_line="$key" ... > "$path"
lm "INFO" "Fixed mismatch for $key and created backup: $path.bak"
fi
2. Filter for Specific Repo
Add a --filter option to only check specific repos:
./main.sh --log-level DEBUG --filter "https://github.com/google/yamlfmt"
Suggested Improvements
1. Handle Case Where No
.ST-pre-commit-config.yamlFiles ExistIn
get_smoked_config_paths, if no.ST-pre-commit-config.yamlfiles are found, the script exits immediately:Improvement:
Use
lm "ERROR"for consistent logging:2. Improved Error Message for Missing Chunks
In
compare_repo_chunks, if the chunks don't match, it logs both the expected and found chunks. For readability, format them nicely:This indents the multi-line chunks to make them easier to read.
3. Add a Final Summary Report
Add a summary of the results after
compare_repo_chunksto provide a clear overview:Call it at the end of
main():4. Ensure Output is Sorted Consistently
When looping over arrays (like
repo_matches), consider sorting the keys to ensure consistent output:5. Add Edge Case Logging for Missing
reposBlockIf
.pre-commit-config.yamldoesn’t contain arepos:block, log an error:Potential New Features
1. Auto-Fix Mode
Optionally replace mismatched chunks if
--auto-fixis passed:2. Filter for Specific Repo
Add a
--filteroption to only check specific repos:./main.sh --log-level DEBUG --filter "https://github.com/google/yamlfmt"