Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Commit

Permalink
Merge pull request #3 from vain/master
Browse files Browse the repository at this point in the history
notify_hipchat: Add optional notifications about applied items
  • Loading branch information
vain committed Jul 15, 2014
2 parents 2d4495e + bf57857 commit d9de00a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
4 changes: 2 additions & 2 deletions index.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"version": 3
},
"notify_hipchat": {
"checksum": "79bf0c59a13212ab4124af96438378e96b0a5eaa",
"checksum": "b06d64cac1f967ba0ce8e1b27626d7bc44925c75",
"desc": "Automatically send notifications to HipChat rooms with bw apply",
"version": 2
"version": 3
}
}
1 change: 1 addition & 0 deletions notify_hipchat/AUTHORS
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Torsten Rehn <[email protected]>
Peter Hofmann <[email protected]>
37 changes: 37 additions & 0 deletions notify_hipchat/hooks/notify_hipchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def _create_config(path):
config.set("connection", "server", "api.hipchat.com")
config.set("connection", "rooms", "name_or_id_of_room1,name_or_id_of_room2")
config.set("connection", "token", "<insert token from https://www.hipchat.com/account/api>")
config.add_section("notifications")
config.set("notifications", "show_item_results", "no")
with open(path, 'wb') as f:
config.write(f)

Expand Down Expand Up @@ -105,3 +107,38 @@ def apply_end(repo, target, nodes, duration=None, **kwargs):
config.get("connection", "token"),
"Finished bw apply on <b>{target}</b>.".format(target=target),
)


def item_apply_end(
repo, node, item, duration=None, status_before=None, status_after=None, **kwargs
):
config = _get_config(repo.path)
if config is None or \
not config.has_section("notifications") or \
not config.getboolean("notifications", "show_item_results"):
return

if status_before.correct:
return
elif status_after is None:
status_string = "<b>skipped</b>"
elif status_after.correct:
status_string = "fixed"
else:
status_string = "<b>failed</b>"

for room in config.get("connection", "rooms").split(","):
LOG.debug("posting item apply end notification to HipChat room {room}@{server}".format(
room=room,
server=config.get("connection", "server"),
))
_notify(
config.get("connection", "server"),
room.strip(),
config.get("connection", "token"),
"<b>{node}</b>: {item}: {status_string}".format(
item=item,
node=node.name,
status_string=status_string
),
)
2 changes: 1 addition & 1 deletion notify_hipchat/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"provides": [
"hooks/notify_hipchat.py"
],
"version": 2
"version": 3
}

0 comments on commit d9de00a

Please sign in to comment.