Skip to content

Commit

Permalink
Add warning status to mattermost-notify action
Browse files Browse the repository at this point in the history
  • Loading branch information
ozgen committed Nov 12, 2024
1 parent e9dd003 commit d6eff54
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mattermost_notify/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def fill_template(
commit_message = head_commit.get("message", "").split("\n", 1)[0]

highlight_str = ""
if highlight and workflow_status is not Status.SUCCESS:
if highlight and workflow_status not in (Status.SUCCESS, Status.WARNING):
highlight_str = "".join([f"@{h}\n" for h in highlight])

return template.format(
Expand Down
2 changes: 1 addition & 1 deletion mattermost_notify/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def parse_args(args=None) -> Namespace:
"-S",
"--status",
type=str,
choices=["success", "failure"],
choices=["success", "failure", "warning"],
default=Status.SUCCESS.name,
help="Status of Job",
)
Expand Down
1 change: 1 addition & 0 deletions mattermost_notify/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Status(Enum):
FAILURE = ":x: failure"
UNKNOWN = ":grey_question: unknown"
CANCELLED = ":no_entry_sign: canceled"
WARNING = ":warning: warning"

def __str__(self):
return self.name
15 changes: 15 additions & 0 deletions tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ def test_success_no_highlight(self):
| Repository (branch) | ([](/tree/)) |
| Related commit | [](/commit/) |
"""
self.assertEqual(expected, actual)

def test_warning_no_highlight(self):
actual = fill_template(
highlight=["user1", "user2"],
status=Status.WARNING.name,
)
expected = """#### Status: :warning: warning
| Workflow | |
| --- | --- |
| Repository (branch) | ([](/tree/)) |
| Related commit | [](/commit/) |
"""
self.assertEqual(expected, actual)

Expand Down
11 changes: 11 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ def test_parse_status(self):
)
self.assertEqual(parsed_args.status, "failure")

def test_parse_warning_status(self):
parsed_args = parse_args(
[
"www.url.de",
"channel",
"-S",
"warning",
]
)
self.assertEqual(parsed_args.status, "warning")

def test_parse_short(self):
parsed_args = parse_args(
[
Expand Down

0 comments on commit d6eff54

Please sign in to comment.