Skip to content

[file-diet] Refactor pkg/parser/import_field_extractor.go (1190 lines) #76861

Done

Description

@github-actions

Overview

pkg/parser/import_field_extractor.go has grown to 1190 lines (threshold 800), mixing import orchestration, engine/config extraction, activation merging, model policy normalization, and result building. Split it into focused files.

Current State

  • File: pkg/parser/import_field_extractor.go
  • Size: 1190 lines (~60 funcs, one large importAccumulator struct at L20-120)
  • Test file: pkg/parser/import_field_extractor_test.go (1178 lines, ratio ≈ 0.99)
  • Complexity: Single god-struct (importAccumulator) with many extract*/merge*/append* methods; several independent domains.
Full File Analysis
  • L20-135: importAccumulator type + constructor
  • L137-368: orchestration (extractImportFields, prepareFrontmatter, inline sub-agent warnings, tools content, markdown helpers)
  • L369-560: engine, config and concurrency extraction
  • L558-760: sandbox mounts, generic JSON/YAML field helpers, activation fields (bots, skip-roles, github-token/app)
  • L751-850: checkout, steps/jobs, ordered steps, feature/observability
  • L852-1020: model policy/alias/provider normalization (self-contained pure functions)
  • L1004-1070: plugins, run-install-scripts, observability
  • L1071-1190: result building, computeImportRelPath, validateGitHubAppJSON

Refactoring Strategy

  1. import_accumulator.go (~170 lines): importAccumulator, newImportAccumulator, toImportsResult, buildImportsResult, populateImportsResultScalars.
  2. import_extract_frontmatter.go (~230 lines): extractImportFields, prepareFrontmatter, parseOriginalFrontmatter, frontmatterMapOrEmpty, sub-agent warnings, extractToolsContent, trackRuntimeOrInlineImport, appendMarkdownWithSeparator, parseFrontmatterForExtraction.
  3. import_extract_engine.go (~230 lines): engine config, MCP settings, config fields, concurrency, mergeSandboxAgentMounts, mustMarshalJSON.
  4. import_extract_activation.go (~190 lines): activation fields, merge* list helpers, mergeJSONStringListField, skip match/token/app fields, validateGitHubAppJSON.
  5. import_extract_models.go (~180 lines): appendModelsField, normalizeModel*, parseModelPolicyField, sanitizeModelProvidersForCosts, parseStringSliceField, isModelPolicyKey.
  6. import_extract_steps.go (~150 lines): checkout, step/job/ordered-step fields, feature/observability, plugins, run-install-scripts, cache/labels/excluded-env, computeImportRelPath.
  7. Generic extractFirstWins*/append*Field helpers could go to import_extract_helpers.go.
Test Coverage Plan

Split the existing test file along the same lines (one _test.go per new file), targeting >80% coverage each; add tests for model normalization edge cases and validateGitHubAppJSON.

Implementation Guidelines

Preserve behavior and exports; move code in small steps, running make test-unit after each; run make fmt and make lint.

Acceptance Criteria

  • Split into ~6 files, each under 500 lines
  • make test-unit, make lint, make build pass
  • No public API changes

Priority: Medium · Effort: Medium · Impact: Better maintainability and testability

Generated by 🧹 Daily File Diet · copilot · auto (Claude Sonnet 5.5) · ~18 AIC · ⌖ ~2 AIC · ⊞ 13.3K · ◷

  • expires on Nov 13, 2026, 4:45 AM UTC-08:00

Activity

  1. github-actions commented on Nov 11, 2026

    @github-actions
    ContributorAuthor

    🍪 Issue Monster selected this for Copilot

    I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.

    If assignment succeeds, Copilot will analyze the issue and create a pull request with the fix.

    Om nom nom! 🍪

    🍪 Om nom nom by Issue Monster · pi · gpt50 · ~1 AIC · ⌖ ~1 AIC · ⊞ 11.7K · ◷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions