示例#1
0
def get_commented_commit_event_body(payload: Dict[str, Any]) -> str:
    comment = payload["object_attributes"]
    action = "[commented]({})".format(comment["url"])
    return get_commits_comment_action_message(
        get_issue_user_name(payload),
        action,
        payload["commit"].get("url"),
        payload["commit"].get("id"),
        comment["note"],
    )
示例#2
0
文件: view.py 项目: priyank-p/zulip
def get_commented_commit_event_body(payload: WildValue) -> str:
    comment = payload["object_attributes"]
    action = "[commented]({})".format(comment["url"].tame(check_string))
    return get_commits_comment_action_message(
        get_issue_user_name(payload),
        action,
        payload["commit"]["url"].tame(check_string),
        payload["commit"]["id"].tame(check_string),
        comment["note"].tame(check_string),
    )
示例#3
0
def get_commit_comment_body(payload: Dict[str, Any]) -> str:
    comment = payload['comment']
    action = u'[commented]({})'.format(comment['links']['html']['href'])
    return get_commits_comment_action_message(
        get_user_username(payload),
        action,
        comment['commit']['links']['html']['href'],
        comment['commit']['hash'],
        comment['content']['raw'],
    )
示例#4
0
文件: view.py 项目: gregmccoy/zulip
def get_commented_commit_event_body(payload: Dict[str, Any]) -> str:
    comment = payload['object_attributes']
    action = u'[commented]({})'.format(comment['url'])
    return get_commits_comment_action_message(
        get_issue_user_name(payload),
        action,
        payload['commit'].get('url'),
        payload['commit'].get('id'),
        comment['note'],
    )
示例#5
0
文件: view.py 项目: buyrs/demozy
def get_commit_comment_body(payload: Dict[str, Any]) -> str:
    comment = payload["comment"]
    action = "[commented]({})".format(comment["links"]["html"]["href"])
    return get_commits_comment_action_message(
        get_actor_info(payload),
        action,
        comment["commit"]["links"]["html"]["href"],
        comment["commit"]["hash"],
        comment["content"]["raw"],
    )
示例#6
0
文件: view.py 项目: joydeep1701/zulip
def get_commit_comment_body(payload: Dict[str, Any]) -> Text:
    comment = payload['comment']
    action = u'[commented]({})'.format(comment['links']['html']['href'])
    return get_commits_comment_action_message(
        get_user_username(payload),
        action,
        comment['commit']['links']['html']['href'],
        comment['commit']['hash'],
        comment['content']['raw'],
    )
示例#7
0
文件: view.py 项目: vineetb95/zulip
def get_commented_commit_event_body(payload: Dict[str, Any]) -> str:
    comment = payload['object_attributes']
    action = '[commented]({})'.format(comment['url'])
    return get_commits_comment_action_message(
        get_issue_user_name(payload),
        action,
        payload['commit'].get('url'),
        payload['commit'].get('id'),
        comment['note'],
    )
示例#8
0
文件: view.py 项目: priyank-p/zulip
def get_commit_comment_body(payload: WildValue, include_title: bool) -> str:
    comment = payload["comment"]
    action = "[commented]({})".format(comment["links"]["html"]["href"].tame(check_string))
    return get_commits_comment_action_message(
        get_actor_info(payload),
        action,
        comment["commit"]["links"]["html"]["href"].tame(check_string),
        comment["commit"]["hash"].tame(check_string),
        comment["content"]["raw"].tame(check_string),
    )
示例#9
0
文件: gitlab.py 项目: galexrt/zulip
def get_commented_commit_event_body(payload):
    # type: (Dict[str, Any]) -> text_type
    comment = payload.get('object_attributes')
    action = u'[commented]({})'.format(comment['url'])
    return get_commits_comment_action_message(
        get_issue_user_name(payload),
        action,
        payload.get('commit').get('url'),
        payload.get('commit').get('id'),
        comment['note'],
    )
示例#10
0
文件: view.py 项目: ysguoqiang/zulip
def get_commented_commit_event_body(payload):
    # type: (Dict[str, Any]) -> Text
    comment = payload.get('object_attributes')
    action = u'[commented]({})'.format(comment['url'])
    return get_commits_comment_action_message(
        get_issue_user_name(payload),
        action,
        payload.get('commit').get('url'),
        payload.get('commit').get('id'),
        comment['note'],
    )
示例#11
0
文件: view.py 项目: gnprice/zulip
def get_commit_comment_body(payload: Dict[str, Any]) -> Text:
    comment = payload['comment']
    comment_url = comment['html_url']
    commit_url = comment_url.split('#', 1)[0]
    action = u'[commented]({})'.format(comment_url)
    return get_commits_comment_action_message(
        get_sender_name(payload),
        action,
        commit_url,
        comment.get('commit_id'),
        comment['body'],
    )
示例#12
0
def get_commit_comment_body(payload: Dict[str, Any]) -> str:
    comment = payload['comment']
    comment_url = comment['html_url']
    commit_url = comment_url.split('#', 1)[0]
    action = u'[commented]({})'.format(comment_url)
    return get_commits_comment_action_message(
        get_sender_name(payload),
        action,
        commit_url,
        comment.get('commit_id'),
        comment['body'],
    )
示例#13
0
def get_commit_comment_body(helper: Helper) -> str:
    payload = helper.payload
    comment = payload["comment"]
    comment_url = comment["html_url"]
    commit_url = comment_url.split("#", 1)[0]
    action = f"[commented]({comment_url})"
    return get_commits_comment_action_message(
        get_sender_name(payload),
        action,
        commit_url,
        comment.get("commit_id"),
        comment["body"],
    )
示例#14
0
def get_commit_comment_body(helper: Helper) -> str:
    payload = helper.payload
    comment = payload['comment']
    comment_url = comment['html_url']
    commit_url = comment_url.split('#', 1)[0]
    action = f'[commented]({comment_url})'
    return get_commits_comment_action_message(
        get_sender_name(payload),
        action,
        commit_url,
        comment.get('commit_id'),
        comment['body'],
    )
示例#15
0
def repo_comment_handler(payload: Dict[str, Any],
                         action: str) -> List[Dict[str, str]]:
    repo_name = payload["repository"]["name"]
    user_name = payload["actor"]["name"]
    subject = BITBUCKET_TOPIC_TEMPLATE.format(repository_name=repo_name)
    sha = payload["commit"]
    commit_url = payload["repository"]["links"]["self"][0][
        "href"][:-6]  # remove the "browse" at the end
    commit_url += "commits/%s" % (sha, )
    body = get_commits_comment_action_message(
        user_name=user_name,
        action=action,
        commit_url=commit_url,
        sha=sha,
        message=payload["comment"]["text"])
    return [{"subject": subject, "body": body}]
示例#16
0
文件: view.py 项目: scrapcode/zulip
def repo_comment_handler(payload: Dict[str, Any], action: str) -> List[Dict[str, str]]:
    repo_name = payload["repository"]["name"]
    subject = BITBUCKET_TOPIC_TEMPLATE.format(repository_name=repo_name)
    sha = payload["commit"]
    commit_url = payload["repository"]["links"]["self"][0]["href"][: -len("browse")]
    commit_url += f"commits/{sha}"
    message = payload["comment"]["text"]
    if action == "deleted their comment":
        message = f"~~{message}~~"
    body = get_commits_comment_action_message(
        user_name=get_user_name(payload),
        action=action,
        commit_url=commit_url,
        sha=sha,
        message=message,
    )
    return [{"subject": subject, "body": body}]
示例#17
0
def repo_comment_handler(
    payload: WildValue,
    action: str,
    branches: Optional[str],
    include_title: Optional[str],
) -> List[Dict[str, str]]:
    repo_name = payload["repository"]["name"].tame(check_string)
    subject = BITBUCKET_TOPIC_TEMPLATE.format(repository_name=repo_name)
    sha = payload["commit"].tame(check_string)
    commit_url = payload["repository"]["links"]["self"][0]["href"].tame(
        check_string)[:-len("browse")]
    commit_url += f"commits/{sha}"
    message = payload["comment"]["text"].tame(check_string)
    if action == "deleted their comment":
        message = f"~~{message}~~"
    body = get_commits_comment_action_message(
        user_name=get_user_name(payload),
        action=action,
        commit_url=commit_url,
        sha=sha,
        message=message,
    )
    return [{"subject": subject, "body": body}]
示例#18
0
文件: view.py 项目: akashnimare/zulip
def api_github_v2(user_profile: UserProfile, event: str, payload: Mapping[str, Any],
                  branches: str, default_stream: str, commit_stream: str,
                  issue_stream: str, topic_focus: Optional[str]=None) -> Tuple[str, str, str]:
    """
    processes github payload with version 2 field specification
    `payload` comes in unmodified from github
    `default_stream` is set to what `stream` is in v1 above
    `commit_stream` and `issue_stream` fall back to `default_stream` if they are empty
    This and allowing alternative endpoints is what distinguishes v1 from v2 of the github configuration
    """
    target_stream = commit_stream if commit_stream else default_stream
    issue_stream = issue_stream if issue_stream else default_stream
    repository = payload['repository']
    updated_topic_focus = topic_focus if topic_focus else repository['name']

    # Event Handlers
    if event == 'pull_request':
        subject = get_pull_request_or_issue_subject(repository, payload['pull_request'], 'PR')
        content = github_pull_request_content(payload)
    elif event == 'issues':
        # in v1, we assume that this stream exists since it is
        # deprecated and the few realms that use it already have the
        # stream
        target_stream = issue_stream
        subject = get_pull_request_or_issue_subject(repository, payload['issue'], 'Issue')
        content = github_issues_content(payload)
    elif event == 'issue_comment':
        # Comments on both issues and pull requests come in as issue_comment events
        issue = payload['issue']
        if 'pull_request' not in issue or issue['pull_request']['diff_url'] is None:
            # It's an issues comment
            target_stream = issue_stream
            type = 'Issue'
            subject = get_pull_request_or_issue_subject(repository, payload['issue'], type)
        else:
            # It's a pull request comment
            type = 'PR'
            subject = get_pull_request_or_issue_subject(repository, payload['issue'], type)

        content = github_object_commented_content(payload, type)

    elif event == 'push':
        subject, content = build_message_from_gitlog(user_profile, updated_topic_focus,
                                                     payload['ref'], payload['commits'],
                                                     payload['before'], payload['after'],
                                                     payload['compare'],
                                                     payload['pusher']['name'],
                                                     forced=payload['forced'],
                                                     created=payload['created'],
                                                     deleted=payload['deleted'])
    elif event == 'commit_comment':
        subject = updated_topic_focus

        comment = payload['comment']
        action = u'[commented]({})'.format(comment['html_url'])
        content = get_commits_comment_action_message(
            comment['user']['login'],
            action,
            comment['html_url'].split('#', 1)[0],
            comment['commit_id'],
            comment['body'],
        )

    else:
        raise UnknownEventType(u'Event %s is unknown and cannot be handled' % (event,))

    return target_stream, subject, content
示例#19
0
文件: github.py 项目: galexrt/zulip
def api_github_v2(
    user_profile, event, payload, branches, default_stream, commit_stream, issue_stream, topic_focus=None
):
    # type: (UserProfile, text_type, Mapping[text_type, Any], text_type, text_type, text_type, text_type, Optional[text_type]) -> Tuple[text_type, text_type, text_type]
    """
    processes github payload with version 2 field specification
    `payload` comes in unmodified from github
    `default_stream` is set to what `stream` is in v1 above
    `commit_stream` and `issue_stream` fall back to `default_stream` if they are empty
    This and allowing alternative endpoints is what distinguishes v1 from v2 of the github configuration
    """
    target_stream = commit_stream if commit_stream else default_stream
    issue_stream = issue_stream if issue_stream else default_stream
    repository = payload["repository"]
    topic_focus = topic_focus if topic_focus else repository["name"]

    # Event Handlers
    if event == "pull_request":
        subject = get_pull_request_or_issue_subject(repository, payload["pull_request"], "PR")
        content = github_pull_request_content(payload)
    elif event == "issues":
        # in v1, we assume that this stream exists since it is
        # deprecated and the few realms that use it already have the
        # stream
        target_stream = issue_stream
        subject = get_pull_request_or_issue_subject(repository, payload["issue"], "Issue")
        content = github_issues_content(payload)
    elif event == "issue_comment":
        # Comments on both issues and pull requests come in as issue_comment events
        issue = payload["issue"]
        if "pull_request" not in issue or issue["pull_request"]["diff_url"] is None:
            # It's an issues comment
            target_stream = issue_stream
            type = "Issue"
            subject = get_pull_request_or_issue_subject(repository, payload["issue"], type)
        else:
            # It's a pull request comment
            type = "PR"
            subject = get_pull_request_or_issue_subject(repository, payload["issue"], type)

        content = github_object_commented_content(payload, type)

    elif event == "push":
        subject, content = build_message_from_gitlog(
            user_profile,
            topic_focus,
            payload["ref"],
            payload["commits"],
            payload["before"],
            payload["after"],
            payload["compare"],
            payload["pusher"]["name"],
            forced=payload["forced"],
            created=payload["created"],
        )
    elif event == "commit_comment":
        subject = topic_focus

        comment = payload.get("comment")
        action = u"[commented]({})".format(comment["html_url"])
        content = get_commits_comment_action_message(
            comment["user"]["login"],
            action,
            comment["html_url"].split("#", 1)[0],
            comment["commit_id"],
            comment["body"],
        )

    else:
        raise UnknownEventType(force_str(u"Event %s is unknown and cannot be handled" % (event,)))

    return target_stream, subject, content
示例#20
0
def api_github_v2(user_profile: UserProfile,
                  event: str,
                  payload: Mapping[str, Any],
                  branches: str,
                  default_stream: str,
                  commit_stream: str,
                  issue_stream: str,
                  topic_focus: Optional[str] = None) -> Tuple[str, str, str]:
    """
    processes github payload with version 2 field specification
    `payload` comes in unmodified from github
    `default_stream` is set to what `stream` is in v1 above
    `commit_stream` and `issue_stream` fall back to `default_stream` if they are empty
    This and allowing alternative endpoints is what distinguishes v1 from v2 of the github configuration
    """
    target_stream = commit_stream if commit_stream else default_stream
    issue_stream = issue_stream if issue_stream else default_stream
    repository = payload['repository']
    updated_topic_focus = topic_focus if topic_focus else repository['name']

    # Event Handlers
    if event == 'pull_request':
        subject = get_pull_request_or_issue_subject(repository,
                                                    payload['pull_request'],
                                                    'PR')
        content = github_pull_request_content(payload)
    elif event == 'issues':
        # in v1, we assume that this stream exists since it is
        # deprecated and the few realms that use it already have the
        # stream
        target_stream = issue_stream
        subject = get_pull_request_or_issue_subject(repository,
                                                    payload['issue'], 'Issue')
        content = github_issues_content(payload)
    elif event == 'issue_comment':
        # Comments on both issues and pull requests come in as issue_comment events
        issue = payload['issue']
        if 'pull_request' not in issue or issue['pull_request'][
                'diff_url'] is None:
            # It's an issues comment
            target_stream = issue_stream
            type = 'Issue'
            subject = get_pull_request_or_issue_subject(
                repository, payload['issue'], type)
        else:
            # It's a pull request comment
            type = 'PR'
            subject = get_pull_request_or_issue_subject(
                repository, payload['issue'], type)

        content = github_object_commented_content(payload, type)

    elif event == 'push':
        subject, content = build_message_from_gitlog(
            user_profile,
            updated_topic_focus,
            payload['ref'],
            payload['commits'],
            payload['before'],
            payload['after'],
            payload['compare'],
            payload['pusher']['name'],
            forced=payload['forced'],
            created=payload['created'],
            deleted=payload['deleted'])
    elif event == 'commit_comment':
        subject = updated_topic_focus

        comment = payload['comment']
        action = u'[commented]({})'.format(comment['html_url'])
        content = get_commits_comment_action_message(
            comment['user']['login'],
            action,
            comment['html_url'].split('#', 1)[0],
            comment['commit_id'],
            comment['body'],
        )

    else:
        raise UnknownEventType(u'Event %s is unknown and cannot be handled' %
                               (event, ))

    return target_stream, subject, content