store incoming hooks

This commit is contained in:
simon 2022-05-20 20:08:12 +07:00
parent f38d8a3594
commit 5b75a80ee1
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
3 changed files with 19 additions and 1 deletions

View File

@ -1,7 +1,9 @@
"""parse and forward docker webhooks"""
import requests
import json
from datetime import datetime
import requests
from src.webhook_base import WebhookBase
@ -117,3 +119,10 @@ class DockerHook(WebhookBase):
response = self._forward_message(message_data, url)
return response
def save_hook(self):
"""save hook to disk for easy debugging"""
now = datetime.now().strftime("%s")
filename = f"/data/hooks/docker_hook-{now}.json"
with open(filename, "w", encoding="utf-8") as f:
f.write(json.dumps(self.hook))

View File

@ -103,6 +103,13 @@ class GithubHook(WebhookBase):
task.create_task("build_release")
GithubBackup(tag_name).save_tag()
def save_hook(self):
"""save hook to disk for easy debugging"""
now = datetime.now().strftime("%s")
filename = f"/data/hooks/github_hook-{now}.json"
with open(filename, "w", encoding="utf-8") as f:
f.write(json.dumps(self.hook))
class GithubBackup:
"""backup release and notes"""

View File

@ -37,6 +37,7 @@ def webhook_docker():
print(request.json)
message = handler.process()
handler.save_hook()
print(message, "hook sent to discord")
return jsonify(message)
@ -53,5 +54,6 @@ def webhook_github():
print(request.json)
handler.create_hook_task()
handler.save_hook()
message = {"success": True}
return jsonify(message)