~edwargix/git.sr.ht

3ba441903ef67418980d9ce63dde475c6fa36224 — Adnan Maolood 2 years ago eb8cf38
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.
2 files changed, 19 insertions(+), 0 deletions(-)

M gitsrht/blueprints/api/info.py
M gitsrht/webhooks.py
M gitsrht/blueprints/api/info.py => gitsrht/blueprints/api/info.py +12 -0
@@ 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)

M gitsrht/webhooks.py => gitsrht/webhooks.py +7 -0
@@ 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"),