Enhance Jenkins integration of safe templates take 2
- Handle case when no files are linted - Skip deleted files for safe commit script - Add verbose options for safe commit
This commit is contained in:
@@ -19,6 +19,7 @@ show_help() {
|
||||
echo " -m, --main-branch=COMMIT Run against files changed between the"
|
||||
echo " current branch and this commit."
|
||||
echo " Defaults to origin/master."
|
||||
echo " -v, --verbose Output details of git commands run."
|
||||
echo ""
|
||||
echo "This scripts does not give a grand total. Be sure to check for"
|
||||
echo "0 violations on each file."
|
||||
@@ -30,12 +31,25 @@ show_help() {
|
||||
|
||||
}
|
||||
|
||||
show_verbose() {
|
||||
echo "Files linted is based on the following:"
|
||||
echo "- Current commit: ${current_branch_hash}"
|
||||
echo "- Main commit: ${MAIN_COMMIT}"
|
||||
echo "- Merge base command: ${merge_base_command}"
|
||||
echo "- Merge base: ${merge_base}"
|
||||
echo "- Diff command: ${diff_command}"
|
||||
|
||||
}
|
||||
|
||||
for i in "$@"; do
|
||||
case $i in
|
||||
-m=*|--main-branch=*)
|
||||
MAIN_COMMIT="${i#*=}"
|
||||
shift # past argument=value
|
||||
;;
|
||||
-v|--verbose)
|
||||
VERBOSE=true
|
||||
;;
|
||||
-h|--help|*)
|
||||
# help or unknown option
|
||||
show_help
|
||||
@@ -51,11 +65,24 @@ if [ -z "${MAIN_COMMIT+x}" ]; then
|
||||
MAIN_COMMIT="origin/master"
|
||||
fi
|
||||
|
||||
merge_base=`git merge-base "$current_branch_hash" "$MAIN_COMMIT"`
|
||||
diff_files=`git diff --name-only "$current_branch_hash" "$merge_base"`
|
||||
merge_base_command="git merge-base $current_branch_hash $MAIN_COMMIT"
|
||||
merge_base=$(${merge_base_command})
|
||||
diff_command="git diff --name-only --diff-filter=ACM $current_branch_hash $merge_base"
|
||||
diff_files=$(${diff_command})
|
||||
|
||||
for f in $diff_files; do
|
||||
if [ "$diff_files" = "" ]; then
|
||||
# When no files are found, automatically display verbose details to help
|
||||
# understand why.
|
||||
show_verbose
|
||||
echo ""
|
||||
echo "Linting $f:"
|
||||
./scripts/safe_template_linter.py $f
|
||||
done
|
||||
echo "No files linted."
|
||||
else
|
||||
if [ ${VERBOSE} ] ; then
|
||||
show_verbose
|
||||
fi
|
||||
for f in $diff_files; do
|
||||
echo ""
|
||||
echo "Linting $f:"
|
||||
./scripts/safe_template_linter.py $f
|
||||
done
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user