mirror of
https://github.com/EeeeKa/webhook-catcher.git
synced 2025-08-04 00:17:22 +05:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
d5a6fe1594 | |||
b5bfe5af7b | |||
0e40f2e916 | |||
76e62815c5 | |||
a4ff475abd | |||
d036bf1bd0 |
12
systemd/webhook-catcher.service
Normal file
12
systemd/webhook-catcher.service
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Webhook catcher
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=whcd
|
||||||
|
Group=whcd
|
||||||
|
|
||||||
|
ExecStart=/usr/sbin/webhook-catcher -c /etc/webhook-catcher/config.json
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
#
|
#
|
||||||
# Webhook-catcher v1.0
|
# Webhook-catcher v1.3
|
||||||
#
|
#
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@ -32,7 +32,7 @@ from signal import signal, SIGHUP, SIGTERM
|
|||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
PROG_NAME = "Webhook-catcher"
|
PROG_NAME = "Webhook-catcher"
|
||||||
PROG_VERSION = "v1.0"
|
PROG_VERSION = "v1.3"
|
||||||
PROG_DESCRIPTION = '\
|
PROG_DESCRIPTION = '\
|
||||||
Simple HTTP-server for processing webhooks from Github or Gogs portals.\n\
|
Simple HTTP-server for processing webhooks from Github or Gogs portals.\n\
|
||||||
\n\
|
\n\
|
||||||
@ -136,6 +136,8 @@ class WebHookHandler(BaseHTTPRequestHandler):
|
|||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(json.dumps(self.json_response, indent=2, sort_keys=True).encode('UTF-8', 'replace'))
|
self.wfile.write(json.dumps(self.json_response, indent=2, sort_keys=True).encode('UTF-8', 'replace'))
|
||||||
|
|
||||||
|
def log_message(self, format, *args):
|
||||||
|
pm("%s - - [%s] %s \n" % (self.address_string(), self.log_date_time_string(), format%args))
|
||||||
|
|
||||||
def do_POST(self):
|
def do_POST(self):
|
||||||
# GET SIGNATURE
|
# GET SIGNATURE
|
||||||
@ -371,9 +373,18 @@ class WebHookWorker(object):
|
|||||||
def git_pull(cls, repo):
|
def git_pull(cls, repo):
|
||||||
if os.path.isdir(repo['dir']):
|
if os.path.isdir(repo['dir']):
|
||||||
result = subprocess.run([
|
result = subprocess.run([
|
||||||
"git", "--git-dir", os.path.join(repo['dir'], '.git'), "pull",
|
"git", "--git-dir", os.path.join(repo['dir'], '.git'), "--work-tree", repo['dir'], "pull",
|
||||||
repo['remote'], repo['branch'],
|
repo['remote'], repo['branch']
|
||||||
], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
||||||
|
if result.returncode == 0:
|
||||||
|
sub_result = subprocess.run([
|
||||||
|
"git", "--git-dir", os.path.join(repo['dir'], '.git'), "--work-tree", repo['dir'], "checkout",
|
||||||
|
repo['branch']
|
||||||
|
], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
||||||
|
|
||||||
|
result.stdout += sub_result.stdout
|
||||||
|
result.stderr += sub_result.stderr
|
||||||
|
result.returncode = sub_result.returncode
|
||||||
else:
|
else:
|
||||||
result = subprocess.run([
|
result = subprocess.run([
|
||||||
"git", "clone", "--origin", repo['remote'], "--branch", repo['branch'], repo['url'], repo['dir']
|
"git", "clone", "--origin", repo['remote'], "--branch", repo['branch'], repo['url'], repo['dir']
|
||||||
@ -422,10 +433,12 @@ class MessagePrinter:
|
|||||||
def pm(self, message):
|
def pm(self, message):
|
||||||
if not self.quiet:
|
if not self.quiet:
|
||||||
print(message)
|
print(message)
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
def pdm(self, debug_message):
|
def pdm(self, debug_message):
|
||||||
if self.debug:
|
if self.debug:
|
||||||
pprint(debug_message)
|
pprint(debug_message)
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
def load_config(path):
|
def load_config(path):
|
||||||
if path != '':
|
if path != '':
|
||||||
|
Loading…
Reference in New Issue
Block a user