From 622eda5a998c2014501430a2f937f528b541650a Mon Sep 17 00:00:00 2001 From: jesopo Date: Mon, 24 Jun 2019 18:32:20 +0100 Subject: [PATCH] Don't show webhook notifications for private repos --- modules/git_webhooks/__init__.py | 3 +++ modules/git_webhooks/gitea.py | 5 +++++ modules/git_webhooks/github.py | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/modules/git_webhooks/__init__.py b/modules/git_webhooks/__init__.py index 6ca058ff..81b34979 100644 --- a/modules/git_webhooks/__init__.py +++ b/modules/git_webhooks/__init__.py @@ -42,6 +42,9 @@ class Module(ModuleManager.BaseModule): "payload"][0]) data = json.loads(payload) + if handler.is_private(data, headers): + return {"state": "success", "deliveries": 0} + full_name, repo_username, repo_name, organisation = handler.names( data, headers) branch = handler.branch(data, headers) diff --git a/modules/git_webhooks/gitea.py b/modules/git_webhooks/gitea.py index 78c356ea..536925ac 100644 --- a/modules/git_webhooks/gitea.py +++ b/modules/git_webhooks/gitea.py @@ -44,6 +44,11 @@ COMMENT_ACTIONS = { } class Gitea(object): + def is_private(self, data, headers): + if "repository" in data: + return data["repository"]["private"] + return False + def names(self, data, headers): full_name = None repo_username = None diff --git a/modules/git_webhooks/github.py b/modules/git_webhooks/github.py index 7154c44c..1df948e4 100644 --- a/modules/git_webhooks/github.py +++ b/modules/git_webhooks/github.py @@ -80,6 +80,11 @@ CHECK_RUN_CONCLUSION = { CHECK_RUN_FAILURES = ["failure", "cancelled", "timed_out", "action_required"] class GitHub(object): + def is_private(self, data, headers): + if "repository" in data: + return data["repository"]["private"] + return False + def names(self, data, headers): full_name = None repo_username = None