Skip to content

Commit

Permalink
Give up on non-github context identifiers and handle comparisons better.
Browse files Browse the repository at this point in the history
  • Loading branch information
AdnaneKhan committed May 16, 2024
1 parent 99983d7 commit 4ed67c4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
9 changes: 6 additions & 3 deletions gato/workflow_parser/components/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,16 @@ def evaluateIf(self):
else:
self.if_condition = f"RESTRICTED: {self.if_condition}"

except ValueError as ve:
self.if_condition = self.if_condition
except NotImplementedError as ni:
self.if_condition = self.if_condition
except SyntaxError as e:
self.if_condition = f"EVALUATED: {self.if_condition}"
self.if_condition = self.if_condition
finally:
self.evaluated = True


return self.if_condition


def gated(self):
"""Check if the workflow is gated.
Expand Down
11 changes: 8 additions & 3 deletions gato/workflow_parser/components/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def __process_action(self, uses: str):
# Local actions are runnable, so it is a sink.
self.is_sink = True

def evaluateIf(self, repo=None):
def evaluateIf(self):
"""Evaluate the If expression by parsing it into an AST
and then evaluating it in the context of an external user
triggering it.
Expand All @@ -164,9 +164,14 @@ def evaluateIf(self, repo=None):
self.if_condition = f"EVALUATED: {self.if_condition}"
else:
self.if_condition = f"RESTRICTED: {self.if_condition}"

except ValueError as ve:
# TODO: Remove after alpha.
print(ve)
self.if_condition = self.if_condition
except NotImplementedError as ni:
self.if_condition = self.if_condition
except SyntaxError as e:
self.if_condition = f"EVALUATED: {self.if_condition}"
self.if_condition = self.if_condition
finally:
self.evaluated = True

Expand Down
13 changes: 11 additions & 2 deletions gato/workflow_parser/expression_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class FlexibleAction:
def __init__(self, options):
self.options = options

def __contains__(self, other):
return other in self.options

def __eq__(self, other):
if other.startswith("'") and other.endswith("'"):
other = other[1:-1]
Expand Down Expand Up @@ -87,8 +90,10 @@ def evaluate(self, node):
if node.type == "identifier":
if node.value in ['github.repository_owner', 'github.event.pull_request.base.repo.owner.login']:
return Wildcard(node.value)
elif not node.value.startswith('github.'):
return True
# Right now, it is not worth supporting non github contexts. Anything that comes out of a step, etc.
# is really hard to solve without running the step. The vasty majority of if checks are context + string only.
elif not node.value.startswith('github.'):
raise NotImplementedError()
return self.variables.get(node.value, node.value)
elif node.type == "string":
return node.value
Expand Down Expand Up @@ -135,6 +140,10 @@ def evaluate(self, node):
return json.loads(json_string)
else:
return json_string
elif node.value in ["toJSON", "toJson"]:
json_string = self.evaluate(node.children[0])

return json_string
elif node.value == "success":
return True
elif node.value == "always":
Expand Down

0 comments on commit 4ed67c4

Please sign in to comment.