Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions pkg/workflow/concurrency_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// # Validation Functions
//
// - validateConcurrencyGroupExpression() - Validates syntax of a single group expression
// - extractGroupExpression() - Extracts group value from concurrency configuration
//
// # Validation Coverage
//
Expand Down Expand Up @@ -283,31 +282,6 @@ func containsLogicalOperators(expr string) bool {
return strings.Contains(expr, "&&") || strings.Contains(expr, "||") || strings.Contains(expr, "!")
}

// extractGroupExpression extracts the group value from a concurrency configuration.
// Handles both string format ("group-name") and object format ({group: "group-name"}).
// Returns the group expression string or empty string if not found.
func extractGroupExpression(concurrency any) string {
if concurrency == nil {
return ""
}

// Handle string format (simple group name)
if groupStr, ok := concurrency.(string); ok {
return groupStr
}

// Handle object format with group field
if concurrencyObj, ok := concurrency.(map[string]any); ok {
if group, hasGroup := concurrencyObj["group"]; hasGroup {
if groupStr, ok := group.(string); ok {
return groupStr
}
}
}

return ""
}

// extractConcurrencyGroupFromYAML extracts the group value from a YAML-formatted concurrency string.
// The input is expected to be in the format generated by the compiler:
//
Expand Down
60 changes: 0 additions & 60 deletions pkg/workflow/concurrency_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,66 +486,6 @@ func TestContainsLogicalOperators(t *testing.T) {
}
}

func TestExtractGroupExpression(t *testing.T) {
tests := []struct {
name string
concurrency any
expected string
description string
}{
{
name: "string format",
concurrency: "my-workflow-group",
expected: "my-workflow-group",
description: "Simple string should be returned as-is",
},
{
name: "object format with group",
concurrency: map[string]any{
"group": "my-workflow-group",
},
expected: "my-workflow-group",
description: "Group value should be extracted from object",
},
{
name: "object format with group and cancel",
concurrency: map[string]any{
"group": "my-workflow-group",
"cancel-in-progress": true,
},
expected: "my-workflow-group",
description: "Group value should be extracted ignoring other fields",
},
{
name: "object format without group",
concurrency: map[string]any{
"cancel-in-progress": true,
},
expected: "",
description: "Missing group should return empty string",
},
{
name: "nil input",
concurrency: nil,
expected: "",
description: "Nil should return empty string",
},
{
name: "invalid type",
concurrency: 123,
expected: "",
description: "Invalid type should return empty string",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := extractGroupExpression(tt.concurrency)
assert.Equal(t, tt.expected, result, tt.description)
})
}
}

// TestValidateConcurrencyGroupExpressionRealWorld tests real-world concurrency group patterns
func TestValidateConcurrencyGroupExpressionRealWorld(t *testing.T) {
// These are actual patterns used in the codebase
Expand Down
56 changes: 0 additions & 56 deletions pkg/workflow/config_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
// Configuration Array Parsing:
// - ParseStringArrayFromConfig() - Generic string array extraction
// - parseLabelsFromConfig() - Extract labels array
// - parseParticipantsFromConfig() - Extract participants array
// - parseAllowedLabelsFromConfig() - Extract allowed labels array
//
// Configuration String Parsing:
Expand Down Expand Up @@ -124,40 +123,6 @@ func parseTargetRepoWithValidation(configMap map[string]any) (string, bool) {
return targetRepoSlug, false
}

// parseParticipantsFromConfig extracts and validates participants (assignees/reviewers) from a config map.
// Supports both string (single participant) and array (multiple participants) formats.
// Returns a slice of participant usernames, or nil if not present or invalid.
// The participantKey parameter specifies which key to look for (e.g., "assignees" or "reviewers").
func parseParticipantsFromConfig(configMap map[string]any, participantKey string) []string {
if participants, exists := configMap[participantKey]; exists {
configHelpersLog.Printf("Parsing %s from config", participantKey)

// Handle single string format
if participantStr, ok := participants.(string); ok {
configHelpersLog.Printf("Parsed single %s: %s", participantKey, participantStr)
return []string{participantStr}
}

// Handle array format
if participantsArray, ok := participants.([]any); ok {
var participantStrings []string
for _, participant := range participantsArray {
if participantStr, ok := participant.(string); ok {
participantStrings = append(participantStrings, participantStr)
}
}
// Return the slice even if empty (to distinguish from not provided)
if participantStrings == nil {
configHelpersLog.Printf("No valid %s strings found, returning empty array", participantKey)
return []string{}
}
configHelpersLog.Printf("Parsed %d %s from config", len(participantStrings), participantKey)
return participantStrings
}
}
return nil
}

// parseAllowedLabelsFromConfig extracts and validates allowed-labels from a config map.
// Returns a slice of label strings, or nil if not present or invalid.
func parseAllowedLabelsFromConfig(configMap map[string]any) []string {
Expand Down Expand Up @@ -210,27 +175,6 @@ func preprocessExpiresField(configData map[string]any, log *logger.Logger) bool
return expiresDisabled
}

// ParseIntFromConfig is a generic helper that extracts and validates an integer value from a map.
// Supports int, int64, float64, and uint64 types.
// Returns the integer value, or 0 if not present or invalid.
// If log is provided, it will log the extracted value for debugging.
// Note: For uint64 values, returns 0 if the value would overflow int.
func ParseIntFromConfig(m map[string]any, key string, log *logger.Logger) int {
if value, exists := m[key]; exists {
if log != nil {
log.Printf("Parsing %s from config", key)
}
// Use parseIntValue for the actual type conversion
if result, ok := parseIntValue(value); ok {
if log != nil {
log.Printf("Parsed %s from config: %d", key, result)
}
return result
}
}
return 0
}

// ParseBoolFromConfig is a generic helper that extracts and validates a boolean value from a map.
// Returns the boolean value, or false if not present or invalid.
// If log is provided, it will log the extracted value for debugging.
Expand Down
Loading
Loading