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
15 changes: 6 additions & 9 deletions pkg/workflow/add_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,13 @@ func (c *Compiler) parseCommentsConfig(outputMap map[string]any) *AddCommentsCon
}
}

// Parse target-repo
if targetRepoSlug, exists := configMap["target-repo"]; exists {
if targetRepoStr, ok := targetRepoSlug.(string); ok {
// Validate that target-repo is not "*" - only definite strings are allowed
if targetRepoStr == "*" {
return nil // Invalid configuration, return nil to cause validation error
}
commentsConfig.TargetRepoSlug = targetRepoStr
}
// Parse target-repo using shared helper
targetRepoSlug := parseTargetRepoFromConfig(configMap)
// Validate that target-repo is not "*" - only definite strings are allowed
if targetRepoSlug == "*" {
return nil // Invalid configuration, return nil to cause validation error
}
commentsConfig.TargetRepoSlug = targetRepoSlug

// Parse discussion
if discussion, exists := configMap["discussion"]; exists {
Expand Down
46 changes: 46 additions & 0 deletions pkg/workflow/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package workflow

// parseLabelsFromConfig extracts and validates labels from a config map
// Returns a slice of label strings, or nil if labels is not present or invalid
func parseLabelsFromConfig(configMap map[string]any) []string {
if labels, exists := configMap["labels"]; exists {
if labelsArray, ok := labels.([]any); ok {
var labelStrings []string
for _, label := range labelsArray {
if labelStr, ok := label.(string); ok {
labelStrings = append(labelStrings, labelStr)
}
}
// Return the slice even if empty (to distinguish from not provided)
if labelStrings == nil {
return []string{}
}
return labelStrings
}
}
return nil
}

// parseTitlePrefixFromConfig extracts and validates title-prefix from a config map
// Returns the title prefix string, or empty string if not present or invalid
func parseTitlePrefixFromConfig(configMap map[string]any) string {
if titlePrefix, exists := configMap["title-prefix"]; exists {
if titlePrefixStr, ok := titlePrefix.(string); ok {
return titlePrefixStr
}
}
return ""
}

// parseTargetRepoFromConfig extracts and validates target-repo from a config map
// Returns the target repository slug, or empty string if not present or invalid
// Returns error string "*" if the wildcard value is used (which is invalid for target-repo)
// Callers should check for "*" and handle it as an error condition
func parseTargetRepoFromConfig(configMap map[string]any) string {
if targetRepoSlug, exists := configMap["target-repo"]; exists {
if targetRepoStr, ok := targetRepoSlug.(string); ok {
return targetRepoStr
}
}
return ""
}
Loading
Loading