@@ -68,6 +68,16 @@ private newtype TAstNode =
68
68
TStrategyNode ( YamlMapping n ) { exists ( YamlMapping m | m .lookup ( "strategy" ) = n ) } or
69
69
TNeedsNode ( YamlMappingLikeNode n ) { exists ( YamlMapping m | m .lookup ( "needs" ) = n ) } or
70
70
TJobNode ( YamlMapping n ) { exists ( YamlMapping w | w .lookup ( "jobs" ) .( YamlMapping ) .lookup ( _) = n ) } or
71
+ TOnNode ( YamlMappingLikeNode n ) { exists ( YamlMapping w | w .lookup ( "on" ) = n ) } or
72
+ TEventNode ( YamlScalar event , YamlMappingLikeNode n ) {
73
+ exists ( OnImpl o |
74
+ o .getNode ( ) .( YamlMapping ) .maps ( event , n )
75
+ or
76
+ o .getNode ( ) .( YamlSequence ) .getAChildNode ( ) = event and event = n
77
+ or
78
+ o .getNode ( ) .( YamlScalar ) = n and event = n
79
+ )
80
+ } or
71
81
TStepNode ( YamlMapping n ) {
72
82
exists ( YamlMapping m | m .lookup ( "steps" ) .( YamlSequence ) .getElementNode ( _) = n )
73
83
} or
@@ -308,6 +318,9 @@ class WorkflowImpl extends AstNodeImpl, TWorkflowNode {
308
318
309
319
override YamlMapping getNode ( ) { result = n }
310
320
321
+ /** Gets the `on` trigger events for this workflow. */
322
+ OnImpl getOn ( ) { result .getNode ( ) = n .lookup ( "on" ) }
323
+
311
324
/** Gets the 'global' `env` mapping in this workflow. */
312
325
EnvImpl getEnv ( ) { result .getNode ( ) = n .lookup ( "env" ) }
313
326
@@ -323,15 +336,8 @@ class WorkflowImpl extends AstNodeImpl, TWorkflowNode {
323
336
/** Gets the permissions granted to this workflow. */
324
337
PermissionsImpl getPermissions ( ) { result .getNode ( ) = n .lookup ( "permissions" ) }
325
338
326
- /** Workflow is triggered by given trigger event */
327
- predicate hasTriggerEvent ( string trigger ) {
328
- exists ( YamlNode y | y = n .lookup ( "on" ) .( YamlMappingLikeNode ) .getNode ( trigger ) )
329
- }
330
-
331
339
/** Gets the trigger event that starts this workflow. */
332
- string getATriggerEvent ( ) {
333
- exists ( YamlNode y | y = n .lookup ( "on" ) .( YamlMappingLikeNode ) .getNode ( result ) )
334
- }
340
+ EventImpl getATriggerEvent ( ) { this .getOn ( ) .getAnEvent ( ) = result }
335
341
336
342
/** Gets the strategy for this workflow. */
337
343
StrategyImpl getStrategy ( ) { result .getNode ( ) = n .lookup ( "strategy" ) }
@@ -573,6 +579,66 @@ class NeedsImpl extends AstNodeImpl, TNeedsNode {
573
579
}
574
580
}
575
581
582
+ class OnImpl extends AstNodeImpl , TOnNode {
583
+ YamlMappingLikeNode n ;
584
+
585
+ OnImpl ( ) { this = TOnNode ( n ) }
586
+
587
+ override string toString ( ) { result = n .toString ( ) }
588
+
589
+ override AstNodeImpl getAChildNode ( ) { result .getNode ( ) = n .getAChildNode * ( ) }
590
+
591
+ override WorkflowImpl getParentNode ( ) { result .getAChildNode ( ) = this }
592
+
593
+ override string getAPrimaryQlClass ( ) { result = "OnImpl" }
594
+
595
+ override Location getLocation ( ) { result = n .getLocation ( ) }
596
+
597
+ override YamlMappingLikeNode getNode ( ) { result = n }
598
+
599
+ /** Gets an event that triggers the workflow. */
600
+ EventImpl getAnEvent ( ) { result .getParentNode ( ) = this }
601
+ }
602
+
603
+ class EventImpl extends AstNodeImpl , TEventNode {
604
+ YamlScalar e ;
605
+ YamlMappingLikeNode n ;
606
+
607
+ EventImpl ( ) { this = TEventNode ( e , n ) }
608
+
609
+ override string toString ( ) { result = e .getValue ( ) }
610
+
611
+ override AstNodeImpl getAChildNode ( ) { result .getNode ( ) = n .getAChildNode * ( ) }
612
+
613
+ override OnImpl getParentNode ( ) { result .getAChildNode ( ) = this }
614
+
615
+ override string getAPrimaryQlClass ( ) { result = "EventImpl" }
616
+
617
+ override Location getLocation ( ) { result = e .getLocation ( ) }
618
+
619
+ override YamlScalar getNode ( ) { result = e }
620
+
621
+ /** Gets the name of the event that triggers the workflow. */
622
+ string getName ( ) { result = e .getValue ( ) }
623
+
624
+ /** Gets the Yaml Node associated with the event if any */
625
+ YamlMappingLikeNode getValueNode ( ) { result = n }
626
+
627
+ /** Gets an activity type */
628
+ string getAnActivityType ( ) {
629
+ result =
630
+ n .( YamlMapping ) .lookup ( "types" ) .( YamlMappingLikeNode ) .getNode ( _) .( YamlScalar ) .getValue ( )
631
+ }
632
+
633
+ /** Gets a string value for any property (eg: branches, branches-ignore, etc.) */
634
+ string getAPropertyValue ( string prop ) {
635
+ result = n .( YamlMapping ) .lookup ( prop ) .( YamlMappingLikeNode ) .getNode ( _) .( YamlScalar ) .getValue ( )
636
+ }
637
+
638
+ /** Holds if the event has a property with the given name */
639
+ predicate hasProperty ( string prop ) { exists ( this .getAPropertyValue ( prop ) ) }
640
+ }
641
+
576
642
class JobImpl extends AstNodeImpl , TJobNode {
577
643
YamlMapping n ;
578
644
string jobId ;
@@ -686,7 +752,7 @@ class JobImpl extends AstNodeImpl, TJobNode {
686
752
// For workflows that are triggered by the pull_request_target event, the GITHUB_TOKEN is granted read/write repository permission unless the permissions key is specified and the workflow can access secrets, even when it is triggered from a fork.
687
753
// The Job is triggered by an event other than `pull_request`
688
754
count ( this .getATriggerEvent ( ) ) = 1 and
689
- not this .getATriggerEvent ( ) = [ "pull_request" , "workflow_call" ]
755
+ not this .getATriggerEvent ( ) . getName ( ) = [ "pull_request" , "workflow_call" ]
690
756
or
691
757
// The Workflow is only triggered by `workflow_call` and there is
692
758
// a caller workflow triggered by an event other than `pull_request`
@@ -701,16 +767,11 @@ class JobImpl extends AstNodeImpl, TJobNode {
701
767
count ( this .getATriggerEvent ( ) ) > 1
702
768
}
703
769
704
- /** Workflow is triggered by given trigger event */
705
- predicate hasTriggerEvent ( string trigger ) {
706
- exists ( YamlNode y | y = n .lookup ( "on" ) .( YamlMappingLikeNode ) .getNode ( trigger ) )
707
- }
708
-
709
770
/** Gets the trigger event that starts this workflow. */
710
- string getATriggerEvent ( ) { result = this .getEnclosingWorkflow ( ) .getATriggerEvent ( ) }
771
+ EventImpl getATriggerEvent ( ) { result = this .getEnclosingWorkflow ( ) .getATriggerEvent ( ) }
711
772
712
773
private predicate hasSingleTrigger ( string trigger ) {
713
- this .getATriggerEvent ( ) = trigger and
774
+ this .getATriggerEvent ( ) . getName ( ) = trigger and
714
775
count ( this .getATriggerEvent ( ) ) = 1
715
776
}
716
777
0 commit comments