Skip to content

Commit

Permalink
ChatOps: Avoid failing the whole action chain when result output is d…
Browse files Browse the repository at this point in the history
…isabled
  • Loading branch information
emedvedev committed Nov 26, 2015
1 parent 9c26f2e commit 2fe0d85
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
7 changes: 3 additions & 4 deletions contrib/chatops/actions/format_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ def run(self, execution):

result = getattr(alias, 'result', None)
if result:
enabled = result.get('enabled', True)

if enabled and 'format' in alias.result:
if not result.get('enabled', True):
raise Exception("Output of this template is disabled.")
if 'format' in alias.result:
template = alias.result['format']

return self.jinja.from_string(template).render(context)
13 changes: 13 additions & 0 deletions contrib/chatops/actions/skip_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from st2actions.runners.pythonrunner import Action

__all__ = [
'SkipMessageAction'
]


class SkipMessageAction(Action):
def run(self):
# That's a placeholder for format_result failure
# to avoid failing action chain on aliases with
# disabled output.
return
7 changes: 7 additions & 0 deletions contrib/chatops/actions/skip_message.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: "skip_message"
pack: chatops
runner_type: "run-python"
description: "Skip sending an execution result for chatops"
enabled: true
entry_point: "skip_message.py"
4 changes: 4 additions & 0 deletions contrib/chatops/actions/workflows/post_result.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ chain:
publish:
message: "{{format_result.result}}"
on-success: "post_message"
on-failure: "skip_message"
-
name: "post_message"
ref: "chatops.post_message"
Expand All @@ -25,3 +26,6 @@ chain:
channel: "{{channel}}"
whisper: "{{whisper}}"
message: "{{message}}"
-
name: "skip_message"
ref: "chatops.skip_message"

0 comments on commit 2fe0d85

Please sign in to comment.