Skip to content

[code-simplifier] refactor: simplify lock file reading and project config string extraction#20978

Closed
github-actions[bot] wants to merge 1 commit intomainfrom
code-simplifier/2026-03-14-3e362eb6255e481b
Closed

[code-simplifier] refactor: simplify lock file reading and project config string extraction#20978
github-actions[bot] wants to merge 1 commit intomainfrom
code-simplifier/2026-03-14-3e362eb6255e481b

Conversation

@github-actions
Copy link
Contributor

Code simplification of recently merged PRs (#20951 and #20939).

Files Simplified

  • pkg/cli/run_workflow_validation.go — extracted readLockFile() helper to eliminate ~30 lines of duplicated code
  • pkg/workflow/project_config_parsing.go — replaced verbose multi-line string extraction with existing extractStringFromMap() helper (~27 lines removed)

Improvements Made

1. Extracted readLockFile() helper (run_workflow_validation.go)

IsRunnable and getWorkflowInputs shared identical logic for reading and parsing the compiled lock file:

  • getLockFilePath + filepath.Clean
  • os.Stat existence check with the same error message
  • os.ReadFile with #nosec G304
  • yaml.Unmarshal with identical error wrapping

Extracted into a single readLockFile(markdownPath string) (map[string]any, error) helper. Both callers now use it, preserving all debug logging.

2. Used extractStringFromMap() helper (project_config_parsing.go)

The new parseProjectViews and parseProjectFieldDefinitions functions (from PR #20939) used a verbose 4-line pattern to extract each string field:

if name, exists := viewMap["name"]; exists {
    if nameStr, ok := name.(string); ok {
        view.Name = nameStr
    }
}

extractStringFromMap() already exists in pkg/workflow/config_helpers.go for exactly this purpose. Changed to use struct initialization with single-line calls:

view := ProjectView{
    Name:        extractStringFromMap(viewMap, "name", nil),
    Layout:      extractStringFromMap(viewMap, "layout", nil),
    Filter:      extractStringFromMap(viewMap, "filter", nil),
    Description: extractStringFromMap(viewMap, "description", nil),
}

Changes Based On

Testing

  • ✅ All relevant tests pass (TestValidateWorkflowInputs, TestParseProjectViews, TestParseProjectFieldDefinitions, etc.)
  • ✅ Build succeeds (make build)
  • go vet clean
  • ✅ No functional changes — behavior is identical (net -57 lines)

Generated by Code Simplifier ·

  • expires on Mar 15, 2026, 7:02 PM UTC

- Extract readLockFile() helper in run_workflow_validation.go to
  eliminate duplicated file reading/parsing logic between IsRunnable
  and getWorkflowInputs (~30 lines removed)
- Use existing extractStringFromMap() helper in project_config_parsing.go
  to replace verbose 4-line string extraction pattern with single-line
  struct initialization (~27 lines removed)

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

@copilot lint

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 recently added workflow validation and project config parsing logic to reduce duplication and simplify string extraction.

Changes:

  • Extracted a shared readLockFile() helper to centralize lock file existence checks, reading, and YAML unmarshaling.
  • Simplified project config parsing by using extractStringFromMap() for views and field-definitions string fields.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/workflow/project_config_parsing.go Replaces manual string field extraction with extractStringFromMap() and keeps required-field filtering.
pkg/cli/run_workflow_validation.go Introduces readLockFile() and updates IsRunnable / getWorkflowInputs to use it.

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

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +75 to 81
field := ProjectFieldDefinition{
Name: extractStringFromMap(fieldMap, "name", nil),
DataType: extractStringFromMap(fieldMap, "data-type", nil),
}
if dataTypeStr, ok := dataType.(string); ok {
field.DataType = dataTypeStr
if field.DataType == "" {
field.DataType = extractStringFromMap(fieldMap, "data_type", nil)
}
Comment on lines 66 to 69
onSection, exists := workflowYAML["on"]
if !exists {
validationLog.Printf("No 'on' section found in lock file")
// If no 'on' section, it's not runnable
return false, nil
}
@pelikhan pelikhan closed this Mar 14, 2026
Copy link
Contributor

Copilot AI commented Mar 14, 2026

@copilot lint

Lint passed with 0 issues. All Go code is properly formatted and all JavaScript/JSON files pass Prettier checks.

Copilot AI requested a review from pelikhan March 14, 2026 19:41
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.

3 participants