MCPcopy Create free account
hub / github.com/github/gh-aw / validateTargetValue

Function validateTargetValue

pkg/workflow/safe_outputs_validation.go:174–210  ·  view source on GitHub ↗

validateTargetValue validates a single target value

(configName, target string)

Source from the content-addressed store, hash-verified

172
173// validateTargetValue validates a single target value
174func validateTargetValue(configName, target string) error {
175 // Empty or "triggering" are always valid
176 if target == "" || target == "triggering" {
177 return nil
178 }
179
180 // "*" is valid (any item)
181 if target == "*" {
182 return nil
183 }
184
185 // Check if it's a GitHub Actions expression
186 if containsExpression(target) {
187 safeOutputsTargetValidationLog.Printf("Target for %s is a GitHub Actions expression", configName)
188 return nil
189 }
190
191 // Check if it's a positive integer
192 if stringutil.IsPositiveInteger(target) {
193 safeOutputsTargetValidationLog.Printf("Target for %s is a valid number: %s", configName, target)
194 return nil
195 }
196
197 // Build a helpful suggestion based on the invalid value
198 suggestion := ""
199 if target == "event" || strings.Contains(target, "github.event") {
200 suggestion = "\n\nDid you mean to use \"${{ github.event.issue.number }}\" instead of \"" + target + "\"?"
201 }
202
203 // Invalid target value
204 return fmt.Errorf(
205 "invalid target value for %s: %q\n\nValid target values are:\n - \"triggering\" (default) - targets the triggering issue/PR/discussion\n - \"*\" - targets any item specified in the output\n - A positive integer (e.g., \"123\")\n - A GitHub Actions expression (e.g., \"${{ github.event.issue.number }}\")%s",
206 configName,
207 target,
208 suggestion,
209 )
210}
211
212var safeOutputsAllowWorkflowsValidationLog = newValidationLogger("safe_outputs_allow_workflows")
213

Callers 2

TestValidateTargetValueFunction · 0.85

Calls 4

IsPositiveIntegerFunction · 0.92
containsExpressionFunction · 0.85
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by 1

TestValidateTargetValueFunction · 0.68