Skip to content
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

Feature/support for multiple projects #1

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 52 additions & 13 deletions step.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@

set -e

# debug log
if [ "${show_debug_logs}" == "yes" ]; then
set -x
fi

red=$'\e[31m'
green=$'\e[32m'
blue=$'\e[34m'
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'
Expand All @@ -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}"
Expand All @@ -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()
{
Expand Down
11 changes: 10 additions & 1 deletion step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"