Esempio n. 1
0
def build_message_from_gitlog(
        user_profile: UserProfile,
        name: str,
        ref: str,
        commits: List[Dict[str, str]],
        before: str,
        after: str,
        url: str,
        pusher: str,
        forced: Optional[str] = None,
        created: Optional[str] = None,
        deleted: Optional[bool] = False) -> Tuple[str, str]:
    short_ref = re.sub(r'^refs/heads/', '', ref)
    subject = SUBJECT_WITH_BRANCH_TEMPLATE.format(repo=name, branch=short_ref)

    if re.match(r'^0+$', after):
        content = get_remove_branch_event_message(pusher, short_ref)
    # 'created' and 'forced' are github flags; the second check is for beanstalk
    elif (forced and not created) or (forced is None and len(commits) == 0):
        content = get_force_push_commits_event_message(pusher, url, short_ref,
                                                       after[:7])
    else:
        commits = _transform_commits_list_to_common_format(commits)
        try:
            content = get_push_commits_event_message(pusher,
                                                     url,
                                                     short_ref,
                                                     commits,
                                                     deleted=deleted)
        except TypeError:  # nocoverage This error condition seems to
            # be caused by a change in GitHub's APIs.  Since we've
            # deprecated this webhook, just suppress them with a 40x error.
            raise JsonableError("Malformed commit data")

    return subject, content
Esempio n. 2
0
def build_message_from_gitlog(user_profile,
                              name,
                              ref,
                              commits,
                              before,
                              after,
                              url,
                              pusher,
                              forced=None,
                              created=None,
                              deleted=False):
    # type: (UserProfile, Text, Text, List[Dict[str, str]], Text, Text, Text, Text, Optional[Text], Optional[Text], Optional[bool]) -> Tuple[Text, Text]
    short_ref = re.sub(r'^refs/heads/', '', ref)
    subject = SUBJECT_WITH_BRANCH_TEMPLATE.format(repo=name, branch=short_ref)

    if re.match(r'^0+$', after):
        content = get_remove_branch_event_message(pusher, short_ref)
    # 'created' and 'forced' are github flags; the second check is for beanstalk
    elif (forced and not created) or (forced is None and len(commits) == 0):
        content = get_force_push_commits_event_message(pusher, url, short_ref,
                                                       after[:7])
    else:
        commits = _transform_commits_list_to_common_format(commits)
        content = get_push_commits_event_message(pusher,
                                                 url,
                                                 short_ref,
                                                 commits,
                                                 deleted=deleted)

    return subject, content
Esempio n. 3
0
def api_bitbucket_webhook(request,
                          user_profile,
                          payload=REQ(validator=check_dict([])),
                          stream=REQ(default='commits')):
    # type: (HttpRequest, UserProfile, Mapping[text_type, Any], text_type) -> 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()
Esempio n. 4
0
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()
Esempio n. 5
0
def api_bitbucket_webhook(request: HttpRequest, user_profile: UserProfile,
                          payload: Mapping[str, Any]=REQ(validator=check_dict([])),
                          branches: Optional[str]=REQ(default=None)) -> HttpResponse:
    repository = payload['repository']

    commits = [
        {
            'name': payload.get('user'),
            '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['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']
        if branches is not None and branches.find(branch) == -1:
            return json_success()
        content = get_push_commits_event_message(payload['user'], None, branch, commits)
        subject = SUBJECT_WITH_BRANCH_TEMPLATE.format(repo=repository['name'], branch=branch)

    check_send_webhook_message(request, user_profile, subject, content)
    return json_success()
Esempio n. 6
0
def get_push_commits_body(payload):
    # type: (Dict[str, Any]) -> Text
    commits_data = [{
        'sha': commit['id'],
        'url': commit['url'],
        'message': commit['message']
    } for commit in payload['commits']]
    return get_push_commits_event_message(
        get_sender_name(payload), payload['compare'],
        get_branch_name_from_ref(payload['ref']), commits_data)
Esempio n. 7
0
def get_normal_push_body(payload, change):
    # type: (Dict[str, Any], Dict[str, Any]) -> text_type
    commits_data = [{
        'sha': commit.get('hash'),
        'url': commit.get('links').get('html').get('href'),
        'message': commit.get('message'),
    } for commit in change['commits']]

    return get_push_commits_event_message(get_user_username(payload),
                                          change['links']['html']['href'],
                                          change['new']['name'], commits_data)
Esempio n. 8
0
def format_push_event(payload: WildValue) -> str:
    user_name = payload["sender"]["username"].tame(check_string)
    compare_url = payload["compare_url"].tame(check_string)
    branch_name = payload["ref"].tame(check_string).replace("refs/heads/", "")
    commits_data = _transform_commits_list_to_common_format(payload["commits"])
    return get_push_commits_event_message(
        user_name=user_name,
        compare_url=compare_url,
        branch_name=branch_name,
        commits_data=commits_data,
    )
Esempio n. 9
0
def build_message_from_gitlog(user_profile: UserProfile, name: str, ref: str,
                              commits: List[Dict[str, str]], before: str, after: str,
                              url: str, pusher: str, forced: Optional[str]=None,
                              created: Optional[str]=None, deleted: bool=False,
                              ) -> Tuple[str, str]:
    short_ref = re.sub(r'^refs/heads/', '', ref)
    subject = TOPIC_WITH_BRANCH_TEMPLATE.format(repo=name, branch=short_ref)

    commits = _transform_commits_list_to_common_format(commits)
    content = get_push_commits_event_message(pusher, url, short_ref, commits, deleted=deleted)

    return subject, content
Esempio n. 10
0
def get_normal_push_event_body(payload: Dict[str, Any]) -> str:
    compare_url = u'{}/compare/{}...{}'.format(
        get_repository_homepage(payload), payload['before'], payload['after'])

    commits = [{
        'name': commit.get('author').get('name'),
        'sha': commit.get('id'),
        'message': commit.get('message'),
        'url': commit.get('url')
    } for commit in payload['commits']]

    return get_push_commits_event_message(get_user_name(payload), compare_url,
                                          get_branch_name(payload), commits)
Esempio n. 11
0
def get_push_commits_body(payload):
    # type: (Dict[str, Any]) -> Text
    commits_data = [{
        'sha': commit['id'],
        'url': commit['url'],
        'message': commit['message']
    } for commit in payload['commits']]
    return get_push_commits_event_message(
        get_sender_name(payload),
        payload['compare'],
        get_branch_name_from_ref(payload['ref']),
        commits_data
    )
Esempio n. 12
0
def get_normal_push_body(payload, change):
    # type: (Dict[str, Any], Dict[str, Any]) -> text_type
    commits_data = [{
        'sha': commit.get('hash'),
        'url': commit.get('links').get('html').get('href'),
        'message': commit.get('message'),
    } for commit in change['commits']]

    return get_push_commits_event_message(
        get_user_username(payload),
        change['links']['html']['href'],
        change['new']['name'],
        commits_data
    )
Esempio n. 13
0
def get_normal_push_body(payload, change):
    # type: (Dict[str, Any], Dict[str, Any]) -> Text
    commits_data = [{
        'name': commit.get('author').get('raw').split()[0],
        'sha': commit.get('hash'),
        'url': commit.get('links').get('html').get('href'),
        'message': commit.get('message'),
    } for commit in change['commits']]

    return get_push_commits_event_message(get_user_username(payload),
                                          change['links']['html']['href'],
                                          change['new']['name'],
                                          commits_data,
                                          is_truncated=change['truncated'])
Esempio n. 14
0
def get_normal_push_body(payload: Dict[str, Any], change: Dict[str,
                                                               Any]) -> str:
    commits_data = [{
        'name': get_commit_author_name(commit),
        'sha': commit.get('hash'),
        'url': commit.get('links').get('html').get('href'),
        'message': commit.get('message'),
    } for commit in change['commits']]

    return get_push_commits_event_message(get_user_username(payload),
                                          change['links']['html']['href'],
                                          change['new']['name'],
                                          commits_data,
                                          is_truncated=change['truncated'])
Esempio n. 15
0
def format_push_event(payload: Dict[str, Any]) -> str:

    for commit in payload["commits"]:
        commit["sha"] = commit["id"]
        commit["name"] = commit["author"]["username"] or commit["author"]["name"].split()[0]

    data = {
        "user_name": payload["sender"]["username"],
        "compare_url": payload["compare_url"],
        "branch_name": payload["ref"].replace("refs/heads/", ""),
        "commits_data": payload["commits"],
    }

    return get_push_commits_event_message(**data)
Esempio n. 16
0
def format_push_event(payload):
    # type: (Dict[str, Any]) -> Text

    for commit in payload['commits']:
        commit['sha'] = commit['id']

    data = {
        'user_name': payload['sender']['username'],
        'compare_url': payload['compare_url'],
        'branch_name': payload['ref'].replace('refs/heads/', ''),
        'commits_data': payload['commits']
    }

    return get_push_commits_event_message(**data)
Esempio n. 17
0
def format_push_event(payload):
    # type: (Dict[str, Any]) -> Text

    for commit in payload['commits']:
        commit['sha'] = commit['id']

    data = {
        'user_name': payload['sender']['username'],
        'compare_url': payload['compare_url'],
        'branch_name': payload['ref'].replace('refs/heads/', ''),
        'commits_data': payload['commits']
    }

    return get_push_commits_event_message(**data)
Esempio n. 18
0
def format_push_event(payload: Dict[str, Any]) -> Text:

    for commit in payload['commits']:
        commit['sha'] = commit['id']
        commit['name'] = (commit['author']['username'] or
                          commit['author']['name'].split()[0])

    data = {
        'user_name': payload['sender']['username'],
        'compare_url': payload['compare_url'],
        'branch_name': payload['ref'].replace('refs/heads/', ''),
        'commits_data': payload['commits']
    }

    return get_push_commits_event_message(**data)
Esempio n. 19
0
def get_push_commits_body(payload: Dict[str, Any]) -> Text:
    commits_data = [{
        'name': (commit.get('author').get('username') or
                 commit.get('author').get('name')),
        'sha': commit['id'],
        'url': commit['url'],
        'message': commit['message']
    } for commit in payload['commits']]
    return get_push_commits_event_message(
        get_sender_name(payload),
        payload['compare'],
        get_branch_name_from_ref(payload['ref']),
        commits_data,
        deleted=payload['deleted']
    )
Esempio n. 20
0
def build_message_from_gitlog(user_profile, name, ref, commits, before, after, url, pusher, forced=None, created=None):
    # type: (UserProfile, text_type, text_type, List[Dict[str, str]], text_type, text_type, text_type, text_type, Optional[text_type], Optional[text_type]) -> Tuple[text_type, text_type]
    short_ref = re.sub(r"^refs/heads/", "", ref)
    subject = SUBJECT_WITH_BRANCH_TEMPLATE.format(repo=name, branch=short_ref)

    if re.match(r"^0+$", after):
        content = get_remove_branch_event_message(pusher, short_ref)
    # 'created' and 'forced' are github flags; the second check is for beanstalk
    elif (forced and not created) or (forced is None and len(commits) == 0):
        content = get_force_push_commits_event_message(pusher, url, short_ref, after[:7])
    else:
        commits = _transform_commits_list_to_common_format(commits)
        content = get_push_commits_event_message(pusher, url, short_ref, commits)

    return subject, content
Esempio n. 21
0
def format_push_event(payload: Dict[str, Any]) -> str:

    for commit in payload['commits']:
        commit['sha'] = commit['id']
        commit['name'] = (commit['author']['username'] or
                          commit['author']['name'].split()[0])

    data = {
        'user_name': payload['sender']['username'],
        'compare_url': payload['compare_url'],
        'branch_name': payload['ref'].replace('refs/heads/', ''),
        'commits_data': payload['commits']
    }

    return get_push_commits_event_message(**data)
Esempio n. 22
0
def get_normal_push_body(payload: WildValue, change: WildValue) -> str:
    commits_data = [{
        "name": get_commit_author_name(commit),
        "sha": commit["hash"].tame(check_string),
        "url": commit["links"]["html"]["href"].tame(check_string),
        "message": commit["message"].tame(check_string),
    } for commit in change["commits"]]

    return get_push_commits_event_message(
        get_actor_info(payload),
        change["links"]["html"]["href"].tame(check_string),
        change["new"]["name"].tame(check_string),
        commits_data,
        is_truncated=change["truncated"].tame(check_bool),
    )
Esempio n. 23
0
def get_normal_push_body(payload: Dict[str, Any], change: Dict[str, Any]) -> Text:
    commits_data = [{
        'name': get_commit_author_name(commit),
        'sha': commit.get('hash'),
        'url': commit.get('links').get('html').get('href'),
        'message': commit.get('message'),
    } for commit in change['commits']]

    return get_push_commits_event_message(
        get_user_username(payload),
        change['links']['html']['href'],
        change['new']['name'],
        commits_data,
        is_truncated=change['truncated']
    )
Esempio n. 24
0
def get_push_commits_body(payload: Dict[str, Any]) -> Text:
    commits_data = [{
        'name': (commit.get('author').get('username') or
                 commit.get('author').get('name')),
        'sha': commit['id'],
        'url': commit['url'],
        'message': commit['message']
    } for commit in payload['commits']]
    return get_push_commits_event_message(
        get_sender_name(payload),
        payload['compare'],
        get_branch_name_from_ref(payload['ref']),
        commits_data,
        deleted=payload['deleted']
    )
Esempio n. 25
0
def get_push_commits_body(helper: Helper) -> str:
    payload = helper.payload
    commits_data = [{
        'name': (commit.get('author').get('username') or
                 commit.get('author').get('name')),
        'sha': commit['id'],
        'url': commit['url'],
        'message': commit['message'],
    } for commit in payload['commits']]
    return get_push_commits_event_message(
        get_sender_name(payload),
        payload['compare'],
        get_branch_name_from_ref(payload['ref']),
        commits_data,
        deleted=payload['deleted'],
    )
Esempio n. 26
0
File: view.py Progetto: buyrs/demozy
def get_normal_push_body(payload: Dict[str, Any], change: Dict[str,
                                                               Any]) -> str:
    commits_data = [{
        "name": get_commit_author_name(commit),
        "sha": commit.get("hash"),
        "url": commit.get("links").get("html").get("href"),
        "message": commit.get("message"),
    } for commit in change["commits"]]

    return get_push_commits_event_message(
        get_actor_info(payload),
        change["links"]["html"]["href"],
        change["new"]["name"],
        commits_data,
        is_truncated=change["truncated"],
    )
Esempio n. 27
0
def api_bitbucket_webhook(
    request: HttpRequest,
    user_profile: UserProfile,
    payload: Mapping[str, Any] = REQ(validator=check_dict([])),
    branches: Optional[str] = REQ(default=None)
) -> HttpResponse:
    repository = payload['repository']

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

    if len(commits) == 0:
        # Bitbucket doesn't give us enough information to really give
        # a useful message :/
        subject = repository['name']
        content = "{} [force pushed]({}).".format(
            payload.get('user', 'Someone'),
            payload['canon_url'] + repository['absolute_url'],
        )
    else:
        branch = payload['commits'][-1]['branch']
        if branches is not None and branches.find(branch) == -1:
            return json_success()

        committer = payload.get('user')
        content = get_push_commits_event_message(
            committer if committer is not None else 'Someone', None, branch,
            commits)
        subject = TOPIC_WITH_BRANCH_TEMPLATE.format(repo=repository['name'],
                                                    branch=branch)

    check_send_webhook_message(request,
                               user_profile,
                               subject,
                               content,
                               unquote_url_parameters=True)
    return json_success()
Esempio n. 28
0
def api_bitbucket_webhook(
        request: HttpRequest,
        user_profile: UserProfile,
        payload: Mapping[str, Any] = REQ(json_validator=check_dict([])),
        branches: Optional[str] = REQ(default=None),
) -> HttpResponse:
    repository = payload["repository"]

    commits = [{
        "name":
        commit.get("author") or payload.get("user"),
        "sha":
        commit.get("raw_node"),
        "message":
        commit.get("message"),
        "url":
        "{}{}commits/{}".format(payload.get("canon_url"),
                                repository.get("absolute_url"),
                                commit.get("raw_node")),
    } for commit in payload["commits"]]

    if len(commits) == 0:
        # Bitbucket doesn't give us enough information to really give
        # a useful message :/
        subject = repository["name"]
        content = "{} [force pushed]({}).".format(
            payload.get("user", "Someone"),
            payload["canon_url"] + repository["absolute_url"],
        )
    else:
        branch = payload["commits"][-1]["branch"]
        if branches is not None and branches.find(branch) == -1:
            return json_success()

        committer = payload.get("user")
        content = get_push_commits_event_message(
            committer if committer is not None else "Someone", None, branch,
            commits)
        subject = TOPIC_WITH_BRANCH_TEMPLATE.format(repo=repository["name"],
                                                    branch=branch)

    check_send_webhook_message(request,
                               user_profile,
                               subject,
                               content,
                               unquote_url_parameters=True)
    return json_success()
Esempio n. 29
0
def api_bitbucket_webhook(
    request: HttpRequest,
    user_profile: UserProfile,
    payload: WildValue = REQ(converter=to_wild_value),
    branches: Optional[str] = REQ(default=None),
) -> HttpResponse:
    repository = payload["repository"]

    commits = [
        {
            "name": commit["author"].tame(check_string)
            if "author" in commit
            else payload.get("user", "Someone").tame(check_string),
            "sha": commit["raw_node"].tame(check_string),
            "message": commit["message"].tame(check_string),
            "url": "{}{}commits/{}".format(
                payload["canon_url"].tame(check_string),
                repository["absolute_url"].tame(check_string),
                commit["raw_node"].tame(check_string),
            ),
        }
        for commit in payload["commits"]
    ]

    if len(commits) == 0:
        # Bitbucket doesn't give us enough information to really give
        # a useful message :/
        subject = repository["name"].tame(check_string)
        content = "{} [force pushed]({}).".format(
            payload.get("user", "Someone").tame(check_string),
            payload["canon_url"].tame(check_string) + repository["absolute_url"].tame(check_string),
        )
    else:
        branch = payload["commits"][-1]["branch"].tame(check_string)
        if branches is not None and branches.find(branch) == -1:
            return json_success(request)

        committer = payload.get("user", "Someone").tame(check_string)
        content = get_push_commits_event_message(committer, None, branch, commits)
        subject = TOPIC_WITH_BRANCH_TEMPLATE.format(
            repo=repository["name"].tame(check_string), branch=branch
        )

    check_send_webhook_message(request, user_profile, subject, content, unquote_url_parameters=True)
    return json_success(request)
Esempio n. 30
0
def get_push_commits_body(helper: Helper) -> str:
    payload = helper.payload
    commits_data = [
        {
            "name": (commit.get("author").get("username") or commit.get("author").get("name")),
            "sha": commit["id"],
            "url": commit["url"],
            "message": commit["message"],
        }
        for commit in payload["commits"]
    ]
    return get_push_commits_event_message(
        get_sender_name(payload),
        payload["compare"],
        get_branch_name_from_ref(payload["ref"]),
        commits_data,
        deleted=payload["deleted"],
    )
Esempio n. 31
0
def build_message_from_gitlog(user_profile: UserProfile, name: Text, ref: Text,
                              commits: List[Dict[str, str]], before: Text, after: Text,
                              url: Text, pusher: Text, forced: Optional[Text]=None,
                              created: Optional[Text]=None, deleted: Optional[bool]=False
                              ) -> Tuple[Text, Text]:
    short_ref = re.sub(r'^refs/heads/', '', ref)
    subject = SUBJECT_WITH_BRANCH_TEMPLATE.format(repo=name, branch=short_ref)

    if re.match(r'^0+$', after):
        content = get_remove_branch_event_message(pusher, short_ref)
    # 'created' and 'forced' are github flags; the second check is for beanstalk
    elif (forced and not created) or (forced is None and len(commits) == 0):
        content = get_force_push_commits_event_message(pusher, url, short_ref, after[:7])
    else:
        commits = _transform_commits_list_to_common_format(commits)
        content = get_push_commits_event_message(pusher, url, short_ref, commits, deleted=deleted)

    return subject, content
Esempio n. 32
0
def api_bitbucket_webhook(
    request: HttpRequest,
    user_profile: UserProfile,
    payload: Mapping[Text, Any] = REQ(validator=check_dict([])),
    stream: Text = REQ(default='commits'),
    branches: Optional[Text] = REQ(default=None)
) -> HttpResponse:
    repository = payload['repository']

    commits = [{
        'name':
        payload.get('user'),
        '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['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']
        if branches is not None and branches.find(branch) == -1:
            return json_success()
        content = get_push_commits_event_message(payload['user'], None, branch,
                                                 commits)
        subject = SUBJECT_WITH_BRANCH_TEMPLATE.format(repo=repository['name'],
                                                      branch=branch)

    check_send_stream_message(user_profile,
                              get_client("ZulipBitBucketWebhook"), stream,
                              subject, content)
    return json_success()
Esempio n. 33
0
def get_normal_push_event_body(payload: WildValue) -> str:
    compare_url = "{}/compare/{}...{}".format(
        get_project_homepage(payload),
        payload["before"].tame(check_string),
        payload["after"].tame(check_string),
    )

    commits = [{
        "name": commit["author"]["name"].tame(check_string),
        "sha": commit["id"].tame(check_string),
        "message": commit["message"].tame(check_string),
        "url": commit["url"].tame(check_string),
    } for commit in payload["commits"]]

    return get_push_commits_event_message(
        get_user_name(payload),
        compare_url,
        get_branch_name(payload),
        commits,
    )
Esempio n. 34
0
def get_normal_push_event_body(payload: Dict[str, Any]) -> str:
    compare_url = "{}/compare/{}...{}".format(
        get_project_homepage(payload),
        payload["before"],
        payload["after"],
    )

    commits = [{
        "name": commit.get("author").get("name"),
        "sha": commit.get("id"),
        "message": commit.get("message"),
        "url": commit.get("url"),
    } for commit in payload["commits"]]

    return get_push_commits_event_message(
        get_user_name(payload),
        compare_url,
        get_branch_name(payload),
        commits,
    )
Esempio n. 35
0
def get_push_commits_body(helper: Helper) -> str:
    payload = helper.payload
    commits_data = []
    for commit in payload["commits"]:
        if commit["author"].get("username"):
            name = commit["author"]["username"].tame(check_string)
        else:
            name = commit["author"]["name"].tame(check_string)
        commits_data.append({
            "name": name,
            "sha": commit["id"].tame(check_string),
            "url": commit["url"].tame(check_string),
            "message": commit["message"].tame(check_string),
        })
    return get_push_commits_event_message(
        get_sender_name(payload),
        payload["compare"].tame(check_string),
        get_branch_name_from_ref(payload["ref"].tame(check_string)),
        commits_data,
        deleted=payload["deleted"].tame(check_bool),
    )
Esempio n. 36
0
def get_normal_push_event_body(payload):
    # type: (Dict[str, Any]) -> text_type
    compare_url = u'{}/compare/{}...{}'.format(
        get_repository_homepage(payload),
        payload['before'],
        payload['after']
    )

    commits = [
        {
            'sha': commit.get('id'),
            'message': commit.get('message'),
            'url': commit.get('url')
        }
        for commit in payload.get('commits')
    ]

    return get_push_commits_event_message(
        get_user_name(payload),
        compare_url,
        get_branch_name(payload),
        commits
    )
Esempio n. 37
0
def build_message_from_gitlog(user_profile: UserProfile, name: str, ref: str,
                              commits: List[Dict[str, str]], before: str, after: str,
                              url: str, pusher: str, forced: Optional[str]=None,
                              created: Optional[str]=None, deleted: Optional[bool]=False
                              ) -> Tuple[str, str]:
    short_ref = re.sub(r'^refs/heads/', '', ref)
    subject = TOPIC_WITH_BRANCH_TEMPLATE.format(repo=name, branch=short_ref)

    if re.match(r'^0+$', after):
        content = get_remove_branch_event_message(pusher, short_ref)
    # 'created' and 'forced' are github flags; the second check is for beanstalk
    elif (forced and not created) or (forced is None and len(commits) == 0):
        content = get_force_push_commits_event_message(pusher, url, short_ref, after[:7])
    else:
        commits = _transform_commits_list_to_common_format(commits)
        try:
            content = get_push_commits_event_message(pusher, url, short_ref, commits, deleted=deleted)
        except TypeError:  # nocoverage This error condition seems to
            # be caused by a change in GitHub's APIs.  Since we've
            # deprecated this webhook, just suppress them with a 40x error.
            raise JsonableError(
                "Malformed commit data")

    return subject, content