

@authenticated_api_view
@has_request_variables
def api_github_landing(request, user_profile, event=REQ, payload=REQ(validator=check_dict([])), branches=REQ(default=''), stream=REQ(default=''), version=REQ(converter=to_non_negative_int, default=1), commit_stream=REQ(default=''), issue_stream=REQ(default=''), exclude_pull_requests=REQ(converter=flexible_boolean, default=False), exclude_issues=REQ(converter=flexible_boolean, default=False), exclude_commits=REQ(converter=flexible_boolean, default=False), emphasize_branch_in_topic=REQ(converter=flexible_boolean, default=False)):
    repository = payload['repository']
    try:
        if (is_test_repository(repository) and settings.PRODUCTION):
            with open('/var/log/zulip/github-payloads', 'a') as f:
                f.write(ujson.dumps({
                    'event': event,
                    'payload': payload,
                    'branches': branches,
                    'stream': stream,
                    'version': version,
                    'commit_stream': commit_stream,
                    'issue_stream': issue_stream,
                    'exclude_pull_requests': exclude_pull_requests,
                    'exclude_issues': exclude_issues,
                    'exclude_commits': exclude_commits,
                    'emphasize_branch_in_topic': emphasize_branch_in_topic,
                }))
                f.write('\n')
    except Exception:
        logging.exception('Error while capturing Github event')
    if (not stream):
        stream = 'commits'
    short_ref = re.sub('^refs/heads/', '', payload.get('ref', ''))
    kwargs = dict()
    if (emphasize_branch_in_topic and short_ref):
        kwargs['topic_focus'] = short_ref
    allowed_events = set()
    if (not exclude_pull_requests):
        allowed_events.add('pull_request')
    if (not exclude_issues):
        allowed_events.add('issues')
        allowed_events.add('issue_comment')
    if (not exclude_commits):
        allowed_events.add('push')
        allowed_events.add('commit_comment')
    if (event not in allowed_events):
        return json_success()
    if ((event == 'issue_comment') and (payload['action'] != 'created')):
        return json_success()
    if (event == 'push'):
        if (branches and (short_ref not in re.split('[\\s,;|]+', branches))):
            return json_success()
    if (version == 2):
        (target_stream, subject, content) = api_github_v2(user_profile, event, payload, branches, stream, commit_stream, issue_stream, **kwargs)
    else:
        (target_stream, subject, content) = api_github_v1(user_profile, event, payload, branches, stream, **kwargs)
    request.client = get_client('ZulipGitHubWebhook')
    return send_message_backend(request, user_profile, message_type_name='stream', message_to=[target_stream], forged=False, subject_name=subject, message_content=content)

dataset/ETHPy150Open zulip/zulip/zerver/views/webhooks/github.py api_github_landing/original