Skip to content

Commit

Permalink
Internal queries: Replace deprecated predicates
Browse files Browse the repository at this point in the history
  • Loading branch information
henrymercer committed Jan 24, 2024
1 parent 65c7496 commit a2619f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
21 changes: 5 additions & 16 deletions queries/required-action-input.ql
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,26 @@ class ActionDeclaration extends File {
getRelativePath().matches("%/action.yml")
}

YAMLDocument getRootNode() {
YamlDocument getRootNode() {
result.getFile() = this
}

/**
* The name of any input to this action.
*/
string getAnInput() {
result = getRootNode().(YAMLMapping).lookup("inputs").(YAMLMapping).getKey(_).(YAMLString).getValue()
result = getRootNode().(YamlMapping).lookup("inputs").(YamlMapping).getKey(_).(YamlString).getValue()
}

/**
* The given input always has a value, either because it is required,
* or because it has a default value.
*/
predicate inputAlwaysHasValue(string input) {
exists(YAMLMapping value |
value = getRootNode().(YAMLMapping).lookup("inputs").(YAMLMapping).lookup(input) and
exists(YamlMapping value |
value = getRootNode().(YamlMapping).lookup("inputs").(YamlMapping).lookup(input) and
(exists(value.lookup("default")) or
value.lookup("required").(YAMLBool).getBoolValue() = true))
}

/**
* The function that is the entrypoint to this action.
*/
FunctionDeclStmt getEntrypoint() {
result.getFile().getRelativePath() = getRootNode().
(YAMLMapping).lookup("runs").
(YAMLMapping).lookup("main").
(YAMLString).getValue().regexpReplaceAll("\\.\\./lib/(.*)\\.js", "src/$1.ts") and
result.getName() = "run"
value.lookup("required").(YamlBool).getBoolValue() = true))
}
}

Expand Down
10 changes: 5 additions & 5 deletions queries/undeclared-action-input.ql
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ class ActionDeclaration extends File {
result = getRelativePath().regexpCapture("(.*)/action.yml", 1)
}

YAMLDocument getRootNode() {
YamlDocument getRootNode() {
result.getFile() = this
}

/**
* The name of any input to this action.
*/
string getAnInput() {
result = getRootNode().(YAMLMapping).lookup("inputs").(YAMLMapping).getKey(_).(YAMLString).getValue()
result = getRootNode().(YamlMapping).lookup("inputs").(YamlMapping).getKey(_).(YamlString).getValue()
}

/**
* The function that is the entrypoint to this action.
*/
FunctionDeclStmt getEntrypoint() {
result.getFile().getRelativePath() = getRootNode().
(YAMLMapping).lookup("runs").
(YAMLMapping).lookup("main").
(YAMLString).getValue().regexpReplaceAll("\\.\\./lib/(.*)\\.js", "src/$1.ts") and
(YamlMapping).lookup("runs").
(YamlMapping).lookup("main").
(YamlString).getValue().regexpReplaceAll("\\.\\./lib/(.*)\\.js", "src/$1.ts") and
result.getName() = "run"
}
}
Expand Down

0 comments on commit a2619f6

Please sign in to comment.