aboutsummaryrefslogtreecommitdiff
path: root/nvim/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'nvim/scripts')
-rw-r--r--[-rwxr-xr-x]nvim/scripts/sonarqube.sh85
1 files changed, 66 insertions, 19 deletions
diff --git a/nvim/scripts/sonarqube.sh b/nvim/scripts/sonarqube.sh
index ee2148e..0f64524 100755..100644
--- a/nvim/scripts/sonarqube.sh
+++ b/nvim/scripts/sonarqube.sh
@@ -2,31 +2,78 @@
2 2
3set -eu 3set -eu
4 4
5errexit() { 5die() {
6 echo "$@" >&2 6 printf 'Fehler: %s\n' "$*" >&2
7 exit "${2:-1}" 7 exit 1
8} 8}
9 9
10command -v curl >/dev/null || errexit "curl nicht installiert" 10have() {
11command -v jq >/dev/null || errexit "jq nicht installiert" 11 command -v "$1" >/dev/null 2>&1
12}
13
14check_prerequisites() {
15 if ! have curl; then
16 die "curl ist nicht installiert."
17 fi
18
19 if ! have jq; then
20 die "jq ist nicht installiert."
21 fi
22}
12 23
13SONAR_CONFIGURATION_FILE="/opt/homebrew/etc/sonar-scanner.properties" 24get_property() {
14[ -f "$SONAR_CONFIGURATION_FILE" ] || errexit "Keine globale sonarcube Konfiguration gefunden!" 25 key="$1"
26 file="$2"
15 27
16PROJECT_FILE=$(find . -maxdepth 1 -name "sonar-project*.properties" -print -quit) 28 awk -F= -v key="$key" '$1 == key { gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2; exit }' "$file"
17[ -n "$PROJECT_FILE" ] || errexit "Keine sonar-project*.properties Datei gefunden!" 29}
30
31find_project_file() {
32 find . -maxdepth 1 -name "sonar-project*.properties" -print -quit
33}
18 34
19SONAR_TOKEN=$(awk -F= '/^sonar.token=/ {gsub(/^[ \t]+|[ \t]+$/,"",$2); print $2}' "$SONAR_CONFIGURATION_FILE") 35load_sonar_config() {
20[ -n "$SONAR_TOKEN" ] || errexit "Kein 'sonar.token' in $SONAR_CONFIGURATION_FILE vorhanden" 36 config_file="/opt/homebrew/etc/sonar-scanner.properties"
21 37
22SONAR_HOST_URL=$(awk -F= '/^sonar.host.url=/ {gsub(/^[ \t]+|[ \t]+$/,"",$2); print $2}' "$SONAR_CONFIGURATION_FILE") 38 if [ ! -f "$config_file" ]; then
23[ -n "$SONAR_HOST_URL" ] || errexit "Kein 'sonar.host.url' in $SONAR_CONFIGURATION_FILE vorhanden" 39 die "Keine globale Sonarqube-Konfiguration gefunden: $config_file"
40 fi
24 41
25PROJECT_KEY=$(awk -F= '/^sonar.projectKey=/ {gsub(/^[ \t]+|[ \t]+$/,"",$2); print $2}' "$PROJECT_FILE") 42 sonar_token=$(get_property "sonar.token" "$config_file")
26[ -n "$PROJECT_KEY" ] || errexit "Kein 'sonar.projectKey' in $PROJECT_FILE vorhanden" 43 if [ -z "$sonar_token" ]; then
44 die "Kein 'sonar.token' in $config_file vorhanden."
45 fi
27 46
28curl -s \ 47 sonar_host_url=$(get_property "sonar.host.url" "$config_file")
29 -u "$SONAR_TOKEN:" \ 48 if [ -z "$sonar_host_url" ]; then
30 "$SONAR_HOST_URL/api/issues/search?componentKeys=$PROJECT_KEY&statuses=OPEN&ps=500" | 49 die "Kein 'sonar.host.url' in $config_file vorhanden."
31 jq -r '.issues[] | "\(.component | sub("^[^:]+:"; "")):\(.line // 1): [\(.severity)] \(.message | gsub("\n"; " ")) (\(.author))"' 50 fi
51}
52
53load_project_key() {
54 project_file=$(find_project_file)
55 if [ -z "$project_file" ]; then
56 die "Keine sonar-project*.properties Datei gefunden."
57 fi
58
59 project_key=$(get_property "sonar.projectKey" "$project_file")
60 if [ -z "$project_key" ]; then
61 die "Kein 'sonar.projectKey' in $project_file vorhanden."
62 fi
63}
64
65fetch_issues() {
66 curl -s \
67 -u "$sonar_token:" \
68 "$sonar_host_url/api/issues/search?componentKeys=$project_key&statuses=OPEN&ps=500" |
69 jq -r '.issues[] | "\(.component | sub("^[^:]+:"; "")):\(.line // 1): [\(.severity)] \(.message | gsub("\n"; " ")) (\(.author))"'
70}
71
72main() {
73 check_prerequisites
74 load_sonar_config
75 load_project_key
76 fetch_issues
77}
32 78
79main "$@"