本文整理匯總了Python中zerver.lib.webhooks.git.SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE類的典型用法代碼示例。如果您正苦於以下問題:Python SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE類的具體用法?Python SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE怎麽用?Python SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_subject_based_on_event
def get_subject_based_on_event(event, payload):
# type: (str, Dict[str, Any]) -> text_type
if event == 'Push Hook':
return u"{} / {}".format(get_repo_name(payload), get_branch_name(payload))
elif event == 'Build Hook':
return u"{} / {}".format(payload.get('repository').get('name'), get_branch_name(payload))
elif event == 'Pipeline Hook':
return u"{} / {}".format(
get_repo_name(payload),
payload.get('object_attributes').get('ref').replace('refs/heads/', ''))
elif event.startswith('Merge Request Hook'):
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
repo=get_repo_name(payload),
type='MR',
id=payload.get('object_attributes').get('iid'),
title=payload.get('object_attributes').get('title')
)
elif event.startswith('Issue Hook'):
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
repo=get_repo_name(payload),
type='Issue',
id=payload.get('object_attributes').get('iid'),
title=payload.get('object_attributes').get('title')
)
return get_repo_name(payload)
示例2: get_subject_based_on_type
def get_subject_based_on_type(payload, event):
# type: (Dict[str, Any], Text) -> Text
if 'pull_request' in event:
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
repo=get_repository_name(payload),
type='PR',
id=payload['pull_request']['number'],
title=payload['pull_request']['title']
)
elif event.startswith('issue'):
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
repo=get_repository_name(payload),
type='Issue',
id=payload['issue']['number'],
title=payload['issue']['title']
)
elif event.startswith('deployment'):
return u"{} / Deployment on {}".format(
get_repository_name(payload),
payload['deployment']['environment']
)
elif event == 'membership':
return u"{} organization".format(payload['organization']['login'])
elif event == 'push_commits':
return SUBJECT_WITH_BRANCH_TEMPLATE.format(
repo=get_repository_name(payload),
branch=get_branch_name_from_ref(payload['ref'])
)
elif event == 'gollum':
return SUBJECT_WITH_BRANCH_TEMPLATE.format(
repo=get_repository_name(payload),
branch='Wiki Pages'
)
return get_repository_name(payload)
示例3: api_gogs_webhook
def api_gogs_webhook(request: HttpRequest, user_profile: UserProfile,
payload: Dict[str, Any]=REQ(argument_type='body'),
stream: Text=REQ(default='commits'),
branches: Optional[Text]=REQ(default=None)) -> HttpResponse:
repo = payload['repository']['name']
event = request.META['HTTP_X_GOGS_EVENT']
if event == 'push':
branch = payload['ref'].replace('refs/heads/', '')
if branches is not None and branches.find(branch) == -1:
return json_success()
body = format_push_event(payload)
topic = SUBJECT_WITH_BRANCH_TEMPLATE.format(
repo=repo,
branch=branch
)
elif event == 'create':
body = format_new_branch_event(payload)
topic = SUBJECT_WITH_BRANCH_TEMPLATE.format(
repo=repo,
branch=payload['ref']
)
elif event == 'pull_request':
body = format_pull_request_event(payload)
topic = SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
repo=repo,
type='PR',
id=payload['pull_request']['id'],
title=payload['pull_request']['title']
)
else:
return json_error(_('Invalid event "{}" in request headers').format(event))
check_send_stream_message(user_profile, request.client, stream, topic, body)
return json_success()
示例4: api_gogs_webhook
def api_gogs_webhook(request: HttpRequest, user_profile: UserProfile,
payload: Dict[str, Any]=REQ(argument_type='body'),
branches: Optional[str]=REQ(default=None)) -> HttpResponse:
repo = payload['repository']['name']
event = validate_extract_webhook_http_header(request, 'X_GOGS_EVENT', 'Gogs')
if event == 'push':
branch = payload['ref'].replace('refs/heads/', '')
if branches is not None and branches.find(branch) == -1:
return json_success()
body = format_push_event(payload)
topic = SUBJECT_WITH_BRANCH_TEMPLATE.format(
repo=repo,
branch=branch
)
elif event == 'create':
body = format_new_branch_event(payload)
topic = SUBJECT_WITH_BRANCH_TEMPLATE.format(
repo=repo,
branch=payload['ref']
)
elif event == 'pull_request':
body = format_pull_request_event(payload)
topic = SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
repo=repo,
type='PR',
id=payload['pull_request']['id'],
title=payload['pull_request']['title']
)
else:
raise UnexpectedWebhookEventType('Gogs', event)
check_send_webhook_message(request, user_profile, topic, body)
return json_success()
示例5: get_subject_based_on_type
def get_subject_based_on_type(payload: Dict[str, Any], type: str) -> Text:
if type.startswith('pull_request'):
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
repo=get_repository_name(payload['repository']),
type='PR',
id=payload['pullrequest']['id'],
title=payload['pullrequest']['title']
)
if type.startswith('issue'):
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
repo=get_repository_name(payload['repository']),
type='Issue',
id=payload['issue']['id'],
title=payload['issue']['title']
)
return get_subject(payload)
示例6: get_subject_based_on_event
def get_subject_based_on_event(event: str, payload: Dict[str, Any]) -> str:
if event == 'Push Hook':
return u"{} / {}".format(get_repo_name(payload), get_branch_name(payload))
elif event == 'Job Hook' or event == 'Build Hook':
return u"{} / {}".format(payload['repository'].get('name'), get_branch_name(payload))
elif event == 'Pipeline Hook':
return u"{} / {}".format(
get_repo_name(payload),
payload['object_attributes'].get('ref').replace('refs/heads/', ''))
elif event.startswith('Merge Request Hook'):
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
repo=get_repo_name(payload),
type='MR',
id=payload['object_attributes'].get('iid'),
title=payload['object_attributes'].get('title')
)
elif event.startswith('Issue Hook'):
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
repo=get_repo_name(payload),
type='Issue',
id=payload['object_attributes'].get('iid'),
title=payload['object_attributes'].get('title')
)
elif event == 'Note Hook Issue':
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
repo=get_repo_name(payload),
type='Issue',
id=payload['issue'].get('iid'),
title=payload['issue'].get('title')
)
elif event == 'Note Hook MergeRequest':
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
repo=get_repo_name(payload),
type='MR',
id=payload['merge_request'].get('iid'),
title=payload['merge_request'].get('title')
)
elif event == 'Note Hook Snippet':
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
repo=get_repo_name(payload),
type='Snippet',
id=payload['snippet'].get('id'),
title=payload['snippet'].get('title')
)
return get_repo_name(payload)
示例7: get_pull_request_or_issue_subject
def get_pull_request_or_issue_subject(repository, payload_object, type):
# type: (Mapping[text_type, Any], Mapping[text_type, Any], text_type) -> text_type
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
repo=repository['name'],
type=type,
id=payload_object['number'],
title=payload_object['title']
)
示例8: get_pull_request_or_issue_subject
def get_pull_request_or_issue_subject(repository: Mapping[str, Any],
payload_object: Mapping[str, Any],
type: str) -> str:
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
repo=repository['name'],
type=type,
id=payload_object['number'],
title=payload_object['title']
)
示例9: get_subject_based_on_type
def get_subject_based_on_type(payload, type):
# type: (Dict[str, Any], str) -> text_type
if type == 'push':
return get_subject_for_branch_specified_events(payload)
if type.startswith('pull_request'):
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
repo=get_repository_name(payload.get('repository')),
type='PR',
id=payload['pullrequest']['id'],
title=payload['pullrequest']['title']
)
if type.startswith('issue'):
return SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
repo=get_repository_name(payload.get('repository')),
type='Issue',
id=payload['issue']['id'],
title=payload['issue']['title']
)
return get_subject(payload)
示例10: api_gogs_webhook
def api_gogs_webhook(request, user_profile, client,
payload=REQ(argument_type='body'),
stream=REQ(default='commits')):
# type: (HttpRequest, UserProfile, Client, Dict[str, Any], Text) -> HttpResponse
repo = payload['repository']['name']
event = request.META['HTTP_X_GOGS_EVENT']
try:
if event == 'push':
body = format_push_event(payload)
topic = SUBJECT_WITH_BRANCH_TEMPLATE.format(
repo=repo,
branch=payload['ref'].replace('refs/heads/', '')
)
elif event == 'create':
body = format_new_branch_event(payload)
topic = SUBJECT_WITH_BRANCH_TEMPLATE.format(
repo=repo,
branch=payload['ref']
)
elif event == 'pull_request':
body = format_pull_request_event(payload)
topic = SUBJECT_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
repo=repo,
type='PR',
id=payload['pull_request']['id'],
title=payload['pull_request']['title']
)
else:
return json_error(_('Invalid event "{}" in request headers').format(event))
except KeyError as e:
return json_error(_('Missing key {} in JSON').format(str(e)))
check_send_message(user_profile, client, 'stream', [stream], topic, body)
return json_success()