def check_for_auto_merge_trigger(text): """Checks the text for the phrases that should trigger an automerge.""" text = text.lower() # The comment must address @dpebot directly. if not '@{}'.format(github_helper.github_user()) in text: return False # These should all be lowercase. triggers = ('merge on green', 'merge when green', 'merge when travis passes', 'merge when travis is green', 'lgtm') for trigger in triggers: if trigger in text: return True return False
def check_for_auto_merge_trigger(text): """Checks the text for the phrases that should trigger an automerge.""" # The comment must address @dpebot directly, on the same line comment = re.search(r'@{}\s+\b(.+)'.format(github_helper.github_user()), text, re.I) if not comment: return False else: # Just get the meat of the command comment = comment.group(1).strip() satisfaction = r'\b(pass|passes|green|approv(e|al|es|ed)|happy|satisfied)' ci_tool = r'\b(travis|tests|statuses|kokoro|ci)\b' merge_action = r'\bmerge\b' triggers = ( r'{}.+({}.+)?{}'.format(merge_action, ci_tool, satisfaction), r'{}.+{},.+{}'.format(ci_tool, satisfaction, merge_action), 'lgtm', ) return any(re.search(trigger, comment, re.I) for trigger in triggers)
def check_for_auto_merge_trigger(text): """Checks the text for the phrases that should trigger an automerge.""" # The comment must address @dpebot directly, on the same line comment = re.search( r'@{}\s+\b(.+)'.format(github_helper.github_user()), text, re.I) if not comment: return False else: # Just get the meat of the command comment = comment.group(1).strip() satisfaction = r'\b(pass|passes|green|approv(e|al|es|ed)|happy|satisfied)' ci_tool = r'\b(travis|tests|statuses|kokoro|ci)\b' merge_action = r'\bmerge\b' triggers = ( r'{}.+({}.+)?{}'.format(merge_action, ci_tool, satisfaction), r'{}.+{},.+{}'.format(ci_tool, satisfaction, merge_action), 'lgtm', ) return any(re.search(trigger, comment, re.I) for trigger in triggers)
def acknowledge_merge_on_travis(data): """When a user comments on a pull request with one of the automerge triggers (e.g. merge on green), this hook will add the 'automerge' label. Issue comment data reference: https://developer.github.com/v3/activity/events/types/#issuecommentevent """ if data.get('action') != 'created': return # Make sure it's a PR. if not github_helper.is_pull_request(data): return # If comment has trigger text. comment = data['comment'] if not check_for_auto_merge_trigger(comment['body']): return # If user is a collaborator. gh = github_helper.get_client() repository = github_helper.get_repository(gh, data) if not repository.is_collaborator(data['sender']['login']): logging.info( '{} is not an owner and is trying to tell me what to do.'.format( data['sender']['login'])) # Write a comment about it. pr = github_helper.get_pull_request(gh, data) pr.create_comment( 'Okay! I\'ll merge when all statuses are green and all reviewers ' 'approve.') pr.issue().add_labels('automerge') pr.issue().assign(github_helper.github_user())