Skip to content

Commit

Permalink
Clean up GitHub rule (#1366)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacknagz authored Sep 25, 2024
1 parent d1c81cc commit 337be68
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions rules/github_rules/github_action_failed.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from unittest.mock import MagicMock

from global_filter_github import filter_include_event
from panther_base_helpers import deep_get, github_alert_context
from panther_base_helpers import github_alert_context

# The keys for MONITORED_ACTIONS are gh_org/repo_name
# The values for MONITORED_ACTIONS are a list of ["action_names"]
Expand All @@ -15,22 +15,22 @@ def rule(event):
global MONITORED_ACTIONS # pylint: disable=global-statement
if isinstance(MONITORED_ACTIONS, MagicMock):
MONITORED_ACTIONS = json.loads(MONITORED_ACTIONS()) # pylint: disable=not-callable
repo = deep_get(event, "repo", default="")
action_name = deep_get(event, "name", default="")
repo = event.get("repo", "")
action_name = event.get("name", "")
return all(
[
deep_get(event, "action", default="") == "workflows.completed_workflow_run",
event.get("action", "") == "workflows.completed_workflow_run",
event.get("conclusion", "") == "failure",
repo in MONITORED_ACTIONS,
action_name in MONITORED_ACTIONS.get(repo, []),
deep_get(event, "conclusion", default="") == "failure",
]
)


def title(event):
repo = deep_get(event, "repo", default="<NO_REPO>")
action_name = deep_get(event, "name", default="<NO_ACTION_NAME>")
return f"The GitHub Action [{action_name}] in [{repo}] has failed"
repo = event.get("repo", "<NO_REPO>")
action_name = event.get("name", "<NO_ACTION_NAME>")
return f"GitHub Action [{action_name}] in [{repo}] has failed"


def alert_context(event):
Expand Down

0 comments on commit 337be68

Please sign in to comment.