Ejemplo n.º 1
0
from zerver.lib.webhooks.common import (
    check_send_webhook_message,
    get_http_headers_from_filename,
    validate_extract_webhook_http_header,
)
from zerver.models import UserProfile

ALL_EVENT_TYPES = [
    "deploy_failed",
    "deploy_locked",
    "deploy_unlocked",
    "deploy_building",
    "deploy_created",
]

fixture_to_headers = get_http_headers_from_filename("HTTP_X_NETLIFY_EVENT")


@webhook_view("Netlify", all_event_types=ALL_EVENT_TYPES)
@has_request_variables
def api_netlify_webhook(
    request: HttpRequest,
    user_profile: UserProfile,
    payload: Dict[str, Sequence[Dict[str, Any]]] = REQ(argument_type="body"),
) -> HttpResponse:

    message_template, event = get_template(request, payload)

    body = message_template.format(
        build_name=payload["name"],
        build_url=payload["url"],
Ejemplo n.º 2
0
    "customer_replied": partial(replied_body, actor="customer", action="replied to"),
    "note_added": partial(replied_body, actor="agent", action="left a note on"),
}

ALL_EVENT_TYPES = list(EVENTS_FUNCTION_MAPPER.keys())


@webhook_view("Groove", all_event_types=ALL_EVENT_TYPES)
@has_request_variables
def api_groove_webhook(
    request: HttpRequest,
    user_profile: UserProfile,
    payload: Dict[str, Any] = REQ(argument_type="body"),
) -> HttpResponse:
    event = validate_extract_webhook_http_header(request, "X_GROOVE_EVENT", "Groove")
    assert event is not None
    handler = EVENTS_FUNCTION_MAPPER.get(event)
    if handler is None:
        raise UnsupportedWebhookEventType(event)

    body = handler(payload)
    topic = "notifications"

    if body is not None:
        check_send_webhook_message(request, user_profile, topic, body, event)

    return json_success()


fixture_to_headers = get_http_headers_from_filename("HTTP_X_GROOVE_EVENT")
Ejemplo n.º 3
0
{extra_info}
```
"""

REPLY_PUBLISHED = """
**{user_name}** [replied]({reply_url}) to [#{id}: {review_request_title}]({review_request_url}):

**Reply**:
``` quote
{reply_body_top}
```
"""

BRANCH_TEMPLATE = "**Branch**: {branch_name}"

fixture_to_headers = get_http_headers_from_filename("HTTP_X_REVIEWBOARD_EVENT")


def get_target_people_string(payload: Dict[str, Any]) -> str:
    result = ""
    target_people = payload['review_request']['target_people']
    if len(target_people) == 1:
        result = "**{title}**".format(**target_people[0])
    else:
        for target_person in target_people[:-1]:
            result += "**{title}**, ".format(**target_person)
        result += "and **{title}**".format(**target_people[-1])

    return result