#!/bin/sh set -eu die() { printf 'Fehler: %s\n' "$*" >&2 exit 1 } have() { command -v "$1" >/dev/null 2>&1 } check_prerequisites() { if ! have curl; then die "curl ist nicht installiert." fi if ! have jq; then die "jq ist nicht installiert." fi } get_property() { key="$1" file="$2" awk -F= -v key="$key" '$1 == key { gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2; exit }' "$file" } find_project_file() { find . -maxdepth 1 -name "sonar-project*.properties" -print -quit } load_sonar_config() { config_file="/opt/homebrew/etc/sonar-scanner.properties" if [ ! -f "$config_file" ]; then die "Keine globale Sonarqube-Konfiguration gefunden: $config_file" fi sonar_token=$(get_property "sonar.token" "$config_file") if [ -z "$sonar_token" ]; then die "Kein 'sonar.token' in $config_file vorhanden." fi sonar_host_url=$(get_property "sonar.host.url" "$config_file") if [ -z "$sonar_host_url" ]; then die "Kein 'sonar.host.url' in $config_file vorhanden." fi } load_project_key() { project_file=$(find_project_file) if [ -z "$project_file" ]; then die "Keine sonar-project*.properties Datei gefunden." fi project_key=$(get_property "sonar.projectKey" "$project_file") if [ -z "$project_key" ]; then die "Kein 'sonar.projectKey' in $project_file vorhanden." fi } fetch_issues() { curl -s \ -u "$sonar_token:" \ "$sonar_host_url/api/issues/search?componentKeys=$project_key&statuses=OPEN&ps=500" | jq -r '.issues[] | "\(.component | sub("^[^:]+:"; "")):\(.line // 1): [\(.severity)] \(.message | gsub("\n"; " ")) (\(.author))"' } main() { check_prerequisites load_sonar_config load_project_key fetch_issues } main "$@"