Skip to content

refactor: extract helpers to bring 3 functions under the 60-line largefunc limit#42624

Merged
pelikhan merged 5 commits into
mainfrom
copilot/lint-monster-cleanup-largefunc
Jul 1, 2026
Merged

refactor: extract helpers to bring 3 functions under the 60-line largefunc limit#42624
pelikhan merged 5 commits into
mainfrom
copilot/lint-monster-cleanup-largefunc

Conversation

Copilot AI commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Three functions flagged by the custom largefunc linter (limit: 60 lines) are refactored by extracting focused private helpers. No behavioural changes.

Extractions

  • pkg/console/console.goRenderTable (67 → ~46 lines)
    Pulled the styleFunc closure out into buildTableStyleFunc(config, ttyCheck, dataRowCount).

  • pkg/github/label_objective_mapping.goComputeObjectiveValue (67 → ~37 lines)
    Each switch branch moved to its own method: computeValueSum, computeValueFirst, computeValueMax.

  • pkg/parser/schema_suggestions.gofindFieldLocationsInSchema (72 → ~14 lines)
    The two scanning loops extracted into collectExactFieldMatches and collectFuzzyFieldMatches.

// Before — monolithic
func findFieldLocationsInSchema(schemaDoc any, targetField, currentPath string) []schemaFieldLocation {
    // 72 lines: exact-match loop + fuzzy loop + sort inline
}

// After — delegating
func findFieldLocationsInSchema(schemaDoc any, targetField, currentPath string) []schemaFieldLocation {
    allLocations := collectSchemaPropertyPaths(schemaDoc, "", 0)
    if exact := collectExactFieldMatches(allLocations, targetField, currentPath); len(exact) > 0 {
        return exact
    }
    return collectFuzzyFieldMatches(allLocations, strings.ToLower(targetField), currentPath)
}

Copilot AI and others added 3 commits July 1, 2026 04:08
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…thub, parser

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 non-workflow largefunc functions to meet line limit refactor: extract helpers to bring 3 functions under the 60-line largefunc limit Jul 1, 2026
Copilot AI requested a review from pelikhan July 1, 2026 04:13
@pelikhan pelikhan marked this pull request as ready for review July 1, 2026 04:20
Copilot AI review requested due to automatic review settings July 1, 2026 04:20
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jul 1, 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 1, 2026

Copy link
Copy Markdown
Contributor

⚠️ PR Code Quality Reviewer failed during code quality review.

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

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

No ADR enforcement needed: PR does not have the 'implementation' label and has ≤100 new lines of code in business logic directories (95 additions detected, threshold is 100).

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

This PR primarily refactors three Go functions that exceeded the custom largefunc (60-line) limit by extracting focused private helpers, aiming to keep behavior unchanged. It also includes a GitHub Actions workflow change that alters actions/checkout behavior and should be either justified in the PR description or reverted.

Changes:

  • Extracted helper functions in pkg/console, pkg/github, and pkg/parser to reduce function length under the largefunc threshold.
  • Introduced a documentation mismatch in computeValueFirst (comment describes priority-order evaluation that the code does not implement).
  • Updated .github/workflows/agentics-maintenance.yml to set clean: false on multiple actions/checkout steps (behavioral change not mentioned in the PR description).
Show a summary per file
File Description
pkg/parser/schema_suggestions.go Extracts exact/fuzzy matching loops into helper functions for schema field suggestions.
pkg/github/label_objective_mapping.go Extracts per-logic branches (sum/first/max) into helper methods.
pkg/console/console.go Extracts the table StyleFunc closure into buildTableStyleFunc.
.github/workflows/agentics-maintenance.yml Changes checkout behavior by disabling workspace cleaning in multiple jobs.

Review details

Tip

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

  • Files reviewed: 4/4 changed files
  • Comments generated: 10
  • Review effort level: Low

Comment thread pkg/github/label_objective_mapping.go Outdated
Comment on lines +85 to +87
// computeValueFirst returns the value for the highest-priority matching label.
// It walks issueLabels in priority order; if none match, it falls back to the
// first label in matchingValues.
Comment on lines 108 to 111
sparse-checkout: |
actions
clean: false
persist-credentials: false
Comment thread .github/workflows/agentics-maintenance.yml
Comment thread .github/workflows/agentics-maintenance.yml
Comment thread .github/workflows/agentics-maintenance.yml
Comment thread .github/workflows/agentics-maintenance.yml
Comment thread .github/workflows/agentics-maintenance.yml
Comment thread .github/workflows/agentics-maintenance.yml
Comment thread .github/workflows/agentics-maintenance.yml
Comment thread .github/workflows/agentics-maintenance.yml

@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 — two observations, no blocking issues.

📋 Key Themes & Highlights

Key Themes

  • Unrelated workflow changes: 8 clean: false additions to .github/workflows/agentics-maintenance.yml are not mentioned in the PR description. Either document the reason or extract to a separate PR.
  • Implicit preconditions: computeValueFirst and computeValueMax both index matchingValues[0] without documenting the len(matchingValues) > 0 precondition. Safe today (caller guards at line 56), but worth documenting now that these are standalone methods.

Positive Highlights

  • ✅ All three extractions are clean and preserve the original logic exactly
  • ✅ Good doc comments on buildTableStyleFunc, collectExactFieldMatches, and collectFuzzyFieldMatches
  • ✅ The schema_suggestions.go refactor is the most impressive — 72 → 14 lines with well-named helpers and correct sort/log placement
  • ✅ Existing tests (label_objective_mapping_test.go, schema_suggestions_test.go) cover the three extraction paths through the public API, so behavioral regression is guarded
  • ✅ Minor style cleanup (struct{} vs struct {\n}) is a nice bonus

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · 51 AIC · ⌖ 7.32 AIC · ⊞ 6.6K
Comment /matt to run again

with:
sparse-checkout: |
actions
clean: false

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.

[/codebase-design] These clean: false additions are unrelated to the stated PR goal (largefunc refactoring) and are not mentioned in the PR description.

💡 Suggestion

Either:

  1. Add a brief note in the PR description explaining why clean: false is needed here, or
  2. Extract these workflow changes into a separate PR for a cleaner commit history.

Keeping unrelated operational fixes separate from refactoring PRs makes bisect and rollback much easier.

@copilot please address this.

return result
}
// Fallback to first matching label
result := matchingValues[0]

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.

[/codebase-design] computeValueFirst (and computeValueMax at line 111) silently require len(matchingValues) > 0 but neither the signature nor the doc comment states this precondition.

💡 Suggestion

The caller (ComputeObjectiveValue) guards against this at line 56, so it is safe today. However, since these are now standalone methods, a future caller could pass an empty slice and get a panic with no obvious explanation. Add the precondition to the doc comment:

// computeValueFirst returns the value for the highest-priority matching label.
// It walks issueLabels in priority order; if none match, it falls back to the
// first label in matchingValues.
// Precondition: len(matchingValues) > 0.
func (om *ObjectiveMapping) computeValueFirst(...) int {

Same addition applies to computeValueMax.

@copilot please address this.

@pelikhan

pelikhan commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

…low clean:false changes

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot run pr-finisher skill

Done in 54a5e85. Two issues addressed:

  1. computeValueFirst doc comment — corrected to accurately describe that the function iterates issueLabels in their existing order and checks membership in PriorityLabels, rather than the misleading "walks in priority order" phrasing.

  2. clean: false in agentics-maintenance.yml — reverted all 8 occurrences. These were introduced when the file was regenerated from source during the planning step; since they're outside the scope of this refactor PR, the file is restored to its original state.

All local checks pass (make fmt, make lint, make test-unit).

@pelikhan pelikhan merged commit c232cfd into main Jul 1, 2026
28 of 29 checks passed
@pelikhan pelikhan deleted the copilot/lint-monster-cleanup-largefunc branch July 1, 2026 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[lint-monster] Small non-workflow largefunc cleanup (2026-07-01)

3 participants