-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcomplementaryDataLoop.sh
More file actions
148 lines (132 loc) · 4.25 KB
/
complementaryDataLoop.sh
File metadata and controls
148 lines (132 loc) · 4.25 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/sh
appsFile="allApps.csv"
outDir=`realpath output`
inputDir=`realpath output` # We scan back every existing output dirs to update metrics
dbDir=`realpath databases`
tmpDir="/tmp/tracker"
mkdir -p $tmpDir
detector="SmellDetector.jar"
##
# Call Detector for the given application
#
# $1 - application name
# $2 - Detector request type
##
function detectorRequest {
java -Xss512m -jar $detector query -r $2 -db "$dbDir/$1/databases/graph.db" -d true
}
##
# Start the metrics calculation for the given app
#
# $1 - application name
##
function retrieveNbMethodsAndClasses {
appName=$1
echo "# Computing methods and classes for project $appName"
detectorRequest $appName ALLNUMMETHODS
detectorRequest $appName COUNTVAR
detectorRequest $appName COUNTINNER
detectorRequest $appName COUNTASYNC
detectorRequest $appName COUNTVIEWS
}
##
# Returns 1 if the given word is present in the string,
# returns 0 otherwise.
#
# $1 - The word to analyze
# $2 - The string to check
##
function isWordPresent {
echo "$2" | grep -E "$1" | wc -l
}
##
# Retrieve commits and their classification regarding actions
# (fix, refactor, feature, ...)
#
# $1 - application name
# $2 - Application path on GitHub
##
function sortCommitByTypes {
appPath=$2
gitDir="/tmp/$appName-git"
logFile=`realpath "$appName-commits"`
resultFile="$logFile-results"
echo "project,commit,feat,fix,docs,style,refactor,perf,tests,chores" > $resultFile
COMMIT_SEPARATOR="أ"
if [[ ! -d $gitDir ]]; then
git clone https://github.com/$appPath $gitDir
fi
cd $gitDir
git log --topo-order --reverse --pretty="%H$COMMIT_SEPARATOR%s %B" > $logFile
cd -
currentCommit=""
currentContent=""
cat $logFile | while IFS=$COMMIT_SEPARATOR read commit content; do
if [[ -z $commit && -z $content ]];then
echo "Skipping empty line"
else
if [[ -z $content ]]; then
# We have to concatenate some body which has been set to commit
currentContent="$currentContent $commit"
else
if [[ ! -z $currentCommit ]]; then
# We analyze the currently gathered commit
# analyzeCommitLanguage $commit $content
feat=`isWordPresent 'feat' $currentContent`
fix=`isWordPresent 'fix|debug' $currentContent`
docs=`isWordPresent 'docs|documentation' $currentContent`
style=`isWordPresent 'style' $currentContent`
refactor=`isWordPresent 'refactor' $currentContent`
perf=`isWordPresent 'perf' $currentContent`
tests=`isWordPresent 'test' $currentContent`
chores=`isWordPresent 'chore' $currentContent`
# Outputing result
echo "$appPath,$currentCommit,$feat,$fix,$docs,$style,$refactor,$perf,$tests,$chores" >> $resultFile
fi
# We assign the new line to our new current commit
echo "Analyzing new commit $commit"
currentCommit=$commit
currentContent=$content
fi
fi
done
}
##
# Retrieve methods and classes,
# then sort commits with keywords
#
# $1 - application name
# $2 - Application path on GitHub
##
function compute {
appName=$1
appPath=$2
echo "##### Starting process for $appName ####"
tmpOutput="$tmpDir/$appName"
finalOutput="$outDir/$appName"
mkdir -p $tmpOutput; cd $tmpOutput
retrieveNbMethodsAndClasses $appName
sortCommitByTypes $appName $appPath
cd -
echo "# Removing previous result and moving new"
rm -rf $finalOutput
mv $tmpOutput $finalOutput
}
if [[ -f $1 ]]; then
# If we have a file as input argument (csv) we read it and do the given applications
echo "Using input file $1"
cat $1 | while IFS=, read name path; do
if [[ -z $name && -z $path ]];then
echo "Skipping empty line"
else
compute $name $path
fi
done
else
# If no input is given we scan every available inputs
for db in $(ls $inputDir); do
appName=$(basename $db)
appPath=$(grep -- $appName $appsFile | cut -d, -f2)
compute $appName $appPath
done
fi