Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge changes from main to release #1372

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading