Skip to content

Commit e60bde2

Browse files
Merge pull request #59 from asaasdev/DVT-730-permitir-bloqueio-merge-codenarc
feat(DVT‑730): bloquear merge em violacoes bloqueantes (priority 1) do CodeNarc
2 parents ec2147b + f93d2f1 commit e60bde2

File tree

1 file changed

+47
-20
lines changed

1 file changed

+47
-20
lines changed

entrypoint.sh

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,61 @@
11
#!/bin/sh
22
set -e
3+
trap 'rm -f result.txt >/dev/null 2>&1' EXIT
34

4-
if [ -n "${GITHUB_WORKSPACE}" ] ; then
5-
cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit
6-
git config --global --add safe.directory "$GITHUB_WORKSPACE" || exit
7-
fi
5+
run_codenarc() {
6+
report="${INPUT_REPORT:-compact:stdout}"
7+
includes_arg=""
88

9-
export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"
9+
if [ -n "$INPUT_SOURCE_FILES" ]; then
10+
includes_arg="-includes=${INPUT_SOURCE_FILES}"
11+
fi
1012

11-
if [ -n "$INPUT_SOURCE_FILES" ]; then
12-
java -jar /lib/codenarc-all.jar \
13-
-report="${INPUT_REPORT:-compact:stdout}" \
14-
-rulesetfiles="${INPUT_RULESETFILES}" \
15-
-basedir="." \
16-
-includes="${INPUT_SOURCE_FILES}" \
17-
> result.txt
18-
else
13+
echo "🔍 Executando CodeNarc..."
1914
java -jar /lib/codenarc-all.jar \
20-
-report="${INPUT_REPORT:-compact:stdout}" \
21-
-rulesetfiles="${INPUT_RULESETFILES}" \
22-
> result.txt
23-
fi
24-
15+
-report="$report" \
16+
-rulesetfiles="${INPUT_RULESETFILES}" \
17+
-basedir="." \
18+
$includes_arg \
19+
> result.txt
20+
}
2521

26-
< result.txt reviewdog -efm="%f:%l:%m" -efm="%f:%r:%m" \
22+
run_reviewdog() {
23+
echo "📤 Enviando resultados para reviewdog..."
24+
< result.txt reviewdog -efm="%f:%l:%m" -efm="%f:%r:%m" \
2725
-name="codenarc" \
2826
-reporter="${INPUT_REPORTER:-github-pr-check}" \
2927
-filter-mode="${INPUT_FILTER_MODE}" \
3028
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
3129
-level="${INPUT_LEVEL}" \
3230
${INPUT_REVIEWDOG_FLAGS}
31+
}
32+
33+
check_blocking_rules() {
34+
echo "🔎 Verificando violacoes bloqueantes (priority 1)..."
35+
36+
p1_count=$(grep -Eo "p1=[0-9]+" result.txt | cut -d'=' -f2 | head -1)
37+
p1_count=${p1_count:-0}
38+
39+
echo "📊 Resumo CodeNarc → priority 1=${p1_count}"
40+
41+
if [ "$p1_count" -gt 0 ]; then
42+
echo "⛔ Foram encontradas violacoes bloqueantes (priority 1)."
43+
echo "💡 Corrija as violacoes ou use o bypass autorizado pelo coordenador."
44+
exit 1
45+
else
46+
echo "✅ Nenhuma violacao bloqueante (priority 1) encontrada."
47+
fi
48+
}
49+
50+
if [ -n "${GITHUB_WORKSPACE}" ]; then
51+
cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit
52+
git config --global --add safe.directory "$GITHUB_WORKSPACE"
53+
fi
54+
55+
export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"
56+
57+
run_codenarc
58+
run_reviewdog
59+
check_blocking_rules
3360

34-
rm result.txt
61+
echo "🏁 Finalizado com sucesso."

0 commit comments

Comments
 (0)