Skip to content

Commit 090d22f

Browse files
author
Alvaro Muñoz
committed
Add GetRepoRoot helper function
1 parent abd49d5 commit 090d22f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

ql/lib/codeql/actions/Helper.qll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,20 @@ string defaultBranchNames() {
298298
not exists(string default_branch_name | repositoryDataModel(_, default_branch_name)) and
299299
result = ["main", "master"]
300300
}
301+
302+
string getRepoRoot() {
303+
exists(Workflow w |
304+
w.getLocation().getFile().getRelativePath().indexOf("/.github/workflows") > 0 and
305+
result =
306+
w.getLocation()
307+
.getFile()
308+
.getRelativePath()
309+
.prefix(w.getLocation().getFile().getRelativePath().indexOf("/.github/workflows") + 1) and
310+
// exclude workflow_enum reusable workflows directory root
311+
not result.indexOf(".github/reusable_workflows/") > -1
312+
or
313+
not w.getLocation().getFile().getRelativePath().indexOf("/.github/workflows") > 0 and
314+
not w.getLocation().getFile().getRelativePath().indexOf(".github/reusable_workflows") > -1 and
315+
result = ""
316+
)
317+
}

0 commit comments

Comments
 (0)