Skip to content

Duplicate Code: project config parsing duplicated in create/update project handlers #20905

@github-actions

Description

@github-actions

Overview

Semantic analysis found a large duplicated parsing block between project-related safe-output config parsers. The duplication covers view parsing and field-definition parsing logic and is significant enough to warrant extraction into shared helpers.

Critical Information

  • Severity: High
  • Pattern type: Structural duplication
  • Occurrences: 2 major occurrences
  • Estimated duplicated size: ~100+ lines
  • Commit analyzed: b00338445c8308b1244fee1a182248509d0ccb40

Duplication Details

  • Primary locations:

    • pkg/workflow/create_project.go ((*Compiler).parseCreateProjectsConfig, lines 17-164)
    • pkg/workflow/update_project.go ((*Compiler).parseUpdateProjectConfig, lines 33-172)
  • Repeated sub-block examples:

    • visible-fields parsing appears in both methods:
      • pkg/workflow/create_project.go lines 80-85
      • pkg/workflow/update_project.go lines 88-93
    • field-definitions parsing appears in both methods:
      • pkg/workflow/create_project.go lines 110-144
      • pkg/workflow/update_project.go lines 118-152
Code Sample (Representative Duplicate Block)
// Parse field-definitions if specified
fieldsData, hasFields := configMap["field-definitions"]
if !hasFields {
	fieldsData, hasFields = configMap["field_definitions"]
}
if hasFields {
	if fieldsList, ok := fieldsData.([]any); ok {
		for i, fieldItem := range fieldsList {
			fieldMap, ok := fieldItem.(map[string]any)
			if !ok {
				continue
			}

			field := ProjectFieldDefinition{}
			// ... parse name, data-type/data_type, options ...
			if field.Name != "" && field.DataType != "" {
				cfg.FieldDefinitions = append(cfg.FieldDefinitions, field)
			}
		}
	}
}

Impact Analysis

  • Maintainability: Fixes to parsing rules must be repeated in both code paths.
  • Bug risk: Divergence risk is high (e.g., one path accepts new schema aliases while the other does not).
  • Code bloat: Large duplicated loops and field-mapping logic increase review and test burden.

Refactoring Recommendations

  1. Extract shared project parser helpers
  • Add helper(s) for parsing views and field-definitions, reused by both create/update paths.
  • Suggested location: pkg/workflow/project_config_parsing.go.
  • Estimated effort: Medium (2-4 hours including tests).
  1. Unify project-specific envelope parsing
  • Keep command-specific fields (title-prefix vs project) in thin wrappers, but delegate common body parsing.
  • Benefit: single source of truth for schema alias handling and validation.
  1. Add regression tests for shared helpers
  • Ensure identical behavior for both create/update entry points using table-driven fixtures.

Implementation Checklist

  • Extract shared parser for views
  • Extract shared parser for field-definitions
  • Wire both parseCreateProjectsConfig and parseUpdateProjectConfig to shared helpers
  • Add parity tests covering both command paths
  • Verify no behavior regressions in existing workflow compilation tests

Analysis Metadata

  • Detection method: Serena semantic analysis (get_symbols_overview, find_symbol, search_for_pattern)
  • Scope analyzed: non-test Go code in pkg/workflow from current commit snapshot
  • Workflow run: §23079853425

References:

Generated by Duplicate Code Detector ·

Warning

⚠️ Firewall blocked 1 domain

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

  • ab.chatgpt.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "ab.chatgpt.com"

See Network Configuration for more information.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions