当前位置: 首页>>代码示例>>Python>>正文


Python actions.check_send_message函数代码示例

本文整理汇总了Python中zerver.lib.actions.check_send_message函数的典型用法代码示例。如果您正苦于以下问题:Python check_send_message函数的具体用法?Python check_send_message怎么用?Python check_send_message使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了check_send_message函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: api_jira_webhook

def api_jira_webhook(request, user_profile, client,
                     payload=REQ(argument_type='body'),
                     stream=REQ(default='jira')):
    # type: (HttpRequest, UserProfile, Client, Dict[str, Any], Text) -> HttpResponse

    event = payload.get('webhookEvent')
    if event == 'jira:issue_created':
        subject = get_issue_subject(payload)
        content = handle_created_issue_event(payload)
    elif event == 'jira:issue_deleted':
        subject = get_issue_subject(payload)
        content = handle_deleted_issue_event(payload)
    elif event == 'jira:issue_updated':
        subject = get_issue_subject(payload)
        content = handle_updated_issue_event(payload, user_profile)
    elif event in IGNORED_EVENTS:
        return json_success()
    else:
        if event is None:
            if not settings.TEST_SUITE:
                message = "Got JIRA event with None event type: {}".format(payload)
                logging.warning(message)
            return json_error(_("Event is not given by JIRA"))
        else:
            if not settings.TEST_SUITE:
                logging.warning("Got JIRA event type we don't support: {}".format(event))
            return json_error(_("Got JIRA event type we don't support: {}".format(event)))

    check_send_message(user_profile, client, "stream", [stream], subject, content)
    return json_success()
开发者ID:acemaster,项目名称:zulip,代码行数:30,代码来源:jira.py

示例2: api_beanstalk_webhook

def api_beanstalk_webhook(request, user_profile,
                          payload=REQ(validator=check_dict([]))):
    # Beanstalk supports both SVN and git repositories
    # We distinguish between the two by checking for a
    # 'uri' key that is only present for git repos
    git_repo = 'uri' in payload
    if git_repo:
        # To get a linkable url,
        subject, content = build_message_from_gitlog(user_profile, payload['repository']['name'],
                                                     payload['ref'], payload['commits'],
                                                     payload['before'], payload['after'],
                                                     payload['repository']['url'],
                                                     payload['pusher_name'])
    else:
        author = payload.get('author_full_name')
        url = payload.get('changeset_url')
        revision = payload.get('revision')
        (short_commit_msg, _, _) = payload.get('message').partition("\n")

        subject = "svn r%s" % (revision,)
        content = "%s pushed [revision %s](%s):\n\n> %s" % (author, revision, url, short_commit_msg)

    check_send_message(user_profile, get_client("ZulipBeanstalkWebhook"), "stream",
                       ["commits"], subject, content)
    return json_success()
开发者ID:anindya,项目名称:zulip,代码行数:25,代码来源:webhooks.py

示例3: api_bitbucket_webhook

def api_bitbucket_webhook(request, user_profile, payload=REQ(validator=check_dict([])),
                          stream=REQ(default='commits')):
    # type: (HttpRequest, UserProfile, Dict[str, Any], str) -> None
    repository = payload['repository']
    commits = [{'id': commit['raw_node'], 'message': commit['message'],
                'url': '%s%scommits/%s' % (payload['canon_url'],
                                           repository['absolute_url'],
                                           commit['raw_node'])}
               for commit in payload['commits']]

    subject = repository['name']
    if len(commits) == 0:
        # Bitbucket doesn't give us enough information to really give
        # a useful message :/
        content = ("%s [force pushed](%s)"
                   % (payload['user'],
                      payload['canon_url'] + repository['absolute_url']))
    else:
        branch = payload['commits'][-1]['branch']
        content = build_commit_list_content(commits, branch, None, payload['user'])
        subject += '/%s' % (branch,)

    check_send_message(user_profile, get_client("ZulipBitBucketWebhook"), "stream",
                       [stream], subject, content)
    return json_success()
开发者ID:MarkCupitt,项目名称:zulip,代码行数:25,代码来源:bitbucket.py

示例4: api_basecamp_webhook

def api_basecamp_webhook(request, user_profile, payload=REQ(argument_type='body'),
                         stream=REQ(default='basecamp')):
    # type: (HttpRequest, UserProfile, Dict[str, Any], Text) -> HttpResponse
    event = get_event_type(payload)

    if event not in SUPPORT_EVENTS:
        logging.warning("Basecamp {} event is not supported".format(event))
        return json_success()

    subject = get_project_name(payload)
    if event.startswith('document_'):
        body = get_document_body(event, payload)
    elif event.startswith('question_answer_'):
        body = get_questions_answer_body(event, payload)
    elif event.startswith('question_'):
        body = get_questions_body(event, payload)
    elif event.startswith('message_'):
        body = get_message_body(event, payload)
    elif event.startswith('todolist_'):
        body = get_todo_list_body(event, payload)
    elif event.startswith('todo_'):
        body = get_todo_body(event, payload)
    elif event.startswith('comment_'):
        body = get_comment_body(event, payload)
    else:
        logging.warning("Basecamp handling of {} event is not implemented".format(event))
        return json_success()

    check_send_message(user_profile, request.client, 'stream', [stream], subject, body)
    return json_success()
开发者ID:JamesLinus,项目名称:zulip,代码行数:30,代码来源:view.py

示例5: api_greenhouse_webhook

def api_greenhouse_webhook(request, user_profile,
                           payload=REQ(argument_type='body'),
                           stream=REQ(default='greenhouse'), topic=REQ(default=None)):
    # type: (HttpRequest, UserProfile, Dict[str, Any], str, str) -> HttpResponse
    try:
        if payload['action'] == 'update_candidate':
            candidate = payload['payload']['candidate']
        else:
            candidate = payload['payload']['application']['candidate']
        action = payload['action'].replace('_', ' ').title()
        body = "{}\n>{} {}\nID: {}\n{}".format(
            action,
            candidate['first_name'],
            candidate['last_name'],
            str(candidate['id']),
            message_creator(payload['action'],
                            payload['payload']['application']))

        if topic is None:
            topic = "{} - {}".format(action, str(candidate['id']))

    except KeyError as e:
        return json_error(_("Missing key {} in JSON").format(str(e)))

    check_send_message(user_profile, request.client, 'stream', [stream], topic, body)
    return json_success()
开发者ID:JamesLinus,项目名称:zulip,代码行数:26,代码来源:view.py

示例6: api_papertrail_webhook

def api_papertrail_webhook(request, user_profile,
                           payload=REQ(argument_type='body'),
                           stream=REQ(default='papertrail'),
                           topic=REQ(default='logs')):
    # type: (HttpRequest, UserProfile, Dict[str, Any], Text, Text) -> HttpResponse

    # construct the message of the message
    try:
        message_template = '**"{}"** search found **{}** matches - {}\n```'
        message = [message_template.format(payload["saved_search"]["name"],
                                           str(len(payload["events"])),
                                           payload["saved_search"]["html_search_url"])]
        for i, event in enumerate(payload["events"]):
            event_text = '{} {} {}:\n  {}'.format(event["display_received_at"],
                                                  event["source_name"],
                                                  payload["saved_search"]["query"],
                                                  event["message"])
            message.append(event_text)
            if i >= 3:
                message.append('```\n[See more]({})'.format(payload["saved_search"]["html_search_url"]))
                break
        else:
            message.append('```')
        post = '\n'.join(message)
    except KeyError as e:
        return json_error(_("Missing key {} in JSON").format(str(e)))

    # send the message
    check_send_message(user_profile, request.client, 'stream', [stream], topic, post)

    # return json result
    return json_success()
开发者ID:yhl-python,项目名称:zulip,代码行数:32,代码来源:view.py

示例7: api_wordpress_webhook

def api_wordpress_webhook(request, user_profile,
                          stream=REQ(default="wordpress"),
                          topic=REQ(default="WordPress Notification"),
                          hook=REQ(default="WordPress Action"),
                          post_title=REQ(default="New WordPress Post"),
                          post_type=REQ(default="post"),
                          post_url=REQ(default="WordPress Post URL"),
                          display_name=REQ(default="New User Name"),
                          user_email=REQ(default="New User Email"),
                          user_login=REQ(default="Logged in User")):
    # type: (HttpRequest, UserProfile, text_type, text_type, text_type, text_type, text_type, text_type, text_type, text_type, text_type) -> HttpResponse

    # remove trailing whitespace (issue for some test fixtures)
    hook = hook.rstrip()

    if hook == 'publish_post' or hook == 'publish_page':
        data = PUBLISH_POST_OR_PAGE_TEMPLATE.format(type=post_type, title=post_title, url=post_url)

    elif hook == 'user_register':
        data = USER_REGISTER_TEMPLATE.format(name=display_name, email=user_email)

    elif hook == 'wp_login':
        data = WP_LOGIN_TEMPLATE.format(name=user_login)

    else:
        return json_error(_("Unknown WordPress webhook action: " + hook))

    check_send_message(user_profile, get_client("ZulipWordPressWebhook"), "stream",
                       [stream], topic, data)
    return json_success()
开发者ID:JamesLinus,项目名称:zulip,代码行数:30,代码来源:view.py

示例8: send_formated_pagerduty

def send_formated_pagerduty(user_profile, client, stream, message_type, format_dict, topic):
    if message_type in ("incident.trigger", "incident.unacknowledge"):
        template = (
            u":imp: Incident "
            u"[{incident_num}]({incident_url}) {action} by "
            u"[{service_name}]({service_url}) and assigned to "
            u"[{assigned_to_username}@]({assigned_to_url})\n\n>{trigger_message}"
        )

    elif message_type == "incident.resolve" and format_dict["resolved_by_url"]:
        template = (
            u":grinning: Incident "
            u"[{incident_num}]({incident_url}) resolved by "
            u"[{resolved_by_username}@]({resolved_by_url})\n\n>{trigger_message}"
        )
    elif message_type == "incident.resolve" and not format_dict["resolved_by_url"]:
        template = u":grinning: Incident " u"[{incident_num}]({incident_url}) resolved\n\n>{trigger_message}"
    else:
        template = (
            u":no_good: Incident [{incident_num}]({incident_url}) "
            u"{action} by [{assigned_to_username}@]({assigned_to_url})\n\n>{trigger_message}"
        )

    subject = topic or u"incident {incident_num}".format(**format_dict)
    body = template.format(**format_dict)

    check_send_message(user_profile, client, "stream", [stream], subject, body)
开发者ID:RomiPierre,项目名称:zulip,代码行数:27,代码来源:pagerduty.py

示例9: api_travis_webhook

def api_travis_webhook(request, user_profile, client,
                       stream=REQ(default='travis'),
                       topic=REQ(default=None),
                       ignore_pull_requests=REQ(validator=check_bool, default=True),
                       message=REQ('payload', validator=check_dict([
                           ('author_name', check_string),
                           ('status_message', check_string),
                           ('compare_url', check_string),
                       ]))):
    # type: (HttpRequest, UserProfile, Client, str, str, str, Dict[str, str]) -> HttpResponse

    message_status = message['status_message']
    if ignore_pull_requests and message['type'] == 'pull_request':
        return json_success()

    if message_status in GOOD_STATUSES:
        emoji = ':thumbsup:'
    elif message_status in BAD_STATUSES:
        emoji = ':thumbsdown:'
    else:
        emoji = "(No emoji specified for status '{}'.)".format(message_status)

    body = MESSAGE_TEMPLATE.format(
        message['author_name'],
        message_status,
        emoji,
        message['compare_url'],
        message['build_url']
    )

    check_send_message(user_profile, client, 'stream', [stream], topic, body)
    return json_success()
开发者ID:aakash-cr7,项目名称:zulip,代码行数:32,代码来源:view.py

示例10: api_newrelic_webhook

def api_newrelic_webhook(request, user_profile, alert=REQ(validator=check_dict([]), default=None),
                             deployment=REQ(validator=check_dict([]), default=None)):
    try:
        stream = request.GET['stream']
    except (AttributeError, KeyError):
        return json_error("Missing stream parameter.")

    if alert:
        # Use the message as the subject because it stays the same for
        # "opened", "acknowledged", and "closed" messages that should be
        # grouped.
        subject = alert['message']
        content = "%(long_description)s\n[View alert](%(alert_url)s)" % (alert)
    elif deployment:
        subject = "%s deploy" % (deployment['application_name'])
        content = """`%(revision)s` deployed by **%(deployed_by)s**
%(description)s

%(changelog)s""" % (deployment)
    else:
        return json_error("Unknown webhook request")

    check_send_message(user_profile, get_client("ZulipNewRelicWebhook"), "stream",
                       [stream], subject, content)
    return json_success()
开发者ID:anindya,项目名称:zulip,代码行数:25,代码来源:webhooks.py

示例11: api_stash_webhook

def api_stash_webhook(request, user_profile, payload=REQ(argument_type='body'),
                      stream=REQ(default='commits')):
    # type: (HttpRequest, UserProfile, Dict[str, Any], text_type) -> HttpResponse
    # We don't get who did the push, or we'd try to report that.
    try:
        repo_name = payload["repository"]["name"]
        project_name = payload["repository"]["project"]["name"]
        branch_name = payload["refChanges"][0]["refId"].split("/")[-1]
        commit_entries = payload["changesets"]["values"]
        commits = [(entry["toCommit"]["displayId"],
                    entry["toCommit"]["message"].split("\n")[0]) for \
                       entry in commit_entries]
        head_ref = commit_entries[-1]["toCommit"]["displayId"]
    except KeyError as e:
        return json_error(_("Missing key %s in JSON") % (e.message,))

    subject = "%s/%s: %s" % (project_name, repo_name, branch_name)

    content = "`%s` was pushed to **%s** in **%s/%s** with:\n\n" % (
        head_ref, branch_name, project_name, repo_name)
    content += "\n".join("* `%s`: %s" % (
            commit[0], commit[1]) for commit in commits)

    check_send_message(user_profile, get_client("ZulipStashWebhook"), "stream",
                       [stream], subject, content)
    return json_success()
开发者ID:Kingedgar,项目名称:zulip,代码行数:26,代码来源:stash.py

示例12: api_splunk_webhook

def api_splunk_webhook(request, user_profile,
                       payload=REQ(argument_type='body'), stream=REQ(default='splunk'),
                       topic=REQ(default=None)):
    # type: (HttpRequest, UserProfile, Dict[str, Any], Text, Optional[Text]) -> HttpResponse

    # use default values if expected data is not provided
    search_name = payload.get('search_name', 'Missing search_name')
    results_link = payload.get('results_link', 'Missing results_link')
    host = payload.get('result', {}).get('host', 'Missing host')
    source = payload.get('result', {}).get('source', 'Missing source')
    raw = payload.get('result', {}).get('_raw', 'Missing _raw')

    # if no topic provided, use search name but truncate if too long
    if topic is None:
        if len(search_name) >= MAX_SUBJECT_LENGTH:
            topic = "{}...".format(search_name[:(MAX_SUBJECT_LENGTH - 3)])
        else:
            topic = search_name

    # construct the message body
    body = "Splunk alert from saved search"
    body_template = ('\n[{search}]({link})\nhost: {host}'
                     '\nsource: {source}\n\nraw: {raw}')
    body += body_template.format(search = search_name, link = results_link,
                                 host = host, source = source, raw = raw)

    # send the message
    check_send_message(user_profile, request.client, 'stream', [stream], topic, body)

    return json_success()
开发者ID:JamesLinus,项目名称:zulip,代码行数:30,代码来源:view.py

示例13: api_teamcity_webhook

def api_teamcity_webhook(request, user_profile, payload=REQ(argument_type='body'),
                         stream=REQ(default='teamcity')):
    # type: (HttpRequest, UserProfile, Dict[str, Any], str) -> HttpResponse
    message = payload['build']

    build_name = message['buildFullName']
    build_url = message['buildStatusUrl']
    changes_url = build_url + '&tab=buildChangesDiv'
    build_number = message['buildNumber']
    build_result = message['buildResult']
    build_result_delta = message['buildResultDelta']
    build_status = message['buildStatus']

    if build_result == 'success':
        if build_result_delta == 'fixed':
            status = 'has been fixed! :thumbsup:'
        else:
            status = 'was successful! :thumbsup:'
    elif build_result == 'failure':
        if build_result_delta == 'broken':
            status = 'is broken with status %s! :thumbsdown:' % (build_status,)
        else:
            status = 'is still broken with status %s! :thumbsdown:' % (build_status,)
    elif build_result == 'running':
        status = 'has started.'
    else:
        status = '(has no message specified for status %s)' % (build_status,)

    template = (
        u'%s build %s %s\n'
        u'Details: [changes](%s), [build log](%s)')

    body = template % (build_name, build_number, status, changes_url, build_url)
    topic = build_name

    # Check if this is a personal build, and if so try to private message the user who triggered it.
    if get_teamcity_property_value(message['teamcityProperties'], 'env.BUILD_IS_PERSONAL') == 'true':
        # The triggeredBy field gives us the teamcity user full name, and the "teamcity.build.triggeredBy.username"
        # property gives us the teamcity username. Let's try finding the user email from both.
        teamcity_fullname = message['triggeredBy'].split(';')[0]
        teamcity_user = guess_zulip_user_from_teamcity(teamcity_fullname, user_profile.realm)

        if teamcity_user is None:
            teamcity_shortname = get_teamcity_property_value(message['teamcityProperties'],
                                                             'teamcity.build.triggeredBy.username')
            if teamcity_shortname is not None:
                teamcity_user = guess_zulip_user_from_teamcity(teamcity_shortname, user_profile.realm)

        if teamcity_user is None:
            # We can't figure out who started this build - there's nothing we can do here.
            logging.info("Teamcity webhook couldn't find a matching Zulip user for Teamcity user '%s' or '%s'" % (
                teamcity_fullname, teamcity_shortname))
            return json_success()

        body = "Your personal build of " + body
        check_send_message(user_profile, request.client, 'private', [teamcity_user.email], topic, body)
        return json_success()

    check_send_message(user_profile, request.client, 'stream', [stream], topic, body)
    return json_success()
开发者ID:JamesLinus,项目名称:zulip,代码行数:60,代码来源:view.py

示例14: api_bitbucket_webhook

def api_bitbucket_webhook(request, user_profile, payload=REQ(validator=check_dict([])),
                          stream=REQ(default='commits')):
    # type: (HttpRequest, UserProfile, Mapping[Text, Any], Text) -> HttpResponse
    repository = payload['repository']

    commits = [
        {
            'sha': commit.get('raw_node'),
            'message': commit.get('message'),
            'url': u'{}{}commits/{}'.format(
                payload.get('canon_url'),
                repository.get('absolute_url'),
                commit.get('raw_node'))
        }
        for commit in payload.get('commits')
    ]

    if len(commits) == 0:
        # Bitbucket doesn't give us enough information to really give
        # a useful message :/
        subject = repository['name']
        content = (u"%s [force pushed](%s)"
                   % (payload['user'],
                      payload['canon_url'] + repository['absolute_url']))
    else:
        branch = payload['commits'][-1]['branch']
        content = get_push_commits_event_message(payload.get('user'), None, branch, commits)
        subject = SUBJECT_WITH_BRANCH_TEMPLATE.format(repo=repository['name'], branch=branch)

    check_send_message(user_profile, get_client("ZulipBitBucketWebhook"), "stream",
                       [stream], subject, content)
    return json_success()
开发者ID:TomaszKolek,项目名称:zulip,代码行数:32,代码来源:view.py

示例15: api_circleci_webhook

def api_circleci_webhook(request, user_profile, client, payload=REQ(argument_type='body'), stream=REQ(default='circleci')):
    payload = payload['payload']
    subject = get_subject(payload)
    body = get_body(payload)

    check_send_message(user_profile, client, 'stream', [stream], subject, body)
    return json_success()
开发者ID:8trust,项目名称:zulip,代码行数:7,代码来源:circleci.py


注:本文中的zerver.lib.actions.check_send_message函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。