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

Function parsePullRequestTrigger

pkg/workflow/trigger_parser.go:232–306  ·  view source on GitHub ↗

parsePullRequestTrigger parses pull request triggers

(tokens []string)

Source from the content-addressed store, hash-verified

230
231// parsePullRequestTrigger parses pull request triggers
232func parsePullRequestTrigger(tokens []string) (*TriggerIR, error) {
233 if len(tokens) == 1 {
234 // Simple "pull_request" trigger - leave as simple string
235 // GitHub Actions supports: on: pull_request
236 return nil, nil
237 }
238
239 // Check for activity type: "pull_request opened", "pull_request merged", etc.
240 activityType := tokens[1]
241
242 // Map common activity types
243 validTypes := map[string]struct {
244 }{
245 "opened": {},
246 "edited": {},
247 "closed": {},
248 "reopened": {},
249 "synchronize": {},
250 "assigned": {},
251 "unassigned": {},
252 "labeled": {},
253 "unlabeled": {},
254 "review_requested": {},
255 }
256
257 // Special case: "merged" is not a real type, it's a condition on "closed"
258 if activityType == "merged" {
259 triggerParserLog.Print("Parsed pull_request merged trigger (maps to closed with merge condition)")
260 return &TriggerIR{
261 Event: "pull_request",
262 Types: []string{"closed"},
263 Conditions: []string{"github.event.pull_request.merged == true"},
264 AdditionalEvents: map[string]any{
265 "workflow_dispatch": nil,
266 },
267 }, nil
268 }
269
270 if setutil.Contains(validTypes, activityType) {
271 ir := &TriggerIR{
272 Event: "pull_request",
273 Types: []string{activityType},
274 AdditionalEvents: map[string]any{
275 "workflow_dispatch": nil,
276 },
277 }
278
279 // Check for path filter: "pull_request opened affecting <path>"
280 if len(tokens) >= 4 && tokens[2] == "affecting" {
281 path := strings.Join(tokens[3:], " ")
282 ir.Filters = map[string]any{
283 "paths": []string{path},
284 }
285 }
286
287 return ir, nil
288 }
289

Callers 1

Calls 3

ContainsFunction · 0.92
PrintMethod · 0.80
ErrorfMethod · 0.45

Tested by

no test coverage detected