mirror of https://github.com/zulip/zulip.git
Annotate zerver/views/webhooks/github.py.
This commit is contained in:
parent
85cb3e6103
commit
1169329a71
|
@ -1,6 +1,6 @@
|
|||
from __future__ import absolute_import
|
||||
from django.conf import settings
|
||||
from zerver.models import get_client
|
||||
from zerver.models import get_client, UserProfile
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.validator import check_dict
|
||||
from zerver.decorator import authenticated_api_view, REQ, has_request_variables, to_non_negative_int, flexible_boolean
|
||||
|
@ -9,13 +9,17 @@ import logging
|
|||
import re
|
||||
import ujson
|
||||
|
||||
from six import text_type
|
||||
from typing import Any, Mapping, Optional, Sequence, Tuple
|
||||
from zerver.lib.str_utils import force_str
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
COMMITS_IN_LIST_LIMIT = 10
|
||||
ZULIP_TEST_REPO_NAME = 'zulip-test'
|
||||
ZULIP_TEST_REPO_ID = 6893087
|
||||
|
||||
def is_test_repository(repository):
|
||||
# type: (Mapping[text_type, Any]) -> bool
|
||||
return repository['name'] == ZULIP_TEST_REPO_NAME and repository['id'] == ZULIP_TEST_REPO_ID
|
||||
|
||||
class UnknownEventType(Exception):
|
||||
|
@ -23,10 +27,12 @@ class UnknownEventType(Exception):
|
|||
|
||||
|
||||
def github_generic_subject(noun, topic_focus, blob):
|
||||
# type: (text_type, text_type, Mapping[text_type, Any]) -> text_type
|
||||
# issue and pull_request objects have the same fields we're interested in
|
||||
return u'%s: %s %d: %s' % (topic_focus, noun, blob['number'], blob['title'])
|
||||
|
||||
def github_generic_content(noun, payload, blob):
|
||||
# type: (text_type, Mapping[text_type, Any], Mapping[text_type, Any]) -> text_type
|
||||
action = 'synchronized' if payload['action'] == 'synchronize' else payload['action']
|
||||
|
||||
# issue and pull_request objects have the same fields we're interested in
|
||||
|
@ -42,6 +48,7 @@ def github_generic_content(noun, payload, blob):
|
|||
|
||||
|
||||
def api_github_v1(user_profile, event, payload, branches, stream, **kwargs):
|
||||
# type: (UserProfile, text_type, Mapping[text_type, Any], text_type, text_type, **Any) -> Tuple[text_type, text_type, text_type]
|
||||
"""
|
||||
processes github payload with version 1 field specification
|
||||
`payload` comes in unmodified from github
|
||||
|
@ -53,6 +60,7 @@ def api_github_v1(user_profile, event, payload, branches, stream, **kwargs):
|
|||
|
||||
|
||||
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
|
||||
|
@ -138,6 +146,7 @@ def api_github_landing(request, user_profile, event=REQ(),
|
|||
exclude_commits=REQ(converter=flexible_boolean, default=False),
|
||||
emphasize_branch_in_topic=REQ(converter=flexible_boolean, default=False),
|
||||
):
|
||||
# type: (HttpRequest, UserProfile, text_type, Mapping[text_type, Any], text_type, text_type, int, text_type, text_type, bool, bool, bool, bool) -> HttpResponse
|
||||
|
||||
repository = payload['repository']
|
||||
|
||||
|
@ -209,6 +218,7 @@ def api_github_landing(request, user_profile, event=REQ(),
|
|||
message_content=content)
|
||||
|
||||
def build_commit_list_content(commits, branch, compare_url, pusher):
|
||||
# type: (Sequence[Mapping[text_type, Any]], text_type, Optional[text_type], text_type) -> text_type
|
||||
if compare_url is not None:
|
||||
push_text = u'[pushed](%s)' % (compare_url,)
|
||||
else:
|
||||
|
@ -231,6 +241,7 @@ def build_commit_list_content(commits, branch, compare_url, pusher):
|
|||
return content
|
||||
|
||||
def build_message_from_gitlog(user_profile, name, ref, commits, before, after, url, pusher, forced=None, created=None):
|
||||
# type: (UserProfile, text_type, text_type, Sequence[Mapping[text_type, Any]], 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 = name
|
||||
|
||||
|
|
Loading…
Reference in New Issue