Skip to content

Instantly share code, notes, and snippets.

@varhub
Last active August 29, 2015 14:15
Show Gist options
  • Save varhub/4599f07766a0fe8dcb1f to your computer and use it in GitHub Desktop.
Save varhub/4599f07766a0fe8dcb1f to your computer and use it in GitHub Desktop.
JdeRobot issue population (1/2): an script to extract possible issues from history.
#!/bin/sh
set -e
set -u
GREP_ISSUE_NUMBER='[#\[][0-9][0-9]*'
SEPARATOR='\t\t\t'
# retrive full log
git log --full-history --all --oneline --pretty=tformat:"%s" > git.messages
# one issue number has a typo. Named 1180 instead 118. this fix it.
cat git.messages | sed -e 's,#1180,#118,' > git.fixed
# take only commits that have the issue number pattern
cat git.fixed | grep -e $GREP_ISSUE_NUMBER > git.issues
# create a numeric index for each issue (using issue number as preffix)
echo -n > git.number
cat git.issues | while read line
do
number=$(echo $line | grep -o $GREP_ISSUE_NUMBER | grep -o '[0-9]*')
echo "$number$SEPARATOR$line" >> git.number
done
# there are commits with the same issue number. This line will drop duplicate numbers
# this process could drop useful messages in favor of worse messages.
cat git.number | sort -n | uniq --check-chars=3 > git.uniq
# final step: format issue messages for upload it.
# this also create stub issues for missed issue numbers
echo -n > git.upload
N_ISSUE=1
cat git.uniq | while read line
do
number=$(echo $line | cut -d' ' -f1)
while true
do
if [ $N_ISSUE -eq $number ]; then
echo "$line" | awk -F"$SEPARATOR" '{print $2}' >> git.upload
N_ISSUE=$((N_ISSUE + 1))
break
else
echo issue $N_ISSUE >> git.upload
N_ISSUE=$((N_ISSUE + 1))
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment