1
0
Fork 0
scripts/jekyll_webhook.py

47 lines
1.1 KiB
Python
Executable file

#!/usr/bin/env python
from __future__ import print_function
import json
import tempfile
import git
from flask import Flask, request
from pid import PidFile
import sarge
from systemd.journal import JournalHandler
DESTINATION = "/var/www/dennogumi-test/"
REPO = "dennogumi.org"
app = Flask(__name__)
@app.route("/", methods=["POST"])
def push_hook_to_server():
app.logger.info("New data received. Processing...")
data = json.loads(request.data)
repository = data["repository"]
if repository["name"] != REPO:
app.logger.warning("Repository not found.")
return "OK"
repo_url = repository["url"]
temp = tempfile.mkdtemp()
app.logger.info("Cloning repository...")
git.Repo.clone_from(repo_url, temp)
cmd = "/home/einar/bin/jekyll_clone_repo.sh {0} {1}"
cmd = sarge.shell_format(cmd, temp, DESTINATION)
app.logger.info("Deploying Jekyll...")
pid = sarge.run(cmd, async=True)
return "OK"
if __name__ == "__main__":
with PidFile("/run/webhook/jekyll_webhook.pid", chmod=0o600):
handler = JournalHandler()
app.logger.addHandler(handler)
app.run()