Repository navigation
scaffold-project.py and adopt-project.py: three functions ran past Sonar's cognitive-complexity limit, so each is split into the phases its own comments already name (#138) - #144
Conversation
…ve complexity 85, so the phases its own section comments already named are now functions (#138) SonarCloud's `python:S3776` had the largest single function in this repository open at 85 against a limit of 15. It ran the argument validation, the elector fallback, the pin declaration, the referent chain, the three-name naming check, the shape revision, the URL arithmetic, the visibility inheritance, the substitution table, the plan print, the existing-tree refusal, the three repository creations, the two seed pushes, the assembly root, the topics and the next-steps block in one body — with `# ---- the two legs ----` style comments already marking where one phase stopped and the next began. Those comments are now function boundaries, in the shape `adopt-project.py` has used since it was written: module-level private helpers labelled `(a)`, `(b)`, `(c)` in their own docstrings, called in order by a thin driver. `_scaffold` is 85 -> 7. Nothing else in the file is above 10, and the 10 is `_reusable_remotes`, which was already there. The `# noqa: C901` it wore is gone with the reason for it. Behaviour is unchanged by construction and by test. Every message string, every refusal id, every `gh` and `git` argument vector and the order of all of them are moved rather than edited. Three orderings are load-bearing and are called out where they now live: `--elected-on` is still parsed before anything is created and before the elector is resolved, so an explicit `--reference` cannot let a malformed date through; the naming policy is still loaded after the elector refusal; and the local remote directory is still created after the dry-run return and after the existing-tree refusal, so a refused run leaves no directory behind. Two small shapes changed and neither is visible from outside. `_seed_legs` and `_build_assembly_root` report a REFUSED push by returning None and False instead of returning 2 from the middle of the old body — the caller turns that back into the same exit 2, after the same two stderr blocks. `_leg_visibility` returns the visibility the two new legs are created at rather than assigning `args.visibility` in place; the caller does the assignment, so the manifest value and both the NOTE and WARNING lines are what they were. `_private_leg_note` keeps the block nested under its own condition rather than taking the guard clause the other helpers took, because `tests/test_free_plan_hint.py::test_every_creating_tool_calls_the_hint` reads this file as text and asserts the exact indentation of the `free_plan_secret_hint(` call. A guard clause would have dedented it and the test would have been right to fail: it is checking that all three creating tools call the hint with their own org, and it cannot check that if the call moves. No argparse text moved, so `docs/cli.md` is unchanged and `tests/test_cli_reference.py` passes without a regeneration. Lane: openreposhape-2 (openRepoShape-2) Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ecking, their remote arithmetic and their reporting inline at cognitive complexity 17 and 24, so each is now the phase helpers this file already writes everywhere else (#138) SonarCloud's `python:S3776` had both of `adopt-project.py`'s acting subcommands open against a limit of 15. Neither needed a new idea to fix: the file has kept `_create_leg_remotes`, `_extract_leg`, `_seed_leg`, `_mount_the_legs`, `_template_values`, `_split_message` and `_verify` as module-level private helpers since it was written, and `cmd_execute` already labels its phases `(a)`, `(b)`, `(c)`, `(d)` in section comments. The work was to finish applying that shape to the two functions that had outgrown it. cmd_plan 17 -> 2 cmd_execute 24 -> 8 `cmd_plan` gives up `_checked_plan_inputs` — every value the plan will record, defaulted and checked — and `_print_plan_report`, what it says to the terminal once the file is on disk. `cmd_execute` gives up `_checked_plan_values`, `_repository_urls`, `_leg_paths`, `_refuse_unconsented_seeding`, `_build_the_legs`, `_commit_the_split`, `_open_the_pull_request` and `_set_the_topic`; what is left is the seventeen calls those phases are, in order, with the section comments still between them. Behaviour is unchanged by construction and by test. Every message string, every refusal id, every `git` and `gh` argument vector and the order of all of them are moved rather than edited. The one thing that had to be preserved deliberately is the ORDER OF THE REFUSALS over untrusted plan input. `execute` checks `legs.spec_path`, `legs.code_path`, `adopt_branch`, `tracking_branch` and then `org`, and a plan with two bad values must still name the first one; `_checked_plan_values` runs before `_repository_urls`, which is what holds that. `local` moved into `_repository_urls` with the URLs it decides, which is safe because it is a pure read of `--local-remote-dir` that nothing observes. Four helpers report a failure by return value where the old body returned 2 from the middle of itself: `_build_the_legs` and `_commit_the_split` return None, `_open_the_pull_request` and `_set_the_topic` return False. The caller turns each back into the same exit, after the same stderr block, in the same place. `_set_the_topic`'s docstring keeps the whole of the comment that explained why a topic that will not set must not suppress the verification table, because that is the reason it returns a bool instead of exiting. No argparse text moved, so `docs/cli.md` is unchanged and `tests/test_cli_reference.py` passes without a regeneration. Lane: openreposhape-2 (openRepoShape-2) Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.
You can request another review in 3 days and 10 hours by commenting @sourcery-ai review. Upgrade to get a review now.
|
@codex review |
Reviewer's GuideRefactors the three SonarCloud-flagged orchestration functions into phase-aligned private helpers, retaining byte-identical behavior, ordering, diagnostics, and exit semantics while bringing each function below the cognitive-complexity threshold. Flow diagram for scaffold project phasesflowchart TD
A["_scaffold"] --> B["Validate inputs and _identity"]
B --> C["_declaration and _check_declared_names"]
C --> D["_shape_revision and _repository_urls"]
D --> E["_leg_visibility and _print_plan"]
E --> F{"--dry-run?"}
F -- "yes" --> G["Return 0"]
F -- "no" --> H["_refuse_existing_trees"]
H --> I["_create_remotes and _private_leg_note"]
I --> J["_seed_legs"]
J --> K["_build_assembly_root"]
K --> L["_set_topics"]
Flow diagram for adopt execute phasesflowchart TD
A["cmd_execute"] --> B["_checked_plan_values"]
B --> C["_repository_urls"]
C --> D["_leg_paths and _refuse_unconsented_seeding"]
D --> E["_create_leg_remotes"]
E --> F["_build_the_legs"]
F --> G["_commit_the_split"]
G --> H{"local remote?"}
H -- "no" --> I["_open_the_pull_request"]
I --> J["_set_the_topic"]
H -- "yes" --> K["_verify"]
J --> K
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
🟢 Approval recommended
The reviewed refactors preserve existing behavior with no unresolved blocking issues.
Pull request overview
Refactors scaffold and adoption workflows into focused helpers, reducing cognitive complexity while preserving behavior and command ordering.
Changes:
- Split
scaffold-project.pyinto phase-specific helpers. - Split
adopt-project.pyplan and execution flows. - Preserved CLI behavior, output, validation, and error handling.
File summaries
| File | Description |
|---|---|
scaffold-project.py |
Extracts scaffolding phases into private helpers. |
adopt-project.py |
Extracts plan validation and execution phases into private helpers. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…because every line in it addresses a repository by its `<org>/<name>` or its clone URL (#138) SonarCloud's `python:S1172` on the pull request, and it is right: the split handed the new helper the same four dictionaries its neighbours take, without checking which of them this phase actually uses. It creates the three remotes by `repositories[role]` and `urls[role]` and never wants the bare name, so the parameter is dropped and the docstring says why, to stop the next reader adding it back for symmetry. No behaviour changes: the argument was unread. Lane: openreposhape-2 (openRepoShape-2) Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Lane: openreposhape-2 (openRepoShape-2) PR-scoped SonarCloud query at head No CI: Reviewers: Copilot recommended approval with 0 comments, twice (before and after the S1172 fix). Sourcery declined — own review budget of 250,000 diff characters spent for the last 7 days. Codex was asked and is over quota today. |



Lane: openreposhape-2 (openRepoShape-2)
Claim: #138 (comment)
Closes #138.
What was wrong
SonarCloud had
python:S3776— cognitive complexity ≤ 15 — open on the threeacting functions of the two repository-CREATING tools, including the largest
single function in this repository.
scaffold-project.py_scaffold# ---- the two legs ----section comments already marked became fourteen module-level helpers:_elector,_identity,_declaration,_check_referent_chain+_check_one_name+_check_declared_names,_shape_revision,_repository_urls,_leg_visibility,_print_plan+_print_declared_classification+_print_plan_actions,_refuse_existing_trees,_create_remotes,_private_leg_note,_seed_legs,_build_assembly_root,_set_topics. What is left is those calls in order, plus the substitution table.adopt-project.pycmd_plan_checked_plan_inputs(every value the plan will record, defaulted and checked) and_print_plan_report(what it says to the terminal once the file is on disk).adopt-project.pycmd_execute_checked_plan_values,_repository_urls,_leg_paths,_refuse_unconsented_seeding,_build_the_legs,_commit_the_split,_open_the_pull_request,_set_the_topic— the(a)/(b)/(c)/(d)phases the file's own section comments have named all along."cc before" is SonarCloud's own number for
mainat d682127, queried ratherthan guessed; "cc after" is
complexipy 8.0.1, which implements the sameSonarSource specification. Nothing in either file now measures above 10, and
the 10 is
scaffold-project.py's_reusable_remotes, which was already thereand was never flagged.
No new idea was invented for either file.
adopt-project.pyhas kept_create_leg_remotes,_extract_leg,_seed_leg,_mount_the_legs,_template_values,_split_messageand_verifyas module-level privatehelpers since it was written; this finishes applying that shape to the two
functions that had outgrown it, and gives
scaffold-project.pythe same one.What landed
Two files, and only those two:
scaffold-project.pyandadopt-project.py.No digest-pinned copy is touched — nothing under
templates/, nothing inscripts/, no contract, no workflow — so no project'supdate-shape.py checkmoves and no estate re-pin is owed for this.
Behaviour is byte-identical, and that is the point. Every message string,
every refusal id, every
ghandgitargument vector, and the ORDER of allof them, are moved rather than edited. No argparse text moved either, so
docs/cli.mdis unchanged and needed no regeneration.Three orderings are load-bearing and are now called out where they live:
scaffold-project.pystill parses--elected-onbefore anything is createdand before the elector is resolved, so an explicit
--referencecannot leta malformed date reach a manifest field no reader can use; the naming policy
is still loaded after the elector refusal; and the local remote directory is
still created after the
--dry-runreturn and after the existing-treerefusal, so a refused run leaves no directory behind.
adopt-project.py executestill checks its untrusted plan values in theorder
legs.spec_path,legs.code_path,adopt_branch,tracking_branch,org, so a plan with two bad values still names thefirst one.
_checked_plan_valuesrunning before_repository_urlsis whatholds that.
Six helpers report a failure by return value where the old bodies returned
2from the middle of themselves —_seed_legs,_build_the_legsand_commit_the_splitreturnNone;_build_assembly_root,_open_the_pull_requestand_set_the_topicreturnFalse. Each callerturns that back into the same exit code, after the same stderr block, in the
same place.
_leg_visibilityreturns the visibility rather than assigningargs.visibilityin place, and the caller does the assignment.One helper deliberately did NOT take the guard clause the others took:
_private_leg_notekeeps its block nested under its own condition, becausetests/test_free_plan_hint.py::test_every_creating_tool_calls_the_hintreadsscaffold-project.pyas TEXT and asserts the exact indentation of thefree_plan_secret_hint(call. A guard clause dedents it and that test fails —correctly, since it is checking that all three creating tools call the hint
with their own org and it cannot check that if the call moves.
No bug was found while restructuring, so there is no follow-up to file from
this.
How it was proven
Full suite, from this worktree, in three foreground chunks:
That is the expected baseline for
maintoday, unchanged. No flake was seen.The suites that actually drive these two tools end to end — into BARE
repositories in a temporary directory, with no network — are
tests/test_scaffold_e2e.py,tests/test_scaffold_pin_and_reuse.py,tests/test_reuse_visibility.py,tests/test_reference_default.py,tests/test_setup_project_py.py,tests/test_setup_sh.py,tests/test_openreposhape_command.py,tests/test_adopt_plan.py,tests/test_adopt_e2e.pyandtests/test_adopt_spec_only.py. Each was runagainst its own commit before it was pushed, and
tests/test_free_plan_hint.pycaught the one indentation change describedabove while the first commit was still local.
tests/test_cli_reference.pypasses withdocs/cli.mduntouched, which isthe proof that no
--helptext moved.tests/test_repo_hygiene.pyandtests/test_commit_trailers.pypass, so both files still compile under theshipped-file rule and the materializer copy lists still account for every
template file.
The authority on the rule itself is this pull request's own SonarCloud
analysis, and the PR-scoped issue query is posted as a comment once it has
run.
🤖 Generated with Claude Code
Summary by Sourcery
Enhancements: