From b7c251e39feefd1f4d9af86e860a8d3eda2fe008 Mon Sep 17 00:00:00 2001 From: Zak Betz Date: Fri, 25 Mar 2016 16:56:05 -0600 Subject: [PATCH] Fix garbled message for multiple commits by making each one an attachment. Fixes issue 24. --- git-slack-hook | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/git-slack-hook b/git-slack-hook index 558c1c3..8ade1a9 100755 --- a/git-slack-hook +++ b/git-slack-hook @@ -243,15 +243,26 @@ function notify() { fi # Process the log and escape double quotes; assuming for now that committer names don't have five semicolons in them - log_out=$( git log --pretty=format:"%cN;;;;;${formattedurl}${commitformat}" $countarg ${start}..${end} \ - | sed ':a;N;$!ba;s/\n/\\n/g' \ - | sed -e 's/\\/\\\\/g' \ - | sed -e 's/"/\\"/g' \ - | sed -e 's/\(.*\);;;;;\(.*\)/{"title":"\1","value":"\2","short":false},/' ) + if $onlylast; then + log_out=$( git log --pretty=format:"%cN;;;;;${formattedurl}${commitformat}" $countarg ${start}..${end} \ + | sed ':a;N;$!ba;s/\n/\\n/g' \ + | sed -e 's/\\/\\\\/g' \ + | sed -e 's/"/\\"/g' \ + | sed -e 's/\(.*\);;;;;\(.*\)/{"title":"\1","value":"\2","short":false},/' ) + fields=${log_out%?} + attachments="[{ \"fallback\" : \"${header}\", \"color\" : \"good\", \"fields\" : [${fields}]}]" - fields=${log_out%?} + else + log_out=$( git log --pretty=format:"%cN;;;;;${formattedurl}${commitformat}" $countarg ${start}..${end} \ + | sed ':a;N;$!ba;s/\n+/\\n/g' \ + | sed -e 's/\\/\\\\/g' \ + | sed -e 's/"/\\"/g' \ + | sed -e 's/\(.*\);;;;;\(.*\)/{ \"fallback\" : \"\", \"color\" : \"good\", \"fields\" : [{"title":"\1","value":"\2","short":false},]},/' \ + | sed -e 's/,\]/]/' ) + + attachments="[${log_out%?}]" + fi - attachments="[{ \"fallback\" : \"${header}\", \"color\" : \"good\", \"fields\" : [${fields}]}]" fi if [ -n "${attachments}" ] && [[ "${attachments}" != "" ]]; then