Exemple #1
0
def test_handlers(capsys):
    """ Test adding handlers. """
    hook = Webhook()
    assert hook.handlers == {}, "No handlers."

    hook.register("ping", PongOne())
    hook.register("ping", PongTwo())
    hook.respond_to('ping', {})
    out, _ = capsys.readouterr()
    assert out == "got ping\nnow pong\n", "Got ping handler responses."
Exemple #2
0
def test_nonexistent_handler():
    """ Test trying to use an event we don't have handlers for. """
    hook = Webhook()
    hook.respond_to('unknown', {})
Exemple #3
0
from bottle import request, post, run, abort, Bottle
import json
from os.path import normpath, dirname, abspath, join
from ghi_assist.utils import byteify
from ghi_assist.webhook import Webhook
from ghi_assist.hooks import AssignRelatedHook, ClaimHook, CommentLabelHook, NewIssueLabelHook, \
    NewPrLabelHook, PingHook

app = Bottle()
path = normpath(abspath(dirname(__file__)))
with open(join(path, '../etc', 'config.json')) as config_file:
    app.config.load_dict(byteify(json.load(config_file)))
app.config.setdefault('server.host', 'localhost')
app.config.setdefault('server.port', '8080')

webhook = Webhook(secret=app.config["github.secret"], api_token=app.config["github.api_token"])
webhook.register("ping", PingHook())
webhook.register("issue_comment", CommentLabelHook(
    whitelist=app.config["labels.whitelist"],
    aliases=app.config["labels.aliases"][0] # hidden in an array to prevent the nesting from being used
                                            # as namespace by load_dict
))
webhook.register("issue_comment", ClaimHook())
webhook.register("issues", NewIssueLabelHook(
    whitelist=app.config["labels.whitelist"],
    aliases=app.config["labels.aliases"][0]
))
webhook.register("pull_request", NewPrLabelHook(
    whitelist=app.config["labels.whitelist"],
    aliases=app.config["labels.aliases"][0]
))
Exemple #4
0
from bottle import request, post, run, abort, Bottle
import json
from os.path import normpath, dirname, abspath, join
from ghi_assist.utils import byteify
from ghi_assist.webhook import Webhook
from ghi_assist.hooks import AssignRelatedHook, ClaimHook, CommentLabelHook, NewIssueLabelHook, \
    NewPrLabelHook, PingHook, AssignedLabelHook, UrlLabelHook

app = Bottle()
path = normpath(abspath(dirname(__file__)))
with open(join(path, '../etc', 'config.json')) as config_file:
    app.config.load_dict(byteify(json.load(config_file)))
app.config.setdefault('server.host', 'localhost')
app.config.setdefault('server.port', '8080')

webhook = Webhook(secret=app.config.get("github.secret"), api_token=app.config.get("github.api_token"))

if app.config.get("labels.autoload"):
    labels = webhook.load_repo_labels(app.config.get("github.repository"))
else:
    labels = app.config.get("labels.whitelist")

webhook.register("ping", PingHook())
webhook.register("issue_comment", CommentLabelHook(
    whitelist=labels,
    aliases=app.config.get("labels.aliases")[0] # hidden in an array to prevent the nesting from being used
                                            # as namespace by load_dict
))
webhook.register("issue_comment", ClaimHook())
webhook.register("issue_comment", UrlLabelHook(r"https?://www\.dreamwidth\.org/support/see_request\?id=\d+", ["from: support"]))
webhook.register("issues", UrlLabelHook(r"https?://www\.dreamwidth\.org/support/see_request\?id=\d+", ["from: support"]))