forked from andeemarks/aeolian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
go-gh.sh
executable file
·136 lines (111 loc) · 4.1 KB
/
go-gh.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env bash
function cleanup {
rm -rf "$WORK_DIR"
echo -e "\033[33mDeleted temp working directory $WORK_DIR\033[0m"
}
function check-deps() {
if ! which abc2midi &> /dev/null; then
>&2 echo “Error: Please install abc2midi and make sure it is in your path”
exit 1
fi
if ! which lein &> /dev/null; then
>&2 echo “Error: Please install Leinginen and make sure it is in your path”
exit 1
fi
if ! which java &> /dev/null; then
>&2 echo “Error: Please install Java and make sure it is in your path”
exit 1
fi
if ! which timidity &> /dev/null; then
>&2 echo “Error: Please install timidity and make sure it is in your path”
exit 1
fi
}
function check-usage() {
if [[ $# -lt 2 ]]; then
>&2 echo "Usage: go-gh.sh <github-user> <github-repo>"
exit 1
fi
}
function clone-repo() {
echo -e "\033[33mCloning repo to $WORK_DIR...\033[0m"
cd $WORK_DIR
git clone -q https://github.com/$GITHUB_USER/$GITHUB_REPO.git
}
function collect-commit-info() {
echo -e "\033[33mFind commit history for each Java file...\033[0m"
pushd $WORK_DIR/$GITHUB_REPO >/dev/null
find . -regex $SOURCE_FILE_RE | xargs -n1 git blame -f -t -e | awk -v PREFIX=${WORK_DIR}/${GITHUB_REPO}/ -F "[ ()]+" '{print "{ :source-file \"" PREFIX $2 "#"$6 "\" :author \"" $3 "\" :timestamp " $4 " }" }' > ${WORK_DIR}/blames.txt
popd >/dev/null
}
function collect-duplication-metrics() {
echo -e "\033[34mGenerating Checkstyle duplication metrics...\033[0m"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CHECKSTYLEDIR=$DIR/resources
java -jar $CHECKSTYLEDIR/simian-2.4.0.jar -threshold=4 -failOnDuplication- -excludes="**/test/**/*.java" $WORK_DIR/**/*.java | tail -3 | head -2 > ${WORK_DIR}/duplication.txt
DUPLICATESTATS=`cat ${WORK_DIR}/duplication.txt`
TOTALDUPLINESRE='Found ([0-9]+).*'
TOTALLINESRE='Processed a total of ([0-9]+).*'
[[ "${DUPLICATESTATS}" =~ ${TOTALDUPLINESRE} ]]
TOTALDUPLINES=${BASH_REMATCH[1]}
[[ "${DUPLICATESTATS}" =~ ${TOTALLINESRE} ]]
TOTALLINES=${BASH_REMATCH[1]}
}
function collect-checkstyle-metrics() {
echo -e "\033[33mRunning metrics on all Java files...\033[0m"
find $WORK_DIR -regex $SOURCE_FILE_RE -exec ./go.sh '{}' $WORK_DIR \;
}
function join-all-metrics() {
UBERMETRICSFILE=${WORK_DIR}/${GITHUB_REPO}.metrics
echo -e "\033[33mBuilding uber metrics file...\033[0m"
cat $WORK_DIR/*.metrics.all > ${UBERMETRICSFILE}
echo -e "\033[33mJoining metrics file with Git commit history...\033[0m"
join -j 3 -a 2 <(sort -k 1b,3 ${WORK_DIR}/blames.txt) <(sort -k 1b,3 ${UBERMETRICSFILE}) | sort -V | cut -d " " -f1,2,3,8,9,10 --complement > ${UBERMETRICSFILE}.history
sed -i 's/^/{/' ${UBERMETRICSFILE}.history
}
function generate-abc() {
echo -e "\033[33mGenerating ABC notation...\033[0m"
source ./gen-abc.sh
}
function generate-midi() {
ABCFILE=${UBERMETRICSFILE}.history.abc
MIDIFILE=${UBERMETRICSFILE}.mid
echo -e "\033[33mGenerating MIDI...\033[0m"
abc2midi ${ABCFILE} -s -o ${MIDIFILE} > /dev/null
MIDIARCHIVEDIR=${DIR}/archive/midi
ABCARCHIVEDIR=${DIR}/archive/abc
mkdir -p ${MIDIARCHIVEDIR}
mkdir -p ${ABCARCHIVEDIR}
echo -e "\033[33mArchiving generated files...\033[0m"
TIMESTAMP=$( date +"%Y-%m-%d_%H-%M-%S" )
cp ${MIDIFILE} ${MIDIARCHIVEDIR}/${GITHUB_REPO}.${TIMESTAMP}.mid
cp ${ABCFILE} ${ABCARCHIVEDIR}/${GITHUB_REPO}.${TIMESTAMP}.abc
}
function play-midi() {
echo -e "\033[33mPlaying MIDI...\033[0m"
timidity ${MIDIFILE} > /dev/null
echo -e "\033[33mTo play again: timidity ${MIDIARCHIVEDIR}/${GITHUB_REPO}.${TIMESTAMP}.mid > /dev/null\033[0m"
}
set -e
set -o pipefail
set -o nounset
check-usage $@
check-deps
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
GITHUB_USER=$1
GITHUB_REPO=$2
echo -e "\033[33mChecking GitHub for repo '$GITHUB_REPO' for user '$GITHUB_USER'...\033[0m"
WORK_DIR=`mktemp -d -p "$DIR/target"`
BIN_DIR=$DIR
SOURCE_FILE_RE=".*[^Test]\.java"
clone-repo
cd $BIN_DIR
collect-commit-info
collect-duplication-metrics
collect-checkstyle-metrics
join-all-metrics
generate-abc
generate-midi
play-midi
# register the cleanup function to be called on the EXIT signal
trap cleanup EXIT