~sircmpwn/sr.ht-dev

hg.sr.ht: Report buildsrht submit errors to the client v1 APPLIED

Ludovic Chabant: 1
 Report buildsrht submit errors to the client

 2 files changed, 23 insertions(+), 7 deletions(-)
Shipped!
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/22240/mbox | git am -3
Learn more about email & git

[PATCH hg.sr.ht] Report buildsrht submit errors to the client Export this patch

# HG changeset patch
# User Ludovic Chabant <ludovic@chabant.com>
# Date 1619151830 0
#      Fri Apr 23 04:23:50 2021 +0000
# Node ID dc3fb2d5a3e09c473968d203df92ecf75b2a08af
# Parent  985f1740a51a91f11bcb70245b1e8d292a54476e
Report buildsrht submit errors to the client

diff --git a/hgsrht-hook-changegroup b/hgsrht-hook-changegroup
--- a/hgsrht-hook-changegroup
+++ b/hgsrht-hook-changegroup
@@ -20,8 +20,9 @@
    if repo_id is None:
        raise Exception("Server Error: repo info missing ID")
except Exception as ex:
    std.stderr.write(str(ex))
    sys.stderr.exit(1)
    sys.stderr.write(str(ex))
    sys.stderr.write("\n")
    sys.exit(1)

# If the repo was auto-created, print some warning.
if repo.get("visibility") == "autocreated":
@@ -41,10 +42,20 @@
headers.update(sign_payload(payload))
r = requests.post(f"{origin}/internal/hook-changegroup",
        data=payload, headers=headers)

try:
    response = r.json()
except:
    sys.stderr.write("Server Error: invalid response from internal hook\n")
    sys.exit(1)

if r.status_code == 200:
    response = r.json()
    status = response.get('status')
    msgs = response.get('messages')
    if status != 'skipped' and msgs:
        for msg in msgs:
            print(msg)
else:
    errormsg = response.get('why') or "unknown error"
    sys.stderr.write(f"Server Error: {errormsg}\n")
    sys.exit(1)
diff --git a/hgsrht/blueprints/internal.py b/hgsrht/blueprints/internal.py
--- a/hgsrht/blueprints/internal.py
+++ b/hgsrht/blueprints/internal.py
@@ -109,8 +109,13 @@
    db.session.commit()

    # Trigger buildsrht builds.
    res = trigger_changegroup_build(repo, node_last)
    if res is not None:
        return res.asdict(), 200
    try:
        res = trigger_changegroup_build(repo, node_last)
        if res is not None:
            return res.asdict(), 200

    return {}, 200
        return {}, 200
    except Exception as ex:
        return {
            "why": str(ex)
        }, 500
LGTM. Ship it?