@@ -144,6 +144,15 @@ module Actions {
144
144
Step getStep ( ) { result = step }
145
145
}
146
146
147
+ /**
148
+ * Gets a regular expression that parses an `owner/repo@version` reference within a `uses` field in an Actions job step.
149
+ * The capture groups are:
150
+ * 1: The owner of the repository where the Action comes from, e.g. `actions` in `actions/checkout@v2`
151
+ * 2: The name of the repository where the Action comes from, e.g. `checkout` in `actions/checkout@v2`.
152
+ * 3: The version reference used when checking out the Action, e.g. `v2` in `actions/checkout@v2`.
153
+ */
154
+ private string usesParser ( ) { result = "([^/]+)/([^/@]+)@(.+)" }
155
+
147
156
/**
148
157
* A `uses` field within an Actions job step, which references an action as a reusable unit of code.
149
158
* See https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepsuses.
@@ -157,31 +166,21 @@ module Actions {
157
166
*/
158
167
class Uses extends YAMLNode , YAMLScalar {
159
168
Step step ;
160
- /** The owner of the repository where the Action comes from, e.g. `actions` in `actions/checkout@v2`. */
161
- string repositoryOwner ;
162
- /** The name of the repository where the Action comes from, e.g. `checkout` in `actions/checkout@v2`. */
163
- string repositoryName ;
164
- /** The version reference used when checking out the Action, e.g. `v2` in `actions/checkout@v2`. */
165
- string version ;
166
-
167
- Uses ( ) {
168
- step .lookup ( "uses" ) = this and
169
- // Simple regular expression to split up an Action reference `owner/repo@version` into its components.
170
- exists ( string regexp | regexp = "([^/]+)/([^/@]+)@(.+)" |
171
- repositoryOwner = this .getValue ( ) .regexpCapture ( regexp , 1 ) and
172
- repositoryName = this .getValue ( ) .regexpCapture ( regexp , 2 ) and
173
- version = this .getValue ( ) .regexpCapture ( regexp , 3 )
174
- )
175
- }
169
+
170
+ Uses ( ) { step .lookup ( "uses" ) = this }
176
171
177
172
/** Gets the step this field belongs to. */
178
173
Step getStep ( ) { result = step }
179
174
180
175
/** Gets the owner and name of the repository where the Action comes from, e.g. `actions/checkout` in `actions/checkout@v2`. */
181
- string getGitHubRepository ( ) { result = repositoryOwner + "/" + repositoryName }
176
+ string getGitHubRepository ( ) {
177
+ result =
178
+ this .getValue ( ) .regexpCapture ( usesParser ( ) , 1 ) + "/" +
179
+ this .getValue ( ) .regexpCapture ( usesParser ( ) , 2 )
180
+ }
182
181
183
182
/** Gets the version reference used when checking out the Action, e.g. `v2` in `actions/checkout@v2`. */
184
- string getVersion ( ) { result = version }
183
+ string getVersion ( ) { result = this . getValue ( ) . regexpCapture ( usesParser ( ) , 3 ) }
185
184
}
186
185
187
186
/**
0 commit comments