-
Notifications
You must be signed in to change notification settings - Fork 11
/
common.sh
71 lines (61 loc) · 1.5 KB
/
common.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
### BEGIN_COMMON
#!/usr/bin/env bash
fatal() {
echo fatal: "$@" >&2
exit 1
}
info() {
echo info: "$@"
}
print_files() {
[[ $# != 1 ]] || return
info $1
shift
for i; do
info " $i"
done
}
if [ "$SKIPSONARLINT" ]; then
info "SKIPSONARLINT is set, skipping verification..."
exit 0
fi
if ! type sonarlint &>/dev/null; then
echo "fatal: cannot find 'sonarlint' on PATH"
echo "See setup steps in https://github.com/janosgyerik/sonarlint-git-hooks"
exit 1
fi
run() {
args=()
sources=()
tests=()
for file; do
if ! [ -f "$file" ]; then
info "skip deleted file: $file"
continue
fi
if [[ $file == *src/* ]]; then
if [[ $file == *[tT]est* ]]; then
tests+=("$file")
args+=(--tests "$file")
else
sources+=("$file")
fi
args+=(--src "$file")
continue
fi
info "skip unknown file: $file"
done
if [ ${#sources} = 0 -a ${#tests} = 0 ]; then
info no files to analyze
return
fi
print_files "source files to analyze:" "${sources[@]}"
print_files "test files to analyze:" "${tests[@]}"
info "analyzing..."
issues=$(sonarlint "${args[@]}" | sed -ne '/SonarLint Report/,/^---/p' -e '/Report generated/p')
echo "$issues"
if ! [[ $issues == *"No issues to display"* ]]; then
fatal "hook abort: some analyses have failed"
fi
}
### END_COMMON