def get_pull_request_review_body(payload: Dict[str, Any]) -> Text: return get_pull_request_event_message( get_sender_name(payload), 'submitted', payload['review']['html_url'], type='PR Review' )
def get_pull_request_action_body(payload: Dict[str, Any], action: str) -> Text: pull_request = payload['pullrequest'] return get_pull_request_event_message( get_user_username(payload), action, get_pull_request_url(pull_request), pull_request.get('id') )
def get_closed_pull_request_body(payload: Dict[str, Any]) -> Text: pull_request = payload['pull_request'] action = 'merged' if pull_request['merged'] else 'closed without merge' return get_pull_request_event_message( get_sender_name(payload), action, pull_request['html_url'], )
def get_pull_request_action_body(payload, action): # type: (Dict[str, Any], str) -> text_type pull_request = payload['pullrequest'] return get_pull_request_event_message( get_user_username(payload), action, get_pull_request_url(pull_request), )
def github_object_commented_content(payload, type): # type: (Mapping[text_type, Any], text_type) -> text_type comment = payload["comment"] issue = payload["issue"] action = u"[commented]({}) on".format(comment["html_url"]) return get_pull_request_event_message( comment["user"]["login"], action, issue["html_url"], issue["number"], message=comment["body"], type=type )
def get_pull_request_comment_action_body(payload: Dict[str, Any], action: str) -> Text: action += ' on' return get_pull_request_event_message( get_user_username(payload), action, payload['pullrequest']['links']['html']['href'], payload['pullrequest']['id'], message=payload['comment']['content']['raw'] )
def get_merge_request_event_body(payload, action): # type: (Dict[str, Any], text_type) -> text_type pull_request = payload.get('object_attributes') return get_pull_request_event_message( get_issue_user_name(payload), action, pull_request.get('url'), type='MR', )
def get_merge_request_event_body(payload: Dict[str, Any], action: Text) -> Text: pull_request = payload['object_attributes'] return get_pull_request_event_message( get_issue_user_name(payload), action, pull_request.get('url'), pull_request.get('iid'), type='MR', )
def get_pull_request_action_body(payload: Dict[str, Any], action: str, include_title: Optional[bool]=False) -> str: pull_request = payload['pullrequest'] return get_pull_request_event_message( get_user_username(payload), action, get_pull_request_url(pull_request), pull_request.get('id'), title=pull_request['title'] if include_title else None )
def github_pull_request_content(payload): # type: (Mapping[text_type, Any]) -> text_type pull_request = payload["pull_request"] action = get_pull_request_or_issue_action(payload) if action in ("opened", "edited"): return get_pull_request_event_message( payload["sender"]["login"], action, pull_request["html_url"], pull_request["number"], pull_request["head"]["ref"], pull_request["base"]["ref"], pull_request["body"], get_pull_request_or_issue_assignee(pull_request), ) return get_pull_request_event_message( payload["sender"]["login"], action, pull_request["html_url"], pull_request["number"] )
def github_pull_request_content(payload): # type: (Mapping[text_type, Any]) -> text_type pull_request = payload['pull_request'] action = get_pull_request_or_issue_action(payload) if action in ('opened', 'edited'): return get_pull_request_event_message( payload['sender']['login'], action, pull_request['html_url'], pull_request['head']['ref'], pull_request['base']['ref'], pull_request['body'], get_pull_request_or_issue_assignee(pull_request) ) return get_pull_request_event_message( payload['sender']['login'], action, pull_request['html_url'], )
def get_merge_request_event_body(payload: Dict[str, Any], action: str, include_title: Optional[bool]=False) -> str: pull_request = payload['object_attributes'] return get_pull_request_event_message( get_issue_user_name(payload), action, pull_request.get('url'), pull_request.get('iid'), type='MR', title=payload['object_attributes'].get('title') if include_title else None )
def get_closed_pull_request_body(payload: Dict[str, Any], include_title: Optional[bool]=False) -> str: pull_request = payload['pull_request'] action = 'merged' if pull_request['merged'] else 'closed without merge' return get_pull_request_event_message( get_sender_name(payload), action, pull_request['html_url'], number=pull_request['number'], title=pull_request['title'] if include_title else None )
def get_pull_request_review_comment_body(payload: Dict[str, Any]) -> Text: action = payload['action'] message = None if action == 'created': message = payload['comment']['body'] return get_pull_request_event_message( get_sender_name(payload), action, payload['comment']['html_url'], message=message, type='PR Review Comment' )
def get_merge_request_open_or_updated_body(payload: Dict[str, Any], action: Text) -> Text: pull_request = payload['object_attributes'] return get_pull_request_event_message( get_issue_user_name(payload), action, pull_request.get('url'), pull_request.get('iid'), pull_request.get('source_branch'), pull_request.get('target_branch'), pull_request.get('description'), get_objects_assignee(payload), type='MR', )
def get_pull_request_comment_action_body( payload: Dict[str, Any], action: str, include_title: Optional[bool]=False ) -> str: action += ' on' return get_pull_request_event_message( get_user_username(payload), action, payload['pullrequest']['links']['html']['href'], payload['pullrequest']['id'], message=payload['comment']['content']['raw'], title=payload['pullrequest']['title'] if include_title else None )
def github_object_commented_content(payload, type): # type: (Mapping[text_type, Any], text_type) -> text_type comment = payload['comment'] issue = payload['issue'] action = u'[commented]({})'.format(comment['html_url']) return get_pull_request_event_message( comment['user']['login'], action, issue['html_url'], message=comment['body'], type=type )
def get_pull_request_review_body(payload: Dict[str, Any], include_title: Optional[bool]=False) -> str: title = "for #{} {}".format( payload['pull_request']['number'], payload['pull_request']['title'] ) return get_pull_request_event_message( get_sender_name(payload), 'submitted', payload['review']['html_url'], type='PR Review', title=title if include_title else None )
def get_merge_request_open_or_updated_body(payload, action): # type: (Dict[str, Any], text_type) -> text_type pull_request = payload.get('object_attributes') return get_pull_request_event_message( get_issue_user_name(payload), action, pull_request.get('url'), pull_request.get('source_branch'), pull_request.get('target_branch'), pull_request.get('description'), get_objects_assignee(payload), type='MR', )
def get_assigned_or_unassigned_pull_request_body(payload): # type: (Dict[str, Any]) -> Text pull_request = payload['pull_request'] assignee = pull_request.get('assignee', {}).get('login') base_message = get_pull_request_event_message( get_sender_name(payload), payload['action'], pull_request['html_url'], ) if assignee: return "{} to {}".format(base_message, assignee) return base_message
def github_object_commented_content(payload: Mapping[str, Any], type: str) -> str: comment = payload['comment'] issue = payload['issue'] action = u'[commented]({}) on'.format(comment['html_url']) return get_pull_request_event_message( comment['user']['login'], action, issue['html_url'], issue['number'], message=comment['body'], type=type )
def get_assigned_or_unassigned_pull_request_body(payload: Dict[str, Any]) -> str: pull_request = payload['pull_request'] assignee = pull_request.get('assignee') if assignee is not None: assignee = assignee.get('login') base_message = get_pull_request_event_message( get_sender_name(payload), payload['action'], pull_request['html_url'], ) if assignee is not None: return "{} to {}".format(base_message, assignee) return base_message
def get_merge_request_open_or_updated_body(payload: Dict[str, Any], action: str, include_title: Optional[bool]=False) -> str: pull_request = payload['object_attributes'] return get_pull_request_event_message( get_issue_user_name(payload), action, pull_request.get('url'), pull_request.get('iid'), pull_request.get('source_branch'), pull_request.get('target_branch'), pull_request.get('description'), get_objects_assignee(payload), type='MR', title=payload['object_attributes'].get('title') if include_title else None )
def get_commented_snippet_event_body(payload: Dict[str, Any]) -> Text: comment = payload['object_attributes'] action = u'[commented]({}) on'.format(comment['url']) url = u'{}/snippets/{}'.format( payload['project'].get('web_url'), payload['snippet'].get('id') ) return get_pull_request_event_message( get_issue_user_name(payload), action, url, payload['snippet'].get('id'), message=comment['note'], type='Snippet' )
def get_pull_request_created_or_updated_body(payload: Dict[str, Any], action: str) -> Text: pull_request = payload['pullrequest'] assignee = None if pull_request.get('reviewers'): assignee = pull_request.get('reviewers')[0]['username'] return get_pull_request_event_message( get_user_username(payload), action, get_pull_request_url(pull_request), pull_request.get('id'), target_branch=pull_request['source']['branch']['name'], base_branch=pull_request['destination']['branch']['name'], message=pull_request['description'], assignee=assignee )
def get_commented_issue_event_body(payload): # type: (Dict[str, Any]) -> text_type comment = payload.get('object_attributes') action = u'[commented]({}) on'.format(comment['url']) url = u'{}/issues/{}'.format( payload.get('project').get('web_url'), payload.get('issue').get('iid') ) return get_pull_request_event_message( get_issue_user_name(payload), action, url, payload.get('issue').get('iid'), message=comment['note'], type='Issue' )
def format_pull_request_event(payload: Dict[str, Any]) -> Text: data = { 'user_name': payload['pull_request']['user']['username'], 'action': payload['action'], 'url': payload['pull_request']['html_url'], 'number': payload['pull_request']['number'], 'target_branch': payload['pull_request']['head_branch'], 'base_branch': payload['pull_request']['base_branch'], } if payload['pull_request']['merged']: data['user_name'] = payload['pull_request']['merged_by']['username'] data['action'] = 'merged' return get_pull_request_event_message(**data)
def get_assigned_or_unassigned_pull_request_body(payload: Dict[str, Any], include_title: Optional[bool]=False) -> str: pull_request = payload['pull_request'] assignee = pull_request.get('assignee') if assignee is not None: assignee = assignee.get('login') base_message = get_pull_request_event_message( get_sender_name(payload), payload['action'], pull_request['html_url'], number=pull_request['number'], title=pull_request['title'] if include_title else None ) if assignee is not None: return "{} to {}".format(base_message, assignee) return base_message
def get_opened_or_update_pull_request_body(payload: Dict[str, Any]) -> Text: pull_request = payload['pull_request'] action = payload['action'] if action == 'synchronize': action = 'updated' assignee = None if pull_request.get('assignee'): assignee = pull_request['assignee']['login'] return get_pull_request_event_message( get_sender_name(payload), action, pull_request['html_url'], target_branch=pull_request['head']['ref'], base_branch=pull_request['base']['ref'], message=pull_request['body'], assignee=assignee )
def format_pull_request_event(payload: Dict[str, Any], include_title: Optional[bool]=False) -> str: data = { 'user_name': payload['pull_request']['user']['username'], 'action': payload['action'], 'url': payload['pull_request']['html_url'], 'number': payload['pull_request']['number'], 'target_branch': payload['pull_request']['head_branch'], 'base_branch': payload['pull_request']['base_branch'], 'title': payload['pull_request']['title'] if include_title else None } if payload['pull_request']['merged']: data['user_name'] = payload['pull_request']['merged_by']['username'] data['action'] = 'merged' return get_pull_request_event_message(**data)
def get_pull_request_review_comment_body(helper: Helper) -> str: payload = helper.payload include_title = helper.include_title action = payload["action"] message = None if action == "created": message = payload["comment"]["body"] title = "on #{} {}".format( payload["pull_request"]["number"], payload["pull_request"]["title"], ) return get_pull_request_event_message( get_sender_name(payload), action, payload["comment"]["html_url"], message=message, type="PR Review Comment", title=title if include_title else None, )
def pr_comment_handler(payload: Dict[str, Any], action: str, include_title: bool = False) -> List[Dict[str, str]]: pr = payload["pullRequest"] subject = get_pr_subject(pr["toRef"]["repository"]["name"], type="PR", id=pr["id"], title=pr["title"]) message = payload["comment"]["text"] if action == "deleted their comment on": message = f"~~{message}~~" body = get_pull_request_event_message( user_name=get_user_name(payload), action=action, url=pr["links"]["self"][0]["href"], number=pr["id"], message=message, title=pr["title"] if include_title else None, ) return [{"subject": subject, "body": body}]
def get_pr_opened_or_modified_body(payload: Dict[str, Any], action: str, include_title: Optional[bool]) -> str: pr = payload["pullRequest"] description = pr.get("description") assignees_string = get_assignees_string(pr) if assignees_string: # Then use the custom message template for this particular integration so that we can # specify the reviewers at the end of the message (but before the description/message). parameters = { "user_name": get_user_name(payload), "action": action, "url": pr["links"]["self"][0]["href"], "number": pr["id"], "source": pr["fromRef"]["displayId"], "destination": pr["toRef"]["displayId"], "message": description, "assignees": assignees_string, "title": pr["title"] if include_title else None } if include_title: body = PULL_REQUEST_OPENED_OR_MODIFIED_TEMPLATE_WITH_REVIEWERS_WITH_TITLE.format( **parameters) else: body = PULL_REQUEST_OPENED_OR_MODIFIED_TEMPLATE_WITH_REVIEWERS.format( **parameters) punctuation = ':' if description else '.' body = "{}{}".format(body, punctuation) if description: body += '\n' + CONTENT_MESSAGE_TEMPLATE.format(message=description) return body return get_pull_request_event_message( user_name=get_user_name(payload), action=action, url=pr["links"]["self"][0]["href"], number=pr["id"], target_branch=pr["fromRef"]["displayId"], base_branch=pr["toRef"]["displayId"], message=pr.get("description"), assignee=assignees_string if assignees_string else None, title=pr["title"] if include_title else None)
def get_pull_request_created_or_updated_body(payload: Dict[str, Any], action: str, include_title: bool=False) -> str: pull_request = payload['pullrequest'] assignee = None if pull_request.get('reviewers'): assignee = pull_request.get('reviewers')[0] # Certain payloads may not contain a username, so we # return the user's display name or nickname instead. assignee = (assignee.get('username') or assignee.get('display_name') or assignee.get('nickname')) return get_pull_request_event_message( get_user_username(payload), action, get_pull_request_url(pull_request), pull_request.get('id'), target_branch=pull_request['source']['branch']['name'], base_branch=pull_request['destination']['branch']['name'], message=pull_request['description'], assignee=assignee, title=pull_request['title'] if include_title else None, )
def format_pull_request_event(payload: WildValue, include_title: bool = False) -> str: if payload["pull_request"]["merged"].tame(check_bool): user_name = payload["pull_request"]["merged_by"]["username"].tame(check_string) action = "merged" else: user_name = payload["pull_request"]["user"]["username"].tame(check_string) action = payload["action"].tame(check_string) url = payload["pull_request"]["html_url"].tame(check_string) number = payload["pull_request"]["number"].tame(check_int) target_branch = payload["pull_request"]["head_branch"].tame(check_string) base_branch = payload["pull_request"]["base_branch"].tame(check_string) title = payload["pull_request"]["title"].tame(check_string) if include_title else None return get_pull_request_event_message( user_name=user_name, action=action, url=url, number=number, target_branch=target_branch, base_branch=base_branch, title=title, )
def get_opened_or_update_pull_request_body(helper: Helper) -> str: payload = helper.payload include_title = helper.include_title pull_request = payload['pull_request'] action = payload['action'] if action == 'synchronize': action = 'updated' assignee = None if pull_request.get('assignee'): assignee = pull_request['assignee']['login'] return get_pull_request_event_message( get_sender_name(payload), action, pull_request['html_url'], target_branch=pull_request['head']['ref'], base_branch=pull_request['base']['ref'], message=pull_request['body'], assignee=assignee, number=pull_request['number'], title=pull_request['title'] if include_title else None, )
def get_pull_request_review_body(payload): # type: (Dict[str, Any]) -> Text return get_pull_request_event_message(get_sender_name(payload), 'submitted', payload['review']['html_url'], type='PR Review')
def get_pull_request_action_body(payload: Dict[str, Any], action: str) -> str: pull_request = payload['pullrequest'] return get_pull_request_event_message(get_user_username(payload), action, get_pull_request_url(pull_request), pull_request.get('id'))
def get_pull_request_action_body(payload, action): # type: (Dict[str, Any], str) -> text_type pull_request = payload['pullrequest'] return get_pull_request_event_message(get_user_username(payload), action, get_pull_request_url(pull_request), pull_request.get('id'))