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

Commit

Permalink
Add: allow filtering for which branch push notifications work (#9)
Browse files Browse the repository at this point in the history
Pyup for example creates a branch in the repository.
Pushes to these branches don't have to be announced.
  • Loading branch information
TrueBrain committed Oct 6, 2018
1 parent 029ca44 commit 7d589bd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dorpsgek_github/modules/watcher/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ async def _notify(github_api, ref, *,
raw_yml = await get_dorpsgek_yml(github_api, repository_name, ref)
if raw_yml:
yml = yaml.load(raw_yml)
services = yml["notifications"].get("issue", {})

services = yml["notifications"].get("issue", {})
for protocol, userdata in services.items():
payload["userdata"] = userdata
await watcher.send_to_watchers(protocol, "notify.issue", payload)
Expand Down
2 changes: 1 addition & 1 deletion dorpsgek_github/modules/watcher/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ async def _notify(github_api, ref, *,
raw_yml = await get_dorpsgek_yml(github_api, repository_name, ref)
if raw_yml:
yml = yaml.load(raw_yml)
services = yml["notifications"].get("pull-request", {})

services = yml["notifications"].get("pull-request", {})
for protocol, userdata in services.items():
payload["userdata"] = userdata
await watcher.send_to_watchers(protocol, "notify.pull_request", payload)
Expand Down
22 changes: 21 additions & 1 deletion dorpsgek_github/modules/watcher/push.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import yaml

from dorpsgek_github import config
Expand Down Expand Up @@ -46,9 +47,28 @@ async def push(event, github_api):
raw_yml = await get_dorpsgek_yml(github_api, repository_name, ref)
if raw_yml:
yml = yaml.load(raw_yml)
services = yml["notifications"].get("push", {})

# Check if there was a filter in place for branches
filter_only = yml["notifications"].get("push", {}).get("only", [])
for filter in filter_only:
if re.match(filter, branch):
break
else:
# No match found, so we didn't match the 'only'; ignore this notification
return

filter_except = yml["notifications"].get("push", {}).get("except", [])
for filter in filter_except:
if re.match(filter, branch):
# We match the except; ignore this notification
return

services = yml["notifications"].get("push", {})
for protocol, userdata in services.items():
# "only" and "except" are not protocols, but filters; ignore them
if protocol in ["only", "except"]:
continue

payload["userdata"] = userdata
await watcher.send_to_watchers(protocol, "notify.push", payload)

Expand Down

0 comments on commit 7d589bd

Please sign in to comment.