diff --git a/step.sh b/step.sh index 2ac65f7..db9d7eb 100755 --- a/step.sh +++ b/step.sh @@ -2,6 +2,11 @@ set -e +# debug log +if [ "${show_debug_logs}" == "yes" ]; then + set -x +fi + red=$'\e[31m' green=$'\e[32m' blue=$'\e[34m' @@ -9,7 +14,7 @@ magenta=$'\e[35m' cyan=$'\e[36m' reset=$'\e[0m' -MERGES=$(git log $(git merge-base --octopus $(git log -1 --merges --pretty=format:%P))..$(git log -1 --merges --pretty=format:%H) --pretty=format:%s) +MERGES=$(git log --pretty=format:%B $(git merge-base --octopus $(git log -1 --merges --pretty=format:%P))..$(git log -1 --merges --pretty=format:%H)) SAVEDIFS=$IFS IFS=$'\n' @@ -18,10 +23,23 @@ MERGES=($MERGES) IFS=$SAVEDIFS -LAST_COMMIT=$(git log -1 --pretty=format:%s) +SAVEDIFS=$IFS +IFS=$'|' + +PROJECT_PREFIXES=($project_prefix) + +IFS=$SAVEDIFS + +LAST_COMMIT=$(git log -1 --pretty=format:%B) +LAST_COMMIT_SUBJECT=$(git log -1 --pretty=format:%s) TASKS=() + +echo "${green}βš™ PROJECT_PREFIXES:${reset}" +printf '%s\n' "${PROJECT_PREFIXES[@]}" +echo "${reset}" + echo "${blue}⚑ ️Last commit:${cyan}" echo $'\t'"πŸ“œ "$LAST_COMMIT echo "${reset}" @@ -37,33 +55,54 @@ then echo "${reset}" - if [ "$LAST_COMMIT" = "${MERGES[0]}" ]; + if [ "$LAST_COMMIT_SUBJECT" = "${MERGES[0]}" ]; then echo "${green}βœ… Merge commit detected. Searching for tasks in merge commits messages...${cyan}" for (( i=0 ; i<${#MERGES[*]} ; ++i )) do echo $'\t'"πŸ“œ "${MERGES[$i]} done + for (( i=0 ; i<${#PROJECT_PREFIXES[*]} ; ++i )) + do + for task in $(echo ${MERGES[*]} | grep "${PROJECT_PREFIXES[$i]}[0-9]{1,5}" -E -o || true | sort -u -r --version-sort) + do + TASKS+=($task) + done + done - for task in $(echo $MERGES | grep "$project_prefix[0-9]{1,5}" -E -o || true | sort -u -r --version-sort) - do - TASKS+=($task) - done else echo "${magenta}β˜‘οΈ Not a merge commit. Searching for tasks in current commit message...${cyan}" echo echo $'\t'"πŸ“œ "$LAST_COMMIT "${reset}" - - for task in $(echo $LAST_COMMIT | grep "$project_prefix[0-9]{1,5}" -E -o || true | sort -u -r --version-sort) - do - TASKS+=($task) - done + + for (( i=0 ; i<${#PROJECT_PREFIXES[*]} ; ++i )) + do + for task in $(echo $LAST_COMMIT | grep "${PROJECT_PREFIXES[$i]}[0-9]{1,5}" -E -o || true | sort -u -r --version-sort) + do + TASKS+=($task) + done + done fi fi +echo "${reset}" +echo "${blue}πŸ“™ Tasks:${reset}" +echo "${TASKS[*]}" +echo "${green}βš™ Removing duplicates:${reset}" +TASKS=($(printf '%s\n' "${TASKS[@]}" | sort -u )) +echo "${TASKS[*]}" +echo "${reset}" + echo "${blue}βœ‰οΈ Comment:${cyan}" +echo "$jira_comment" +echo "${reset}" + +escaped_jira_comment=$(echo "$jira_comment" | perl -pe 's/\n/\\n/g' | sed 's/"/'\''/g' | sed 's/.\{2\}$//') -escaped_jira_comment=$(echo "$jira_comment" | perl -pe 's/\n/\\n/g' | sed 's/.\{2\}$//') + +echo "${blue}βœ‰οΈ Escaped comment:${cyan}" +echo "$escaped_jira_comment" +echo "${reset}" create_comment_data() { diff --git a/step.yml b/step.yml index b0b8888..9eedcc3 100644 --- a/step.yml +++ b/step.yml @@ -70,7 +70,7 @@ inputs: opts: title: "Jira project prefix" description: | - Project prefix to search for tasks. + Project prefix to search for tasks separatad with `|`. e.g. "PROJ-" is_expand: true @@ -105,3 +105,12 @@ inputs: opts: title: "Comment" description: "Comment that will be posted for each found Jira task" + - show_debug_logs: "no" + opts: + category: Debug + title: "Show debug logs?" + description: | + If debug=yes the step will print debug infos + value_options: + - "no" + - "yes"