-
Notifications
You must be signed in to change notification settings - Fork 0
feat: consulta priority direto do XML ao inves de marcadores P1/P2 no violationMessage #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ab51fa5
d0d7365
59e73fc
40ac077
dcb4116
4f5695c
9befd71
33f1f1d
8a3e0e9
b4a22bc
14fcf56
bb8fcaf
f9232ab
0d57370
73a1ec9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,28 +1,30 @@ | ||||||
| #!/bin/sh | ||||||
| set -e | ||||||
|
|
||||||
| # ========== ARQUIVOS TEMPORÁRIOS ========== | ||||||
| CODENARC_RESULT="result.txt" | ||||||
| LINE_VIOLATIONS="line_violations.txt" | ||||||
| FILE_VIOLATIONS="file_violations.txt" | ||||||
| VIOLATIONS_FLAG="/tmp/found_violations.txt" | ||||||
| ALL_DIFF="/tmp/all_diff.txt" | ||||||
| CHANGED_LINES_CACHE="/tmp/changed_lines.txt" | ||||||
| CHANGED_FILES_CACHE="/tmp/changed_files.txt" | ||||||
| TMP_VIOLATIONS="/tmp/violations.tmp" | ||||||
|
|
||||||
| cleanup_temp_files() { | ||||||
| rm -f "$CODENARC_RESULT" "$LINE_VIOLATIONS" "$FILE_VIOLATIONS" "$VIOLATIONS_FLAG" \ | ||||||
| "$ALL_DIFF" "$CHANGED_LINES_CACHE" "$CHANGED_FILES_CACHE" \ | ||||||
| "${FILE_VIOLATIONS}.formatted" >/dev/null 2>&1 | ||||||
| "${FILE_VIOLATIONS}.formatted" "$TMP_VIOLATIONS" >/dev/null 2>&1 | ||||||
| } | ||||||
|
|
||||||
| trap 'cleanup_temp_files' EXIT | ||||||
|
|
||||||
| # ========== ETAPA 1 - EXECUTA CODENARC ========== | ||||||
| run_codenarc() { | ||||||
| report="${INPUT_REPORT:-compact:stdout}" | ||||||
| includes_arg="" | ||||||
|
|
||||||
| [ -n "$INPUT_SOURCE_FILES" ] && includes_arg="-includes=${INPUT_SOURCE_FILES}" | ||||||
|
|
||||||
| echo "🔍 Executando CodeNarc..." | ||||||
| java -jar /lib/codenarc-all.jar \ | ||||||
| -report="$report" \ | ||||||
|
|
@@ -32,14 +34,15 @@ run_codenarc() { | |||||
| > "$CODENARC_RESULT" | ||||||
| } | ||||||
|
|
||||||
| # ========== ETAPA 2 - REVIEWDOG ========== | ||||||
| run_reviewdog_with_config() { | ||||||
| input_file="$1" | ||||||
| efm="$2" | ||||||
| reporter="$3" | ||||||
| name="$4" | ||||||
| filter_mode="$5" | ||||||
| level="$6" | ||||||
|
|
||||||
| < "$input_file" reviewdog \ | ||||||
| -efm="$efm" \ | ||||||
| -reporter="$reporter" \ | ||||||
|
|
@@ -57,16 +60,16 @@ separate_violations() { | |||||
|
|
||||||
| run_reviewdog() { | ||||||
| echo "📤 Enviando resultados para reviewdog..." | ||||||
|
|
||||||
| separate_violations | ||||||
|
|
||||||
| if [ -s "$LINE_VIOLATIONS" ]; then | ||||||
| echo "📤 Enviando violações line-based (${INPUT_REPORTER:-github-pr-check})..." | ||||||
| run_reviewdog_with_config "$LINE_VIOLATIONS" "%f:%l:%m" \ | ||||||
| "${INPUT_REPORTER:-github-pr-check}" "codenarc" \ | ||||||
| "${INPUT_FILTER_MODE}" "${INPUT_LEVEL}" | ||||||
| fi | ||||||
|
|
||||||
| if [ -s "$FILE_VIOLATIONS" ]; then | ||||||
| true > "${FILE_VIOLATIONS}.formatted" | ||||||
| while read -r violation; do | ||||||
|
|
@@ -76,33 +79,38 @@ run_reviewdog() { | |||||
| echo "$violation" | sed 's/:null:/::/' | ||||||
| fi | ||||||
| done < "$FILE_VIOLATIONS" > "${FILE_VIOLATIONS}.formatted" | ||||||
|
|
||||||
| if [ "${INPUT_REPORTER}" = "local" ]; then | ||||||
| echo "📤 Enviando violações file-based (local)..." | ||||||
| run_reviewdog_with_config "${FILE_VIOLATIONS}.formatted" "%f::%m" \ | ||||||
| "local" "codenarc" "nofilter" "${INPUT_LEVEL}" | ||||||
| else | ||||||
| echo "📤 Enviando violações file-based (github-pr-check)..." | ||||||
| run_reviewdog_with_config "${FILE_VIOLATIONS}.formatted" "%f::%m" \ | ||||||
| "github-pr-check" "codenarc" "nofilter" "warning" | ||||||
| fi | ||||||
| fi | ||||||
|
|
||||||
| # fallback se nao houver violacoes categorizadas | ||||||
|
|
||||||
| if [ ! -s "$LINE_VIOLATIONS" ] && [ ! -s "$FILE_VIOLATIONS" ]; then | ||||||
| echo "📝 Executando reviewdog padrão..." | ||||||
| run_reviewdog_with_config "$CODENARC_RESULT" "%f:%l:%m" \ | ||||||
| "${INPUT_REPORTER:-github-pr-check}" "codenarc" \ | ||||||
| "${INPUT_FILTER_MODE}" "${INPUT_LEVEL}" | ||||||
| fi | ||||||
| } | ||||||
|
|
||||||
| generate_git_diff() { | ||||||
| if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then | ||||||
| echo "⚠️ Diretório não é um repositório Git; nenhuma comparação de diff será feita." | ||||||
| return 0 | ||||||
| fi | ||||||
|
|
||||||
| if [ -n "$GITHUB_BASE_SHA" ] && [ -n "$GITHUB_HEAD_SHA" ]; then | ||||||
| git fetch origin "$GITHUB_BASE_SHA" --depth=1 2>/dev/null || true | ||||||
| git fetch origin "$GITHUB_HEAD_SHA" --depth=1 2>/dev/null || true | ||||||
| git diff -U0 "$GITHUB_BASE_SHA" "$GITHUB_HEAD_SHA" -- '*.groovy' | ||||||
| else | ||||||
| if ! git rev-parse HEAD~1 >/dev/null 2>&1; then | ||||||
| echo "⚠️ Nenhum commit anterior para comparar; diff vazio." | ||||||
| return 0 | ||||||
| fi | ||||||
| git diff -U0 HEAD~1 -- '*.groovy' | ||||||
| fi | ||||||
| } | ||||||
|
|
@@ -119,10 +127,13 @@ parse_diff_range() { | |||||
| build_changed_lines_cache() { | ||||||
| true > "$CHANGED_LINES_CACHE" | ||||||
| true > "$CHANGED_FILES_CACHE" | ||||||
|
|
||||||
| generate_git_diff > "$ALL_DIFF" 2>/dev/null || true | ||||||
| [ ! -s "$ALL_DIFF" ] && return 0 | ||||||
|
|
||||||
| [ ! -s "$ALL_DIFF" ] && { | ||||||
| echo "ℹ️ Nenhum diff detectado; prosseguindo com cache vazio." | ||||||
| return 0 | ||||||
| } | ||||||
|
|
||||||
| current_file="" | ||||||
| while read -r line; do | ||||||
| case "$line" in | ||||||
|
|
@@ -150,6 +161,7 @@ build_changed_lines_cache() { | |||||
| done < "$ALL_DIFF" | ||||||
| } | ||||||
|
|
||||||
| # ========== FUNÇÕES AUXILIARES ========== | ||||||
| get_p1_count() { | ||||||
| p1_count=$(grep -Eo "p1=[0-9]+" "$CODENARC_RESULT" | cut -d'=' -f2 | head -1) | ||||||
| echo "${p1_count:-0}" | ||||||
|
|
@@ -179,52 +191,63 @@ is_file_changed() { | |||||
| grep -q "^$1$" "$CHANGED_FILES_CACHE" | ||||||
| } | ||||||
|
|
||||||
| # ========== ETAPA 4 - BLOQUEIO POR P1 ========== | ||||||
| check_blocking_rules() { | ||||||
| echo "🔎 Verificando violações bloqueantes (priority 1)..." | ||||||
|
|
||||||
| [ ! -f "$CODENARC_RESULT" ] && echo "❌ Resultado não encontrado" && return 1 | ||||||
|
|
||||||
| p1_count=$(get_p1_count) | ||||||
| echo "📊 Total de P1 encontradas: $p1_count" | ||||||
|
|
||||||
| [ "$p1_count" -eq 0 ] && echo "✅ Nenhuma P1 detectada → merge permitido" && return 0 | ||||||
|
|
||||||
| echo "⚠️ Verificando P1s em linhas alteradas..." | ||||||
| echo "📊 Total de P1 encontradas no resumo: ${p1_count:-0}" | ||||||
| [ "$p1_count" -eq 0 ] && { echo "✅ Nenhuma P1 detectada → merge permitido"; return 0; } | ||||||
|
|
||||||
| echo "⚙️ Preparando diff..." | ||||||
| build_changed_lines_cache | ||||||
|
|
||||||
| allowed_patterns=$(get_allowed_patterns) | ||||||
| [ -n "$allowed_patterns" ] && echo "🧩 Analisando apenas arquivos filtrados por INPUT_SOURCE_FILES" | ||||||
| [ -n "$allowed_patterns" ] && echo "🧩 Filtrando por INPUT_SOURCE_FILES" | ||||||
|
|
||||||
| echo "0" > "$VIOLATIONS_FLAG" | ||||||
|
|
||||||
| grep -E ':[0-9]+:|:null:|\|\|' "$CODENARC_RESULT" | while IFS=: read -r file line rest; do | ||||||
| grep -E ':[0-9]+:|:null:|\|\|' "$CODENARC_RESULT" > "$TMP_VIOLATIONS" || true | ||||||
|
|
||||||
| while IFS=: read -r file line rest; do | ||||||
| [ -z "$file" ] && continue | ||||||
| if echo "$file" | grep -q '||'; then | ||||||
| file=$(echo "$file" | cut -d'|' -f1) | ||||||
| line="" | ||||||
| fi | ||||||
| [ -z "$file" ] && continue | ||||||
| file_matches_patterns "$file" "$allowed_patterns" || continue | ||||||
|
|
||||||
| priority_marker=$(echo "$rest" | grep -o '\[P[0-9]\]' | head -1) | ||||||
|
|
||||||
| if [ -n "$priority_marker" ]; then | ||||||
| [ "$priority_marker" != "[P1]" ] && continue | ||||||
| fi | ||||||
|
|
||||||
| if [ -z "$line" ] || [ "$line" = "null" ]; then | ||||||
| if is_file_changed "$file"; then | ||||||
| echo "📍 Violação file-based em arquivo alterado: $file" | ||||||
| echo "1" > "$VIOLATIONS_FLAG" && break | ||||||
| echo "📍 Violação P1 file-based em arquivo alterado: $file" | ||||||
| echo "1" > "$VIOLATIONS_FLAG" | ||||||
| break | ||||||
| fi | ||||||
| elif is_line_changed "$line" "$file"; then | ||||||
| echo "📍 Violação em linha alterada: $file:$line" | ||||||
| echo "1" > "$VIOLATIONS_FLAG" && break | ||||||
| echo "📍 Violação P1 em linha alterada: $file:$line" | ||||||
| echo "1" > "$VIOLATIONS_FLAG" | ||||||
| break | ||||||
| fi | ||||||
| done | ||||||
|
|
||||||
| done < "$TMP_VIOLATIONS" | ||||||
|
|
||||||
| rm -f "$TMP_VIOLATIONS" | ||||||
|
|
||||||
| if [ "$(cat "$VIOLATIONS_FLAG")" -eq 1 ]; then | ||||||
| echo "⛔ P1s existem E há violações em linhas alteradas" | ||||||
| echo "💡 Corrija as violacoes ou use o bypass autorizado pelo coordenador." | ||||||
| echo "⛔ P1 encontrada em linha/arquivo alterado" | ||||||
|
||||||
| echo "⛔ P1 encontrada em linha/arquivo alterado" | |
| echo "⛔ Violação(ões) P1 encontrada(s) em linha/arquivo alterado(s)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
codenarc-docker/entrypoint.sh
Line 54 in 73a1ec9