From 249307a8498a5e99b7bdc0fb7e25f7a8d888d5b8 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 21 May 2021 20:12:00 +0200 Subject: [PATCH] Misc fixes --- README-generator/README.md | 2 +- README-generator/make_readme.py | 10 +++++++--- README-generator/nginx.conf | 2 +- README-generator/requirements.txt | 1 + README-generator/webhook.py | 13 ++++++++----- README-generator/webhook.service | 2 +- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/README-generator/README.md b/README-generator/README.md index 5da33ff..260e2fe 100644 --- a/README-generator/README.md +++ b/README-generator/README.md @@ -23,7 +23,7 @@ Configure the webhook on github Also need to allow the bot to push on all repos -Configure nginx to reverse proxy on port 80123 (or whichever port you set in the systemd config) +Configure nginx to reverse proxy on port 8123 (or whichever port you set in the systemd config) ```bash echo "github_webhook_secret" > github_webhook_secret diff --git a/README-generator/make_readme.py b/README-generator/make_readme.py index ffbc8f4..9dac1ea 100755 --- a/README-generator/make_readme.py +++ b/README-generator/make_readme.py @@ -12,15 +12,19 @@ def generate_READMEs(app_path): if not os.path.exists(app_path): raise Exception("App path provided doesn't exists ?!") + manifest = json.load(open(os.path.join(app_path, "manifest.json"))) + upstream = manifest.get("upstream", {}) + + if not upstream and not os.path.exists(os.path.join(app_path, "doc", "DISCLAIMER.md")): + print("There's no 'upstream' key in the manifest, and doc/DISCLAIMER.md doesn't exists - therefore assuming that we shall not auto-update the README.md for this app yet.") + return + env = Environment(loader=FileSystemLoader('./templates')) for lang, lang_suffix in [("en", ""), ("fr", "_fr")]: template = env.get_template(f'README{lang_suffix}.md.j2') - manifest = json.load(open(os.path.join(app_path, "manifest.json"))) - upstream = manifest.get("upstream", {}) - if os.path.exists(os.path.join(app_path, "doc", "screenshots")): screenshots = os.listdir(os.path.join(app_path, "doc", "screenshots")) if ".gitkeep" in screenshots: diff --git a/README-generator/nginx.conf b/README-generator/nginx.conf index 4c1374a..3dd620c 100644 --- a/README-generator/nginx.conf +++ b/README-generator/nginx.conf @@ -7,7 +7,7 @@ location / { client_max_body_size 100M; - proxy_pass http://127.0.0.1:80123; + proxy_pass http://127.0.0.1:8123; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; diff --git a/README-generator/requirements.txt b/README-generator/requirements.txt index 8f402cb..3e3ec9d 100644 --- a/README-generator/requirements.txt +++ b/README-generator/requirements.txt @@ -1,3 +1,4 @@ argparse jinja2 github-webhook==1.0.4 +gunicorn==20.1.0 diff --git a/README-generator/webhook.py b/README-generator/webhook.py index bfdcbe0..b47393c 100755 --- a/README-generator/webhook.py +++ b/README-generator/webhook.py @@ -10,11 +10,12 @@ webhook = Webhook(app) # Defines '/postreceive' endpoint webhook.secret = open("github_webhook_secret", "r").read().strip() +login = open("login").read().strip() +token = open("token").read().strip() + my_env = os.environ.copy() my_env["GIT_TERMINAL_PROMPT"] = "0" -login = open("login").read().strip() -token = open("token").read().strip() def git(cmd, in_folder=None): @@ -38,16 +39,18 @@ def on_push(data): branch = data["ref"].split("/", 2)[2] folder = subprocess.check_output(["mktemp", "-d"]) - git(f"clone https://{login}:{token}@github.com/{repository} --single-branch --branch {branch} {folder}") + git(["clone", f"https://{login}:{token}@github.com/{repository}", "--single-branch", "--branch", branch, folder]) generate_READMEs(folder) + git(["add", "README*.md"], in_folder=folder) + diff_not_empty = bool(subprocess.check_output(f"cd {folder} && git diff HEAD --compact-summary", shell=True).strip().decode("utf-8")) if not diff_not_empty: return git(["commit", "-a", "-m", "Auto-update README", "--author='Yunohost-Bot <>'"], in_folder=folder) - git(f"push fork origin {branch} --quiet", in_folder=folder) + git(["push", "fork", "origin", branch, "--quiet"], in_folder=folder) if __name__ == "__main__": - app.run(host="0.0.0.0", port=80123) + app.run(host="0.0.0.0", port=8123) diff --git a/README-generator/webhook.service b/README-generator/webhook.service index 08296b8..e4783c7 100644 --- a/README-generator/webhook.service +++ b/README-generator/webhook.service @@ -7,7 +7,7 @@ PIDFile=/run/gunicorn/autoreadme_webhook-pid User=autoreadme_webhook Group=autoreadme_webhook WorkingDirectory=__PATH_TO_README_GENERATOR__ -ExecStart=__PATH_TO_README_GENERATOR__/venv/bin/gunicorn -w 4 -b 127.0.0.1:80123 webhook:app +ExecStart=__PATH_TO_README_GENERATOR__/venv/bin/gunicorn -w 4 -b 127.0.0.1:8123 webhook:app ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s TERM $MAINPID PrivateTmp=true