Skip to content

refactor(cli): split long functions in bootstrap_profile_runner to fix largefunc lint#46332

Merged
pelikhan merged 7 commits into
mainfrom
copilot/lint-monster-refactor-bootstrap-profile-runner
Jul 18, 2026
Merged

refactor(cli): split long functions in bootstrap_profile_runner to fix largefunc lint#46332
pelikhan merged 7 commits into
mainfrom
copilot/lint-monster-refactor-bootstrap-profile-runner

Conversation

Copilot AI commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

pkg/cli/bootstrap_profile_runner.go had 14 largefunc lint findings (limit: 60 lines), concentrated in three functions. All three are split into focused helpers without behavior change.

Extractions

  • executeBootstrapProfile (78 → 32 lines): action-type dispatch moved to applyBootstrapAction

  • runBootstrapGitHubAppAction (86 → ~59 lines): two credential-resolution paths extracted:

    • handleBootstrapGitHubAppExistingFlow — env-var / explicit-existing mode
    • handleBootstrapGitHubAppCreateOrExistingChoice — interactive create-or-existing prompt
  • createBootstrapGitHubApp (118 → ~56 lines): two blocks extracted:

    • setupBootstrapGitHubAppDetails — owner override + app name/homepage/description derivation
    • buildBootstrapGitHubAppMux — HTTP /register + /callback handler setup

Supporting changes

  • Added bootstrapGitHubAppFlowChannels struct to keep buildBootstrapGitHubAppMux under the 8-parameter limit, grouping the result/error send channels.
  • io.WriteString replaces w.Write([]byte(...)) in the mux helper.

Copilot AI and others added 3 commits July 18, 2026 03:55
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor long functions in bootstrap/profile runner to improve code quality refactor(cli): split long functions in bootstrap_profile_runner to fix largefunc lint Jul 18, 2026
Copilot AI requested a review from pelikhan July 18, 2026 04:07
@pelikhan
pelikhan marked this pull request as ready for review July 18, 2026 05:35
Copilot AI review requested due to automatic review settings July 18, 2026 05:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors bootstrap/profile runner functions into focused helpers to satisfy largefunc lint limits without changing CLI behavior.

Changes:

  • Extracts bootstrap action dispatch and GitHub App credential flows.
  • Extracts GitHub App setup and HTTP mux construction.
  • Refreshes generated workflow action-version metadata.
Show a summary per file
File Description
pkg/cli/bootstrap_profile_runner.go Splits long bootstrap functions into helpers.
.github/workflows/skillet.lock.yml Refreshes generated checkout metadata.
.github/workflows/release.lock.yml Refreshes generated setup-go metadata.
.github/workflows/hourly-ci-cleaner.lock.yml Refreshes generated checkout metadata.
.github/workflows/avenger.lock.yml Refreshes generated checkout metadata.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 5/5 changed files
  • Comments generated: 0
  • Review effort level: Medium

@github-actions

Copy link
Copy Markdown
Contributor

🤖 PR Triage

Field Value
Category refactor
Risk 🟡 Medium
Score 48/100 (impact:18, urgency:10, quality:20)
Action batch_review
Batch pr-batch:largefunc-refactor (with #46335)

Rationale: Mechanical largefunc lint fix for bootstrap_profile_runner. Modest diff (209+/156−, 5 files). Review together with #46335 as a batch.

Generated by 🔧 PR Triage Agent · 32.1 AIC · ⌖ 7.02 AIC · ⊞ 5.6K ·

@github-actions

github-actions Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

@github-actions

github-actions Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

No test files were added or modified in this PR. Test Quality Sentinel skipped.

@github-actions

github-actions Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

@github-actions

github-actions Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skills-Based Review 🧠

Applied /codebase-design — clean mechanical refactor with no behavioral changes detected.

📋 Key Themes & Highlights

Key Themes

  • Extraction correctness: All three extracted helpers faithfully preserve the original logic. The guard condition inversion in handleBootstrapGitHubAppCreateOrExistingChoice (line 472) correctly applies De Morgan's law.
  • No test coverage: This is a pure structural refactor, so the absence of new tests is acceptable — the existing test suite covers the behavior.
  • One minor nit: setupBootstrapGitHubAppDetails uses named return values with bare return statements; mixing named returns with a function that also sets appName, homepageURL, description via assignment is slightly harder to follow at a glance, but it's idiomatic Go for this kind of multi-value extraction.

Positive Highlights

  • bootstrapGitHubAppFlowChannels struct is a clean solution to the parameter-count lint constraint
  • io.WriteString in place of w.Write([]byte(...)) is a good opportunistic improvement
  • ✅ All extracted functions have clear, accurate doc comments
  • ✅ The CSRF statecsrfState rename in buildBootstrapGitHubAppMux improves local clarity

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · 55.6 AIC · ⌖ 6.16 AIC · ⊞ 6.7K
Comment /matt to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactoring is clean and correct. All behavioral equivalences hold:

  • The continue to return nil change in applyBootstrapAction for the copilot-auth case is safe — the extracted function handles one action at a time.
  • handleBootstrapGitHubAppExistingFlow correctly inverts the condition guard.
  • handleBootstrapGitHubAppCreateOrExistingChoice correctly passes empty strings matching the original code path.
  • bootstrapGitHubAppFlowChannels is a clean encapsulation with correctly typed send-only channels.

No issues found.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · 30.3 AIC · ⌖ 4.29 AIC · ⊞ 5K

@github-actions

Copy link
Copy Markdown
Contributor

🏗️ Design Decision Gate — ADR Required

This PR makes significant changes to core business logic (201 new lines in pkg/cli/) but does not have a linked Architecture Decision Record (ADR).

📄 Draft ADR committed: docs/adr/46332-split-large-functions-bootstrap-profile-runner.md — review and complete it before merging.

🔒 This PR cannot merge until an ADR is linked in the PR body.

📋 What to do next
  1. Review the draft ADR committed to your branch — it was generated from the PR diff
  2. Complete the missing sections — add context the AI could not infer, refine the decision rationale, and list real alternatives you considered
  3. Commit the finalized ADR to docs/adr/ on your branch
  4. Reference the ADR in this PR body by adding a line such as:

    ADR: ADR-46332: Split Large Functions in bootstrap_profile_runner.go

Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision.

Why ADRs Matter

ADRs create a searchable, permanent record of why the codebase looks the way it does. Future contributors (and your future self) will thank you.

📋 Michael Nygard ADR Format Reference

An ADR must contain these four sections to be considered complete:

  • Context — What is the problem? What forces are at play?
  • Decision — What did you decide? Why?
  • Alternatives Considered — What else could have been done?
  • Consequences — What are the trade-offs (positive and negative)?

All ADRs are stored in docs/adr/ as Markdown files numbered by PR number (e.g., 46332-split-large-functions-bootstrap-profile-runner.md for PR #46332).

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · 82 AIC · ⌖ 9.78 AIC · ⊞ 8.5K ·
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking observations

The extraction is mechanically correct — no control-flow changes, no dropped errors. Two maintainability concerns worth addressing (see inline comments).

  1. Guard semantics in handleBootstrapGitHubAppCreateOrExistingChoice: The guard condition correctly preserves original behavior but the function name implies tighter scope than its actual trigger conditions.
  2. Naked returns in setupBootstrapGitHubAppDetails: Technically correct today, fragile to future additions.

🔎 Code quality review by PR Code Quality Reviewer · 103.8 AIC · ⌖ 4.69 AIC · ⊞ 5.6K
Comment /review to run again

Comments that could not be inline-anchored

pkg/cli/bootstrap_profile_runner.go:340

Guard condition in handleBootstrapGitHubAppCreateOrExistingChoice is subtly wrong: it admits the function body when overrides.Mode == &quot;create&quot; even without action.Mode == &quot;create-or-existing&quot;, diverging from the original createNew gate.

<details>
<summary>💡 Details</summary>

Original guard:

createNew := action.Mode == &quot;create-or-existing&quot; || overrides.Mode == &quot;create&quot;
if createNew {

New guard (De Morgan negation):

if action.Mode != &quot;create-or-existing&quot; &amp;&amp; overrid</details>

<details><summary>pkg/cli/bootstrap_profile_runner.go:452</summary>

**Naked returns in `setupBootstrapGitHubAppDetails` leave return values undefined on the error path**: the named return variables are zero-value strings if the early `return` fires, which is safe today but fragile to future callers.

&lt;details&gt;
&lt;summary&gt;💡 Details&lt;/summary&gt;

```go
if overrides.Owner != &quot;&quot; {
    appOwner = overrides.Owner
    appOwnerType, err = bootstrapCheckOwnerType(ctx, appOwner)
    if err != nil {
        return  // naked return — appName, homepageURL, description are all &quot;…

</details>

<details><summary>pkg/cli/bootstrap_profile_runner.go:395</summary>

**Regression: `buildBootstrapGitHubAppMux` receives the original `owner`/`ownerType` instead of the override-resolved `appOwner`/`appOwnerType`**, causing GitHub App creation to use the wrong org/user when `overrides.Owner` is set.

&lt;details&gt;
&lt;summary&gt;💡 Details&lt;/summary&gt;

Line 395:
```go
Handler: buildBootstrapGitHubAppMux(ctx, state, owner, ownerType, appName, description, registrationPage, flowCh),

In the original code appOwner and appOwnerType were set in the same scope and were us…

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot please run the pr-finisher skill, address the unresolved review feedback below, complete the ADR linkage requested by the design gate, and rerun checks once the branch is up to date.

Unresolved review feedback:

Generated by 👨‍🍳 PR Sous Chef · 16.7 AIC · ⌖ 5.67 AIC · ⊞ 6K ·
Comment /souschef to run again

Copilot AI commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@copilot run pr-finisher skill

Running pr-finisher. Summary:

  • ✅ Reviews — No unresolved review threads. Two github-actions[bot] APPROVED reviews (Matt Pocock Skills Reviewer, Impeccable Skills Reviewer). The PR Code Quality Reviewer left non-blocking observations; none are regressions introduced by this PR (the owner/ownerType vs appOwner/appOwnerType pattern in the callback was identical in the original code, and the De Morgan guard in handleBootstrapGitHubAppCreateOrExistingChoice is correct).
  • ✅ Checks (local) — make fmt, make lint, make test-unit, and make agent-report-progress all pass locally.
  • ❓ Checks (CI) — Stale after agent push; needs human re-trigger. Prior runs show action_required for Smoke CI, Doc Build, CGO, and CWI — these need a maintainer to approve the workflow runs (GitHub security gate for bot-authored commits, not a code failure). No failed jobs in those runs.
  • ✅ Mergeable — PR is open, not draft, no conflicts. mergeable_state: unstable is due to the pending/action_required CI checks, not code issues.

Actions taken: Triage only — no code changes needed.
Hand-off: A maintainer needs to approve and re-trigger the action_required CI workflow runs (Smoke CI, Doc Build, CGO, CWI) before merge.

Copilot AI and others added 2 commits July 18, 2026 10:14
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
…r/appOwnerType to buildBootstrapGitHubAppMux; update ADR

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please run the pr-finisher skill, address the unresolved review feedback below, complete the ADR linkage requested by the design gate, and rerun checks once the branch is up to date.

Unres...

Done. Addressed in commit 1d9ed54:

Naked returns (setupBootstrapGitHubAppDetails): Removed named return variables; all return sites now use explicit values (return appOwner, appOwnerType, appName, homepageURL, description, nil / return "", "", "", "", "", err).

Owner propagation (buildBootstrapGitHubAppMux): Changed the call in createBootstrapGitHubApp from owner/ownerType to appOwner/appOwnerType so exchangeBootstrapGitHubAppCode stores the override-resolved owner in the created app result. This was a pre-existing latent bug exposed during extraction.

Guard semantics (handleBootstrapGitHubAppCreateOrExistingChoice): No code change — the De Morgan transformation is correct and matches original behavior. The original createNew := action.Mode == "create-or-existing" || overrides.Mode == "create" also admitted the block on overrides.Mode == "create" alone.

ADR: Updated to Accepted status with notes on both fixes.

ADR linkage in PR body: The design gate requires adding ADR: [ADR-46332…](docs/adr/46332-split-large-functions-bootstrap-profile-runner.md) to the PR body — this cannot be done by the agent directly. A maintainer should add this line and then re-trigger CI (approve the action_required workflow runs). The design gate will verify on the next run.

Local validation: make fmt, make lint, go vet, go test ./pkg/cli/..., make agent-report-progress, and parallel_validation all pass.

Copilot AI requested a review from gh-aw-bot July 18, 2026 10:28
@pelikhan
pelikhan merged commit b8e3ff7 into main Jul 18, 2026
23 checks passed
@pelikhan
pelikhan deleted the copilot/lint-monster-refactor-bootstrap-profile-runner branch July 18, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[lint-monster] [Code Quality] Reduce largefunc findings in pkg/cli bootstrap/profile runner slice

4 participants