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

Function validateOnNeedsDependencyChain

pkg/workflow/on_needs_validation.go:169–238  ·  view source on GitHub ↗
(
	root string,
	current string,
	allJobs map[string]any,
	onNeedsSet map[string]struct {
	}, promptReferencedSet map[string]struct {
	}, visiting map[string]struct {
	}, visited map[string]struct {
	})

Source from the content-addressed store, hash-verified

167}
168
169func validateOnNeedsDependencyChain(
170 root string,
171 current string,
172 allJobs map[string]any,
173 onNeedsSet map[string]struct {
174 }, promptReferencedSet map[string]struct {
175 }, visiting map[string]struct {
176 }, visited map[string]struct {
177 }) error {
178 if setutil.Contains(visited, current) {
179 return nil
180 }
181 if setutil.Contains(visiting, current) {
182 return fmt.Errorf("on.needs: cycle detected while validating dependency chain for %q", root)
183 }
184
185 jobConfigAny, exists := allJobs[current]
186 if !exists {
187 return nil
188 }
189
190 jobConfig, ok := jobConfigAny.(map[string]any)
191 if !ok {
192 return nil
193 }
194
195 visiting[current] = struct {
196 }{}
197 defer delete(visiting, current)
198
199 for _, dep := range parseNeedsField(jobConfig["needs"]) {
200 if isReservedOnNeedsTarget(dep) {
201 return fmt.Errorf(
202 "on.needs: job %q depends on built-in job %q. Dependencies for on.needs jobs must be custom jobs that run before activation",
203 current,
204 dep,
205 )
206 }
207
208 depAny, depExists := allJobs[dep]
209 if !depExists {
210 continue
211 }
212
213 depConfig, ok := depAny.(map[string]any)
214 if !ok {
215 continue
216 }
217
218 _, depHasExplicitNeeds := depConfig["needs"]
219 if !depHasExplicitNeeds && !setutil.Contains(onNeedsSet, dep) && !setutil.Contains(promptReferencedSet, dep) {
220 return fmt.Errorf(
221 "on.needs: job %q depends on %q, but %q has no explicit needs and is not in on.needs. It may get an implicit needs: activation and create a cycle. Add %q to on.needs or give %q explicit needs that run before activation",
222 current,
223 dep,
224 dep,
225 dep,
226 dep,

Callers 1

Calls 4

ContainsFunction · 0.92
parseNeedsFieldFunction · 0.85
isReservedOnNeedsTargetFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected