Skip to content

[code-simplifier] refactor: extract writeStepsSection helper to eliminate pre/post-steps duplication#25256

Merged
pelikhan merged 1 commit intomainfrom
code-simplifier/dedup-steps-section-writer-373a26be21b0213e
Apr 8, 2026
Merged

[code-simplifier] refactor: extract writeStepsSection helper to eliminate pre/post-steps duplication#25256
pelikhan merged 1 commit intomainfrom
code-simplifier/dedup-steps-section-writer-373a26be21b0213e

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 8, 2026

This PR simplifies recently modified code from PR #25242 (feat: add pre-steps to agent job) to eliminate code duplication introduced by the new feature.

Files Simplified

  • pkg/workflow/compiler_yaml.go — extracted shared writeStepsSection helper

Improvements Made

Eliminated duplicated step-rendering logic

generatePreSteps and generatePostSteps had byte-for-byte identical implementations: strip the YAML header line (pre-steps: / post-steps:), skip blank lines, and normalise indentation to 6/8 spaces. A shared writeStepsSection helper now owns this logic:

func writeStepsSection(yaml *strings.Builder, stepsYAML string) {
    if stepsYAML == "" {
        return
    }
    lines := strings.Split(stepsYAML, "\n")
    for _, line := range lines[1:] { // skip the header line
        trimmed := strings.TrimRight(line, " ")
        if strings.TrimSpace(trimmed) == "" {
            yaml.WriteString("\n")
            continue
        }
        if strings.HasPrefix(line, "  ") {
            yaml.WriteString("        " + line[2:] + "\n")
        } else {
            yaml.WriteString("      " + line + "\n")
        }
    }
}

The two callers become one-liners, and future changes to indentation/whitespace handling only need to happen in one place.

Changes Based On

Recent changes from:

Testing

  • TestPreStepsGeneration passes (step order: pre-step < checkout < custom < AI < post)
  • go test ./pkg/workflow/ — all 1665-file package tests pass (21s)
  • go vet ./pkg/workflow/... — clean
  • ✅ Build succeeds (make build)
  • ✅ No functional changes — behaviour is identical

Review Focus

Please verify:

  • writeStepsSection preserves the exact indentation behaviour of both original functions
  • The helper is correctly skipping the header line (lines[1:])
  • No unintended side effects on pre-steps or post-steps rendering

Automated by Code Simplifier Agent — analysing code from the last 24 hours

References: §24120682674

Note

🔒 Integrity filter blocked 2 items

The following items were blocked because they don't meet the GitHub integrity level.

  • #25153 search_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".
  • #25152 search_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".

To allow these resources, lower min-integrity in your GitHub frontmatter:

tools:
  github:
    min-integrity: approved  # merged | approved | unapproved | none

Generated by Code Simplifier · ● 3.1M ·

  • expires on Apr 9, 2026, 6:17 AM UTC

…s duplication

generatePreSteps and generatePostSteps had identical implementations for
stripping the YAML header line and normalising indentation. Extract a shared
writeStepsSection helper so the logic lives in one place.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review April 8, 2026 11:47
Copilot AI review requested due to automatic review settings April 8, 2026 11:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 refactors YAML step rendering in the workflow compiler by extracting shared pre/post-steps formatting logic into a single helper, removing duplication introduced by the earlier pre-steps feature work.

Changes:

  • Extracted shared step-section rendering logic into writeStepsSection.
  • Simplified generatePreSteps and generatePostSteps to delegate to the shared helper.
Show a summary per file
File Description
pkg/workflow/compiler_yaml.go Removes duplicated pre/post-steps YAML rendering code by introducing writeStepsSection and delegating both generators to it.

Copilot's findings

Tip

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

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

@pelikhan pelikhan merged commit 5ad4f46 into main Apr 8, 2026
65 of 67 checks passed
@pelikhan pelikhan deleted the code-simplifier/dedup-steps-section-writer-373a26be21b0213e branch April 8, 2026 11:58
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.

2 participants