diff options
| author | Thomas Schmucker <ts@its1.de> | 2026-08-11 22:42:26 +0200 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2026-08-11 22:42:26 +0200 |
| commit | 04faf6e0ee74ad578ae73aba8a53a7673aeb0d81 (patch) | |
| tree | 72f1c5486740a1eba28d9e1bb8b73aed7b4add84 /nvim/scripts/sonarqube.sh | |
| parent | f16823c248dde7485c674067a6a6c6b14d7ddc6c (diff) | |
| parent | a6dadccf839f147a8896910ae1d7d681bbbd1fb5 (diff) | |
| download | dotfiles-04faf6e0ee74ad578ae73aba8a53a7673aeb0d81.tar.gz dotfiles-04faf6e0ee74ad578ae73aba8a53a7673aeb0d81.tar.bz2 dotfiles-04faf6e0ee74ad578ae73aba8a53a7673aeb0d81.zip | |
Merge remote-tracking branch 'origin/rework-sonarqube'
Diffstat (limited to 'nvim/scripts/sonarqube.sh')
| -rw-r--r--[-rwxr-xr-x] | nvim/scripts/sonarqube.sh | 85 |
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 | ||
| 3 | set -eu | 3 | set -eu |
| 4 | 4 | ||
| 5 | errexit() { | 5 | die() { |
| 6 | echo "$@" >&2 | 6 | printf 'Fehler: %s\n' "$*" >&2 |
| 7 | exit "${2:-1}" | 7 | exit 1 |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | command -v curl >/dev/null || errexit "curl nicht installiert" | 10 | have() { |
| 11 | command -v jq >/dev/null || errexit "jq nicht installiert" | 11 | command -v "$1" >/dev/null 2>&1 |
| 12 | } | ||
| 13 | |||
| 14 | check_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 | ||
| 13 | SONAR_CONFIGURATION_FILE="/opt/homebrew/etc/sonar-scanner.properties" | 24 | get_property() { |
| 14 | [ -f "$SONAR_CONFIGURATION_FILE" ] || errexit "Keine globale sonarcube Konfiguration gefunden!" | 25 | key="$1" |
| 26 | file="$2" | ||
| 15 | 27 | ||
| 16 | PROJECT_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 | |||
| 31 | find_project_file() { | ||
| 32 | find . -maxdepth 1 -name "sonar-project*.properties" -print -quit | ||
| 33 | } | ||
| 18 | 34 | ||
| 19 | SONAR_TOKEN=$(awk -F= '/^sonar.token=/ {gsub(/^[ \t]+|[ \t]+$/,"",$2); print $2}' "$SONAR_CONFIGURATION_FILE") | 35 | load_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 | ||
| 22 | SONAR_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 | ||
| 25 | PROJECT_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 | ||
| 28 | curl -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 | |||
| 53 | load_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 | |||
| 65 | fetch_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 | |||
| 72 | main() { | ||
| 73 | check_prerequisites | ||
| 74 | load_sonar_config | ||
| 75 | load_project_key | ||
| 76 | fetch_issues | ||
| 77 | } | ||
| 32 | 78 | ||
| 79 | main "$@" | ||
