Skip to content

Commit 9357f12

Browse files
committed
Add SonarCloud integration and improve complexity checking
CI/tooling updates: - Add SonarCloud scan job to CI workflow - Add sonar-project.properties configuration - Improve ci_complexity to use whitelist comparison - Update whitelizard.txt with current complexity warnings - Fix pyrefly to only check src/ (not tests/) The complexity check now: 1. Runs lizard to find complexity violations 2. Compares against whitelizard.txt whitelist 3. Only fails if NEW violations are found 4. Allows existing technical debt to be tracked separately
1 parent a8da261 commit 9357f12

File tree

5 files changed

+122
-12
lines changed

5 files changed

+122
-12
lines changed

.github/scripts/ci-utils.sh

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,42 @@ ci_typecheck() {
4646

4747
ci_complexity() {
4848
_header "📊 COMPLEXITY" "" "CCN ≤ 10 | NLOC ≤ 50 | Params ≤ 6"
49-
if ! uv run lizard src/ -C 10 -L 50 -a 6 -w; then
50-
_warn "⚠️ COMPLEXITY WARNING" "" "Some functions exceed thresholds"
49+
50+
# Create temp files for comparison
51+
local tmp_current tmp_whitelist tmp_raw
52+
tmp_current=$(mktemp)
53+
tmp_whitelist=$(mktemp)
54+
tmp_raw=$(mktemp)
55+
56+
# Run lizard and capture output (suppress uv build messages)
57+
uv run lizard src/ -C 10 -L 50 -a 6 -w > "$tmp_raw" 2>&1 || true
58+
59+
# Extract just the warning lines and sort
60+
grep "^src/" "$tmp_raw" | sort > "$tmp_current" || true
61+
rm -f "$tmp_raw"
62+
63+
if [ ! -s "$tmp_current" ]; then
64+
rm -f "$tmp_current" "$tmp_whitelist"
65+
_success "✅ COMPLEXITY PASSED"
66+
return 0
67+
fi
68+
69+
# Get whitelisted warnings (skip comments and empty lines)
70+
grep "^src/" whitelizard.txt | sort > "$tmp_whitelist" 2>/dev/null || true
71+
72+
# Find new warnings not in whitelist
73+
local new_warnings
74+
new_warnings=$(comm -23 "$tmp_current" "$tmp_whitelist")
75+
76+
rm -f "$tmp_current" "$tmp_whitelist"
77+
78+
if [ -n "$new_warnings" ]; then
79+
echo "$new_warnings"
80+
_error "❌ NEW COMPLEXITY VIOLATIONS" "" "Add to whitelizard.txt or refactor"
5181
return 1
5282
fi
53-
_success "✅ COMPLEXITY PASSED"
83+
84+
_success "✅ COMPLEXITY PASSED (whitelisted warnings only)"
5485
}
5586

5687
ci_test() {

.github/workflows/ci.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ jobs:
7777
runs-on: ubuntu-latest
7878
steps:
7979
- uses: actions/checkout@v4
80+
with:
81+
fetch-depth: 0 # Full history for SonarCloud
8082
- name: Install gum
8183
run: |
8284
sudo mkdir -p /etc/apt/keyrings
@@ -88,7 +90,31 @@ jobs:
8890
enable-cache: true
8991
- run: uv python install ${{ env.PYTHON_VERSION }}
9092
- run: uv sync --dev
91-
- run: source .github/scripts/ci-utils.sh && ci_test
93+
- name: Run tests with coverage
94+
run: uv run pytest --cov=src/jdo --cov-report=xml --cov-branch -q
95+
- name: Upload coverage artifact
96+
uses: actions/upload-artifact@v4
97+
with:
98+
name: coverage-report
99+
path: coverage.xml
100+
retention-days: 1
101+
102+
sonarcloud:
103+
name: "📊 SonarCloud"
104+
runs-on: ubuntu-latest
105+
needs: test
106+
steps:
107+
- uses: actions/checkout@v4
108+
with:
109+
fetch-depth: 0 # Full history for blame information
110+
- name: Download coverage artifact
111+
uses: actions/download-artifact@v4
112+
with:
113+
name: coverage-report
114+
- name: SonarCloud Scan
115+
uses: SonarSource/sonarqube-scan-action@v5
116+
env:
117+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
92118

93119
roadmap:
94120
name: "📋 Roadmap"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ docstring-code-format = true
171171
# NOTE: pyrefly has known false positives with SQLModel/SQLAlchemy - check runtime if unsure
172172
[tool.pyrefly]
173173
python-version = "3.11.0"
174-
project-includes = ["src", "tests"]
174+
project-includes = ["src"]
175175
search-path = ["src"]
176176

177177
[tool.pyrefly.errors]

sonar-project.properties

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# SonarCloud configuration
2+
# Docs: https://docs.sonarsource.com/sonarqube-cloud/
3+
4+
# Project identification
5+
sonar.projectKey=JRedeker_jdo
6+
sonar.organization=jredeker
7+
8+
# Project metadata
9+
sonar.projectName=jdo
10+
sonar.projectVersion=0.1.0
11+
12+
# Source code location
13+
sonar.sources=src
14+
sonar.tests=tests
15+
16+
# Python configuration
17+
sonar.python.version=3.11
18+
19+
# Coverage report path (generated by pytest-cov)
20+
sonar.python.coverage.reportPaths=coverage.xml
21+
22+
# Exclusions
23+
sonar.exclusions=**/migrations/**,**/__pycache__/**
24+
sonar.test.exclusions=**/tests/**
25+
26+
# Encoding
27+
sonar.sourceEncoding=UTF-8

whitelizard.txt

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
11
# Whitelist for pre-existing complexity warnings
22
# These functions exceed thresholds but are acceptable for now
3+
# Format matches exact lizard output for comparison
34

4-
src/jdo/commands/handlers.py:54: warning: execute has 36 NLOC, 7 CCN, 226 token, 3 PARAM, 56 length, 0 ND
5-
src/jdo/commands/handlers.py:196: warning: execute has 40 NLOC, 9 CCN, 255 token, 3 PARAM, 61 length, 0 ND
6-
src/jdo/commands/handlers.py:313: warning: execute has 39 NLOC, 6 CCN, 199 token, 3 PARAM, 59 length, 0 ND
7-
src/jdo/commands/handlers.py:1242: warning: _show_analysis_with_options has 55 NLOC, 4 CCN, 308 token, 5 PARAM, 75 length, 0 ND
8-
src/jdo/db/session.py:166: warning: check_and_generate_recurring_instances has 26 NLOC, 7 CCN, 182 token, 2 PARAM, 55 length, 0 ND
9-
src/jdo/db/session.py:223: warning: generate_next_instance_for_recurring has 26 NLOC, 7 CCN, 161 token, 3 PARAM, 53 length, 0 ND
10-
src/jdo/widgets/chat_message.py:59: warning: __init__ has 15 NLOC, 2 CCN, 98 token, 7 PARAM, 26 length, 0 ND
5+
src/jdo/screens/chat.py:461: warning: _handle_command has 27 NLOC, 7 CCN, 161 token, 2 PARAM, 54 length, 0 ND
6+
src/jdo/screens/chat.py:555: warning: _apply_modification_request has 41 NLOC, 9 CCN, 199 token, 2 PARAM, 59 length, 0 ND
7+
src/jdo/screens/chat.py:804: warning: _save_pending_entity has 39 NLOC, 7 CCN, 203 token, 1 PARAM, 51 length, 0 ND
8+
src/jdo/screens/chat.py:939: warning: _do_ai_streaming has 40 NLOC, 7 CCN, 248 token, 2 PARAM, 59 length, 0 ND
9+
src/jdo/commands/handlers.py:61: warning: execute has 43 NLOC, 8 CCN, 263 token, 3 PARAM, 66 length, 0 ND
10+
src/jdo/commands/handlers.py:233: warning: execute has 40 NLOC, 9 CCN, 255 token, 3 PARAM, 61 length, 0 ND
11+
src/jdo/commands/handlers.py:350: warning: execute has 40 NLOC, 6 CCN, 208 token, 3 PARAM, 60 length, 0 ND
12+
src/jdo/commands/handlers.py:901: warning: execute has 40 NLOC, 3 CCN, 143 token, 3 PARAM, 51 length, 0 ND
13+
src/jdo/commands/handlers.py:1291: warning: execute has 49 NLOC, 5 CCN, 196 token, 3 PARAM, 63 length, 0 ND
14+
src/jdo/commands/handlers.py:1399: warning: execute has 55 NLOC, 7 CCN, 241 token, 3 PARAM, 73 length, 0 ND
15+
src/jdo/commands/handlers.py:1510: warning: execute has 33 NLOC, 4 CCN, 145 token, 3 PARAM, 51 length, 0 ND
16+
src/jdo/commands/handlers.py:1673: warning: _show_dashboard has 60 NLOC, 5 CCN, 317 token, 2 PARAM, 69 length, 0 ND
17+
src/jdo/commands/handlers.py:1831: warning: _handle_at_risk_abandon has 50 NLOC, 5 CCN, 208 token, 3 PARAM, 61 length, 0 ND
18+
src/jdo/commands/handlers.py:2050: warning: _show_analysis_with_options has 55 NLOC, 11 CCN, 308 token, 5 PARAM, 75 length, 0 ND
19+
src/jdo/commands/handlers.py:2240: warning: execute has 84 NLOC, 11 CCN, 344 token, 3 PARAM, 109 length, 0 ND
20+
src/jdo/ai/tools.py:337: warning: _register_time_coaching_tools has 9 NLOC, 1 CCN, 39 token, 1 PARAM, 112 length, 0 ND
21+
src/jdo/db/persistence.py:184: warning: save_task has 28 NLOC, 4 CCN, 205 token, 2 PARAM, 56 length, 0 ND
22+
src/jdo/db/persistence.py:351: warning: save_recurring_commitment has 42 NLOC, 5 CCN, 298 token, 2 PARAM, 78 length, 0 ND
23+
src/jdo/db/task_history_service.py:41: warning: log_event has 28 NLOC, 1 CCN, 120 token, 9 PARAM, 48 length, 0 ND
24+
src/jdo/db/session.py:174: warning: check_and_generate_recurring_instances has 26 NLOC, 7 CCN, 182 token, 2 PARAM, 55 length, 0 ND
25+
src/jdo/db/session.py:231: warning: generate_next_instance_for_recurring has 26 NLOC, 7 CCN, 161 token, 3 PARAM, 53 length, 0 ND
26+
src/jdo/widgets/data_panel.py:371: warning: _render_list_item has 35 NLOC, 7 CCN, 237 token, 3 PARAM, 54 length, 0 ND
27+
src/jdo/widgets/data_panel.py:889: warning: _render_integrity has 35 NLOC, 3 CCN, 340 token, 1 PARAM, 52 length, 0 ND
28+
src/jdo/widgets/data_panel.py:959: warning: _render_cleanup has 42 NLOC, 7 CCN, 320 token, 1 PARAM, 54 length, 0 ND
29+
src/jdo/widgets/chat_message.py:67: warning: __init__ has 17 NLOC, 2 CCN, 108 token, 7 PARAM, 28 length, 0 ND
30+
src/jdo/integrity/service.py:129: warning: mark_commitment_at_risk has 60 NLOC, 5 CCN, 304 token, 5 PARAM, 92 length, 0 ND
31+
src/jdo/integrity/service.py:222: warning: recover_commitment has 45 NLOC, 9 CCN, 247 token, 4 PARAM, 78 length, 0 ND
32+
src/jdo/integrity/service.py:327: warning: calculate_integrity_metrics has 53 NLOC, 3 CCN, 319 token, 2 PARAM, 82 length, 0 ND
33+
src/jdo/integrity/service.py:410: warning: detect_risks has 45 NLOC, 4 CCN, 252 token, 2 PARAM, 73 length, 0 ND
34+
src/jdo/integrity/service.py:525: warning: _calculate_streak_weeks has 51 NLOC, 14 CCN, 315 token, 2 PARAM, 79 length, 0 ND
35+
src/jdo/integrity/service.py:605: warning: _calculate_estimation_accuracy has 33 NLOC, 8 CCN, 237 token, 2 PARAM, 66 length, 0 ND
36+
src/jdo/app.py:613: warning: on_hierarchy_view_item_selected has 53 NLOC, 8 CCN, 288 token, 2 PARAM, 62 length, 0 ND

0 commit comments

Comments
 (0)