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

Method parseSafeJobsConfig

pkg/workflow/safe_jobs.go:38–180  ·  view source on GitHub ↗

parseSafeJobsConfig parses safe-jobs configuration from a jobs map. This function expects a map of job configurations directly (from safe-outputs.jobs). The top-level "safe-jobs" key is NOT supported - only "safe-outputs.jobs" is valid.

(jobsMap map[string]any)

Source from the content-addressed store, hash-verified

36// This function expects a map of job configurations directly (from safe-outputs.jobs).
37// The top-level "safe-jobs" key is NOT supported - only "safe-outputs.jobs" is valid.
38func (c *Compiler) parseSafeJobsConfig(jobsMap map[string]any) map[string]*SafeJobConfig {
39 if jobsMap == nil {
40 return nil
41 }
42
43 safeJobsLog.Printf("Parsing %d safe-jobs from jobs map", len(jobsMap))
44 result := make(map[string]*SafeJobConfig)
45
46 for jobName, jobValue := range jobsMap {
47 jobConfig, ok := jobValue.(map[string]any)
48 if !ok {
49 continue
50 }
51
52 safeJob := &SafeJobConfig{}
53
54 // Parse name
55 if name, exists := jobConfig["name"]; exists {
56 if nameStr, ok := name.(string); ok {
57 safeJob.Name = nameStr
58 }
59 }
60
61 // Parse description
62 if description, exists := jobConfig["description"]; exists {
63 if descStr, ok := description.(string); ok {
64 safeJob.Description = descStr
65 }
66 }
67
68 // Parse runs-on (also accept "runner" as alias)
69 if runsOn, exists := jobConfig["runs-on"]; exists {
70 safeJob.RunsOn = runsOn
71 } else if runner, exists := jobConfig["runner"]; exists {
72 safeJob.RunsOn = runner
73 }
74
75 // Parse if condition
76 if ifCond, exists := jobConfig["if"]; exists {
77 if ifStr, ok := ifCond.(string); ok {
78 safeJob.If = c.extractExpressionFromIfString(ifStr)
79 }
80 }
81
82 // Parse needs
83 if needs, exists := jobConfig["needs"]; exists {
84 if needsList, ok := needs.([]any); ok {
85 for _, need := range needsList {
86 if needStr, ok := need.(string); ok {
87 safeJob.Needs = append(safeJob.Needs, needStr)
88 }
89 }
90 } else if needStr, ok := needs.(string); ok {
91 safeJob.Needs = append(safeJob.Needs, needStr)
92 }
93 }
94
95 // Parse steps

Calls 3

ParseInputDefinitionsFunction · 0.85
PrintfMethod · 0.45

Tested by 4

TestParseSafeJobsConfigFunction · 0.76
TestSafeJobsInputTypesFunction · 0.76