Skip to content

[duplicate-code] Duplicate Code: repeated frontmatter trigger-condition parsing in YAML extraction #39028

@github-actions

Description

@github-actions

Summary

Several helpers in frontmatter_extraction_yaml.go repeat the same nested frontmatter["on"] traversal and value-normalization pattern for different triggers. The shape is duplicated across deployment status, workflow-run conclusion, slash-command, and label-command parsing.

Duplication Details

  • pkg/workflow/frontmatter_extraction_yaml.go:869-915
  • pkg/workflow/frontmatter_extraction_yaml.go:938-995
  • pkg/workflow/frontmatter_extraction_yaml.go:1016-1099
  • pkg/workflow/frontmatter_extraction_yaml.go:1102-1165

Impact

  • Each new on.* trigger variant risks adding another copy of the same map-walking and normalization logic.
  • Bug fixes to one parser path can be missed in the others, especially around validation and empty-value handling.

Refactoring Recommendation

Extract a small helper for nested on-section lookup and another for normalizing scalar-or-array values into a string slice. The trigger-specific helpers can then focus on validation and expression rendering instead of repeating frontmatter plumbing.

Code Sample

onValue, ok := frontmatter["on"]
onMap, ok := onValue.(map[string]any)
childValue, ok := onMap["workflow_run"]
...
if s, ok := value.(string); ok {
    conclusions = []string{s}
} else {
    conclusions = parseStringSliceAny(value, nil)
}

Analysis Metadata

  • Commit: 27e0d8d
  • Detection Method: Serena semantic code analysis + local source inspection

Generated by 🔍 Duplicate Code Detector · 78.6 AIC · ⌖ 12.1 AIC · ⊞ 14.8K ·

  • expires on Jun 14, 2026, 10:41 PM UTC-08:00

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions