Skip to content

Comments

[code-simplifier] refactor: extract setStringFromMap helper in parseMessagesConfig#17258

Merged
pelikhan merged 1 commit intomainfrom
code-simplifier/2026-02-20-4b9a9be9d8a0d274
Feb 20, 2026
Merged

[code-simplifier] refactor: extract setStringFromMap helper in parseMessagesConfig#17258
pelikhan merged 1 commit intomainfrom
code-simplifier/2026-02-20-4b9a9be9d8a0d274

Conversation

@github-actions
Copy link
Contributor

The parseMessagesConfig function in pkg/workflow/safe_outputs_config_messages.go had 12 identical 4-line blocks for parsing string fields from a map[string]any. This PR extracts a setStringFromMap helper function to eliminate the repetition while preserving identical behavior.

Files Simplified

  • pkg/workflow/safe_outputs_config_messages.go — extracted setStringFromMap helper; reduced parseMessagesConfig from ~100 to ~50 lines

Improvements Made

Reduced Repetition

Before, each string field required 4 lines:

if footer, exists := messagesMap["footer"]; exists {
    if footerStr, ok := footer.(string); ok {
        config.Footer = footerStr
    }
}

After, each string field is one line:

setStringFromMap(messagesMap, "footer", &config.Footer)

Applied Project Standards

  • Helper function is small, focused, and well-commented
  • All 12 string field assignments now use the helper consistently
  • The boolean field (append-only-comments) retains its own block since it has a log statement and a different type

Changes Based On

Recent changes from:

Testing

  • ✅ File is gofmt-compliant (gofmt -l produces no output)
  • go vet passes (no compile errors or type issues)
  • ✅ No functional changes — behavior is identical; only the structure changed

Review Focus

Please verify:

  • All 12 string fields are still correctly mapped to their YAML keys
  • The boolean append-only-comments field is still handled separately (it has a debug log call)
  • No unintended side effects

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

Generated by Code Simplifier

Warning

⚠️ Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • proxy.golang.org
  • expires on Feb 21, 2026, 7:08 PM UTC

The parseMessagesConfig function had 12 identical 4-line blocks for
parsing string fields from a map. Extract a setStringFromMap helper
to eliminate the repetition while preserving identical behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review February 20, 2026 19:16
Copilot AI review requested due to automatic review settings February 20, 2026 19:16
@pelikhan pelikhan merged commit 86ac7ac into main Feb 20, 2026
@pelikhan pelikhan deleted the code-simplifier/2026-02-20-4b9a9be9d8a0d274 branch February 20, 2026 19:16
Copy link
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

Refactors parseMessagesConfig to remove repeated “read string from map and assign” blocks by introducing a small helper, aiming to preserve existing parsing behavior.

Changes:

  • Added setStringFromMap helper to DRY up string-field extraction from map[string]any
  • Updated parseMessagesConfig to use the helper for all string message fields
  • Kept append-only-comments parsing as a dedicated bool block (with logging)

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

Comment on lines +37 to +48
setStringFromMap(messagesMap, "footer", &config.Footer)
setStringFromMap(messagesMap, "footer-install", &config.FooterInstall)
setStringFromMap(messagesMap, "footer-workflow-recompile", &config.FooterWorkflowRecompile)
setStringFromMap(messagesMap, "footer-workflow-recompile-comment", &config.FooterWorkflowRecompileComment)
setStringFromMap(messagesMap, "staged-title", &config.StagedTitle)
setStringFromMap(messagesMap, "staged-description", &config.StagedDescription)
setStringFromMap(messagesMap, "run-started", &config.RunStarted)
setStringFromMap(messagesMap, "run-success", &config.RunSuccess)
setStringFromMap(messagesMap, "run-failure", &config.RunFailure)
setStringFromMap(messagesMap, "detection-failure", &config.DetectionFailure)
setStringFromMap(messagesMap, "agent-failure-issue", &config.AgentFailureIssue)
setStringFromMap(messagesMap, "agent-failure-comment", &config.AgentFailureComment)
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

parseMessagesConfig now sets detection-failure, agent-failure-issue, and agent-failure-comment via the new helper, but the existing TestParseMessagesConfig assertions (in pkg/workflow/safe_outputs_test.go) don’t cover these fields (or append-only-comments). Adding/expanding tests to assert these mappings would help catch accidental key/field mixups during refactors like this.

Copilot uses AI. Check for mistakes.
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.

1 participant