~edwargix/git.sr.ht

3ac4646627061166b68bc60fc3a6429fe7061fd5 — Drew DeVault 6 years ago d09df42
Set up scm.sr.ht webhooks
M config.example.ini => config.example.ini +2 -2
@@ 64,8 64,8 @@ connection-string=postgresql://postgres@localhost/git.sr.ht
# Set to "yes" to automatically run migrations on package upgrade.
migrate-on-upgrade=yes
#
# The redis connection used for the Celery worker
redis=redis://localhost:6379/1
# The redis connection used for the webhooks worker
webhooks=redis://localhost:6379/1
#
# A post-update script which is installed in every git repo.
post-update-script=/usr/bin/gitsrht-update-hook

M gitsrht-migrate => gitsrht-migrate +0 -1
@@ 3,4 3,3 @@ import gitsrht.alembic
import srht.alembic
from srht.database import alembic
alembic("git.sr.ht", gitsrht.alembic)
alembic("git.sr.ht", srht.alembic)

A gitsrht/alembic/versions/778f04602534_add_repo_webhook_table.py => gitsrht/alembic/versions/778f04602534_add_repo_webhook_table.py +46 -0
@@ 0,0 1,46 @@
"""Add repo webhook table

Revision ID: 778f04602534
Revises: 69b1f39fdca7
Create Date: 2019-04-19 11:41:54.626104

"""

# revision identifiers, used by Alembic.
revision = '778f04602534'
down_revision = '69b1f39fdca7'

from alembic import op
import sqlalchemy as sa
import sqlalchemy_utils as sau


def upgrade():
    op.create_table('repo_webhook_subscription',
        sa.Column("id", sa.Integer, primary_key=True),
        sa.Column("created", sa.DateTime, nullable=False),
        sa.Column("url", sa.Unicode(2048), nullable=False),
        sa.Column("events", sa.Unicode, nullable=False),
        sa.Column("user_id", sa.Integer, sa.ForeignKey("user.id")),
        sa.Column("token_id", sa.Integer, sa.ForeignKey("oauthtoken.id")),
        sa.Column("repo_id", sa.Integer, sa.ForeignKey("repository.id")),
    )
    op.create_table('repo_webhook_delivery',
        sa.Column("id", sa.Integer, primary_key=True),
        sa.Column("uuid", sau.UUIDType, nullable=False),
        sa.Column("created", sa.DateTime, nullable=False),
        sa.Column("event", sa.Unicode(256), nullable=False),
        sa.Column("url", sa.Unicode(2048), nullable=False),
        sa.Column("payload", sa.Unicode(65536), nullable=False),
        sa.Column("payload_headers", sa.Unicode(16384), nullable=False),
        sa.Column("response", sa.Unicode(65536)),
        sa.Column("response_status", sa.Integer, nullable=False),
        sa.Column("response_headers", sa.Unicode(16384)),
        sa.Column("subscription_id", sa.Integer,
            sa.ForeignKey('repo_webhook_subscription.id'), nullable=False),
    )


def downgrade():
    op.drop_table('repo_webhook_delivery')
    op.drop_table('repo_webhook_subscription')

M gitsrht/app.py => gitsrht/app.py +1 -0
@@ 11,6 11,7 @@ from gitsrht.types import Access, Redirect, Repository, User
from scmsrht.flask import ScmSrhtFlask
from srht.config import cfg
from srht.database import DbSession
import gitsrht.webhooks # makes valid the global

db = DbSession(cfg("git.sr.ht", "connection-string"))
db.init()

A gitsrht/webhooks.py => gitsrht/webhooks.py +11 -0
@@ 0,0 1,11 @@
from srht.config import cfg
from srht.database import DbSession, db
if not hasattr(db, "session"):
    # Initialize the database if not already configured (for running daemon)
    db = DbSession(cfg("git.sr.ht", "connection-string"))
    import gitsrht.types
    db.init()
from srht.webhook.celery import make_worker
from scmsrht.webhooks import RepoWebhook

worker = make_worker(broker=cfg("git.sr.ht", "webhooks"))