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

Method parseBaseSafeOutputConfig

pkg/workflow/safe_outputs_config.go:817–881  ·  view source on GitHub ↗

parseBaseSafeOutputConfig parses common fields (max, github-token, github-app, staged) from a config map. If defaultMax is provided (> 0), it will be set as the default value for config.Max before parsing the max field from configMap. Supports both integer values and GitHub Actions expression string

(configMap map[string]any, config *BaseSafeOutputConfig, defaultMax int)

Source from the content-addressed store, hash-verified

815// before parsing the max field from configMap. Supports both integer values and GitHub
816// Actions expression strings (e.g. "${{ inputs.max }}").
817func (c *Compiler) parseBaseSafeOutputConfig(configMap map[string]any, config *BaseSafeOutputConfig, defaultMax int) {
818 // Set default max if provided
819 if defaultMax > 0 {
820 safeOutputsConfigLog.Printf("Setting default max: %d", defaultMax)
821 config.Max = defaultIntStr(defaultMax)
822 }
823
824 // Parse max (this will override the default if present in configMap)
825 if max, exists := configMap["max"]; exists {
826 switch v := max.(type) {
827 case string:
828 // Accept GitHub Actions expression strings
829 if strings.HasPrefix(v, "${{") && strings.HasSuffix(v, "}}") {
830 safeOutputsConfigLog.Printf("Parsed max as GitHub Actions expression: %s", v)
831 config.Max = &v
832 }
833 default:
834 // Convert integer/float64/etc to string via typeutil.ParseIntValue
835 if maxInt, ok := typeutil.ParseIntValue(max); ok {
836 safeOutputsConfigLog.Printf("Parsed max as integer: %d", maxInt)
837 s := defaultIntStr(maxInt)
838 config.Max = s
839 }
840 }
841 }
842
843 // Parse github-token
844 if githubToken, exists := configMap["github-token"]; exists {
845 if githubTokenStr, ok := githubToken.(string); ok {
846 safeOutputsConfigLog.Print("Parsed custom github-token from config")
847 config.GitHubToken = githubTokenStr
848 }
849 }
850
851 // Parse github-app (per-handler GitHub App credentials for token minting)
852 if app, exists := configMap["github-app"]; exists {
853 if appMap, ok := app.(map[string]any); ok {
854 safeOutputsConfigLog.Print("Parsed custom github-app from config")
855 config.GitHubApp = parseAppConfig(appMap)
856 }
857 }
858
859 // Parse staged flag (per-handler staged mode)
860 if err := preprocessBoolFieldAsString(configMap, "staged", safeOutputsConfigLog); err != nil {
861 safeOutputsConfigLog.Printf("Invalid staged value: %v", err)
862 } else if staged, exists := configMap["staged"]; exists {
863 if stagedStr, ok := staged.(string); ok && stagedStr != "" {
864 safeOutputsConfigLog.Printf("Parsed staged flag: %s", stagedStr)
865 value := TemplatableBool(stagedStr)
866 config.Staged = &value
867 }
868 }
869
870 // Parse samples list (hidden feature: deterministic replay samples for --use-samples).
871 // Accepts either a YAML list of objects, or a single object that is auto-wrapped
872 // into a one-element list. The JSON schema rejects scalar/string shapes so we
873 // don't need a defensive YAML-string branch here.
874 if samples, exists := configMap["samples"]; exists {

Calls 8

ParseIntValueFunction · 0.92
defaultIntStrFunction · 0.85
parseAppConfigFunction · 0.85
TemplatableBoolTypeAlias · 0.85
parseSamplesValueFunction · 0.85
PrintMethod · 0.80
PrintfMethod · 0.45

Tested by

no test coverage detected