From 3ba441903ef67418980d9ce63dde475c6fa36224 Mon Sep 17 00:00:00 2001 From: Adnan Maolood Date: Thu, 3 Feb 2022 17:50:20 -0500 Subject: [PATCH] gitsrht: Add missing routes These routes should have been added to git.sr.ht along with the rest of the routes moved over from scm.sr.ht. --- gitsrht/blueprints/api/info.py | 12 ++++++++++++ gitsrht/webhooks.py | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/gitsrht/blueprints/api/info.py b/gitsrht/blueprints/api/info.py index c943756..3c662e7 100644 --- a/gitsrht/blueprints/api/info.py +++ b/gitsrht/blueprints/api/info.py @@ -2,6 +2,7 @@ from flask import Blueprint, Response, current_app, request from scmsrht.access import UserAccess from scmsrht.repos import RepoVisibility from scmsrht.types import Access, Repository, User +from gitsrht.webhooks import UserWebhook from gitsrht.blueprints.api import get_user, get_repo from srht.api import paginated_response from srht.database import db @@ -156,3 +157,14 @@ def repos_by_name_readme_DELETE(reponame): if not valid.ok: return valid.response return {}, 204 + +def _webhook_filters(query): + user = get_user(None) + return query.filter(UserWebhook.Subscription.user_id == user.id) + +def _webhook_create(sub, valid): + user = get_user(None) + return sub + +UserWebhook.api_routes(info, "/api/user", + filters=_webhook_filters, create=_webhook_create) diff --git a/gitsrht/webhooks.py b/gitsrht/webhooks.py index c857698..36486d0 100644 --- a/gitsrht/webhooks.py +++ b/gitsrht/webhooks.py @@ -14,6 +14,13 @@ webhook_broker = cfg("git.sr.ht", "webhooks") worker = make_worker(broker=webhook_broker) webhook_metrics_collector = RedisQueueCollector(webhook_broker, "srht_webhooks", "Webhook queue length") +class UserWebhook(CeleryWebhook): + events = [ + Event("repo:create", "info:read"), + Event("repo:delete", "info:read"), + Event("repo:update", "info:read"), + ] + class RepoWebhook(CeleryWebhook): events = [ Event("repo:post-update", "data:read"), -- 2.38.4