@@ -20,7 +20,10 @@ class AstNode instanceof YamlNode {
20
20
* A statement is a group of expressions and/or statements that you design to carry out a task or an action.
21
21
* Any statement that can return a value is automatically qualified to be used as an expression.
22
22
*/
23
- class Statement extends AstNode { }
23
+ class Statement extends AstNode {
24
+ /** Gets the workflow that this job is a part of. */
25
+ WorkflowStmt getEnclosingWorkflowStmt ( ) { exists ( WorkflowStmt w | w .getAChildNode * ( ) = result ) }
26
+ }
24
27
25
28
/**
26
29
* An expression is any word or group of words or symbols that is a value. In programming, an expression is a value, or anything that executes and ends up being a value.
@@ -53,6 +56,14 @@ class WorkflowStmt extends Statement instanceof Actions::Workflow {
53
56
JobStmt getAJobStmt ( ) { result = super .getJob ( _) }
54
57
55
58
JobStmt getJobStmt ( string id ) { result = super .getJob ( id ) }
59
+
60
+ predicate hasTriggerEvent ( string trigger ) {
61
+ exists ( YamlNode n | n = super .getOn ( ) .( YamlMappingLikeNode ) .getNode ( trigger ) )
62
+ }
63
+
64
+ string getATriggerEvent ( ) {
65
+ exists ( YamlNode n | n = super .getOn ( ) .( YamlMappingLikeNode ) .getNode ( result ) )
66
+ }
56
67
}
57
68
58
69
class ReusableWorkflowStmt extends WorkflowStmt {
@@ -122,9 +133,6 @@ class JobStmt extends Statement instanceof Actions::Job {
122
133
*/
123
134
string getId ( ) { result = super .getId ( ) }
124
135
125
- /** Gets the workflow that this job is a part of. */
126
- WorkflowStmt getWorkflowStmt ( ) { result = super .getWorkflow ( ) }
127
-
128
136
/** Gets the step at the given index within this job. */
129
137
StepStmt getStepStmt ( int index ) { result = super .getStep ( index ) }
130
138
@@ -222,7 +230,7 @@ class StepUsesExpr extends StepStmt, UsesExpr {
222
230
)
223
231
or
224
232
exists ( Actions:: WorkflowEnv env |
225
- env .getWorkflow ( ) = this .getJobStmt ( ) .getWorkflowStmt ( ) and
233
+ env .getWorkflow ( ) = this .getJobStmt ( ) .getEnclosingWorkflowStmt ( ) and
226
234
env .( YamlMapping ) .maps ( any ( YamlScalar s | s .getValue ( ) = name ) , result )
227
235
)
228
236
}
@@ -287,7 +295,7 @@ class JobUsesExpr extends UsesExpr instanceof YamlMapping {
287
295
)
288
296
or
289
297
exists ( Actions:: WorkflowEnv env |
290
- env .getWorkflow ( ) = this .getJobStmt ( ) .getWorkflowStmt ( ) and
298
+ env .getWorkflow ( ) = this .getJobStmt ( ) .getEnclosingWorkflowStmt ( ) and
291
299
env .( YamlMapping ) .maps ( any ( YamlScalar s | s .getValue ( ) = name ) , result )
292
300
)
293
301
}
@@ -320,7 +328,7 @@ class RunExpr extends StepStmt, Expression {
320
328
)
321
329
or
322
330
exists ( Actions:: WorkflowEnv env |
323
- env .getWorkflow ( ) = this .getJobStmt ( ) .getWorkflowStmt ( ) and
331
+ env .getWorkflow ( ) = this .getJobStmt ( ) .getEnclosingWorkflowStmt ( ) and
324
332
env .( YamlMapping ) .maps ( any ( YamlScalar s | s .getValue ( ) = name ) , result )
325
333
)
326
334
}
0 commit comments