-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{%- set git = ctx.deployment['meta-info'].git or {} %} | ||
{ | ||
"username": "Deployer ({{ctx.cluster}}-{{ctx.operation}})", | ||
"channel": "{{ notification.channel or '#totem' }}", | ||
"text": | ||
{% if git.type == 'github' %} | ||
"<https://github.com/{{git.owner}}|{{git.owner or 'NA'}}> / <https://github.com/{{git.owner}}/{{git.repo}}|{{git.repo or 'NA'}}> / <https://github.com/{{git.owner}}/{{git.repo}}/{{git.ref}}|{{git.ref or 'NA'}}> / <https://github.com/{{ctx.owner}}/{{ctx.repo}}/commits/{{ctx.commit or ctx.ref}}|{{ctx.commit or ctx.ref or 'NA'}}>" | ||
{% else %} | ||
"{{git.owner or 'NA'}} / {{git.repo or 'NA'}} / {{git.ref or 'NA'}} / {{git.commit or 'NA'}}" | ||
{% endif %}, | ||
|
||
"attachments": [ | ||
{ | ||
"text": "{{ notification.code}}: {{ notification.message | truncate(1000) }}", | ||
"color": | ||
{% if level == 1 %} | ||
"danger" | ||
{% elif level == 2 %} | ||
"warning" | ||
{% elif level == 3 %} | ||
"good" | ||
{% else %} | ||
"#439FE0" | ||
{% endif %} | ||
} | ||
] | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import json | ||
|
||
from nose.tools import eq_, ok_ | ||
|
||
from deployer import templatefactory | ||
|
||
""" | ||
Tests for Slack Jinja templates | ||
""" | ||
|
||
|
||
def test_slack_template(): | ||
""" | ||
should render json output for slack API. | ||
""" | ||
|
||
output = templatefactory.render_template( | ||
'slack.json.jinja', | ||
ctx={ | ||
"deployment": { | ||
"meta-info": { | ||
"git": { | ||
"owner": "test-owner", | ||
"repo": "test-repo", | ||
"ref": "test-ref", | ||
"type": "github", | ||
} | ||
} | ||
}, | ||
"cluster": "local", | ||
"operation": "test", | ||
|
||
}, | ||
notification={ | ||
"message": "test message", | ||
"code": "DEPLOYMENT_FAILED" | ||
}, level=1) | ||
slack_dict = json.loads(output) | ||
|
||
eq_(slack_dict.get("username"), "Deployer (local-test)") | ||
eq_(slack_dict.get("channel"), "#totem") | ||
ok_(slack_dict.get("text")) | ||
ok_(slack_dict.get("attachments")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters