Skip to content

Instantly share code, notes, and snippets.

@msreekm
Last active February 19, 2016 01:12
Show Gist options
  • Save msreekm/40c9107e45d68c2d3f60 to your computer and use it in GitHub Desktop.
Save msreekm/40c9107e45d68c2d3f60 to your computer and use it in GitHub Desktop.
sfdc-precommit-jira-validation.sh
#!/usr/bin/env bash
author- Sreekumar menon
usage - validates if all jira ticket numbers are marked as "Verififed" starting from a selected commit date, this script extract jira ticket numbers from git commit and query jira for verified status.
params -
$1 - start date of commit "2016-02-15"
$2 - jira username
$3 - jira password
$4- jira host
//function to parse json key and value
function jsonValue() {
KEY=$1
num=$2
awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'$KEY'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p
}
start_date=$1 # "2016-02-15"
arr=()
for commit in $(git log --since="$start_date" --oneline)
do
#echo $commit
jira=($(echo $commit | grep -oi 'CRM-[0-9]*' ) )
#echo $commit | grep -oi 'CRM-[0-9]*'
#echo $jira | xargs
arr+=($jira)
done
echo "all jira tickets since $start_date"
echo ${arr[@]}
echo "unique tickets since $start_date"
echo "*********************************"
#newArr= $("${arr[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')
unique_sorted_list=($(printf "%s\n" "${arr[@]}" | sort -u))
echo ${unique_sorted_list[@]}
echo "Checking Jira ticket status ....."
#loop through each element in array
for ticket in "${unique_sorted_list[@]}"
do
#echo $ticket
jira_status=($(echo `curl -u $2:$3 http://$4/rest/api/2/issue/$ticket?fields=status 2>&1` | jsonValue name 1))
#echo $jira_status
if [ $jira_status == 'Verified' ]; then
echo "$ticket ready for deployment ,status is $jira_status"
else
echo "unable to proceed with deployment, $ticket marked as $jira_status"
fi
# do whatever on $i
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment