Skip to content

chore(refactor): flatten duplicated contribution loops in get_user_activities#278

Merged
saidsef merged 1 commit into
mainfrom
chore/flatten-user-activities-loops
Jul 8, 2026
Merged

chore(refactor): flatten duplicated contribution loops in get_user_activities#278
saidsef merged 1 commit into
mainfrom
chore/flatten-user-activities-loops

Conversation

@saidsef

@saidsef saidsef commented Jul 4, 2026

Copy link
Copy Markdown
Owner

What

get_user_activities built its commits, pull requests, issues and reviews lists with four near-identical double loops, each manually descending into contributions.nodes before appending. The outer iteration and org/repo filtering already lived in the _filtered_contributions generator, so this moves the inner descent into it as well. The generator now yields individual contribution nodes, and each of the four blocks collapses to a single flat loop - one less level of nesting and no repeated .get("contributions", {}).get("nodes", []).

Why

Removes the last piece of structural duplication in the method and makes the four blocks read uniformly. The per-type result dicts - the only thing that genuinely differs between them - are left exactly as they were.

No behaviour change

The old inner break stopped appending once max_results was hit while the outer loop kept spinning as a no-op; the flat loop stops at the same point (and iterates a little less). Because that field extraction has no unit test, I proved equivalence directly: cached a real GraphQL response, then ran the extraction before and after the change - the JSON output is byte-identical, with max_results actively capping every list so the break path is exercised.

Testing

  • Byte-identical output on real data (before vs after)
  • uv run pytest -q - 56 passed
  • ruff check src/ and pyright - clean
  • Server boots in HTTP mode and serves get_user_activities over MCP

Follow-up to the de-duplication in #277; touches different lines of the same method, so the two do not conflict.

…tivities

get_user_activities built its commits, pull requests, issues and reviews lists
with four near-identical double loops, each manually descending into
contributions.nodes. The outer iteration and org/repo filtering already lived
in the _filtered_contributions generator, so this moves the inner descent into
it too: the generator now yields individual contribution nodes and each of the
four blocks becomes a single flat loop, dropping a nesting level and the
repeated .get("contributions", {}).get("nodes", []).

No behaviour change. The old inner break stopped appending once max_results was
reached while the outer loop kept spinning as a no-op; the flat loop stops at
the same point. Verified byte-identical output by replaying a cached real
GraphQL response through the extraction before and after (with max_results
capping every list).
@saidsef saidsef added python Pull requests that update python code chore github-integration refactor labels Jul 4, 2026
@saidsef saidsef self-assigned this Jul 4, 2026
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 4 minor

Results:
4 new issues

Category Results
Documentation 4 minor

View in Codacy

🟢 Metrics -4 complexity

Metric Results
Complexity -4

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@saidsef
saidsef merged commit 44e5242 into main Jul 8, 2026
7 checks passed
@saidsef
saidsef deleted the chore/flatten-user-activities-loops branch July 8, 2026 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore github-integration python Pull requests that update python code refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant