Skip to content

Commit

Permalink
Merge pull request #2098 from github/henrymercer/update-internal-queries
Browse files Browse the repository at this point in the history
Internal queries: Replace deprecated predicates
  • Loading branch information
henrymercer authored Jan 24, 2024
2 parents 65c7496 + a2619f6 commit bd67d8d
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 bd67d8d

Please sign in to comment.