def __call__(self): check_root() uninited_modules = git_tool.get_uninited_submodules() if uninited_modules: display_uninited_modules_instructions(uninited_modules) return current_branch = get_current_branch() resolve_errors(git_tool.recurse_submodules(lambda: git_tool.fetch([current_branch])), **FETCH_HANDLING) resolve_errors(git_tool.recurse_submodules(lambda: git_tool.rebase_if_needed(current_branch)), **REBASE_HANDLING) resolve_errors(git_tool.fix_refs(), title="Fixing submodule references") resolve_errors(git_tool.recurse_submodules(git_tool.push), title="Pushing...")
def __call__(self, namespace): check_root() branch = get_current_branch() authors = Counter() if is_squashed_branch(branch): print "You are trying to submit a squashed branch doll, go back to the original branch, it'll surely work!" return squashed_branch = append_squashed_branch_suffix(branch) issue = issue_from_branchname(branch) issue = issue_tracker_tool.validate_issue(issue) title = issue.fields.summary title = "%s: %s" % (issue.key, title) uninited_modules = git_tool.get_uninited_submodules() if uninited_modules: display_uninited_modules_instructions(uninited_modules) return resolve_errors(git_tool.recurse_submodules(lambda: git_tool.fetch(['master'])), **FETCH_HANDLING) resolve_errors(git_tool.recurse_submodules(lambda: git_tool.rebase_if_needed('master')), **REBASE_HANDLING) def get_original_author(): if git_tool.is_branch_diverged('origin/master'): authors[git_tool.get_author()] += 1 list(git_tool.recurse_submodules(get_original_author)) author = authors.most_common(1)[0][0] if authors else None def create_squashed_branch(): git_tool.gitcmd(['branch', '-f', squashed_branch, branch]) return git_tool.gitcmd(['checkout', squashed_branch]) def squash(): ret = err = None if git_tool.is_branch_diverged('origin/master'): ret, err = git_tool.squash(title, author) return ret, err def push_and_back(): git_tool.gitcmd(['checkout', branch]) return git_tool.forcepush(squashed_branch) resolve_errors(git_tool.recurse_submodules(git_tool.forcepush), title="Pushing...") resolve_errors(git_tool.recurse_submodules(create_squashed_branch), title="Creating squashed branch...") resolve_errors(git_tool.recurse_submodules(squash), title="Squashing...") resolve_errors(git_tool.fix_refs(), title="Fixing refs...") resolve_errors(git_tool.recurse_submodules(push_and_back), title="Pushing squashed branch...") self.process(namespace, squashed_branch)
def __call__(self, checks=True, push=True): check_root() if checks: check_config() uninited_modules = git_tool.get_uninited_submodules() if uninited_modules: display_uninited_modules_instructions(uninited_modules) return resolve_errors(git_tool.recurse_submodules(lambda: git_tool.fetch(['master'])), **FETCH_HANDLING) resolve_errors(git_tool.recurse_submodules(lambda: git_tool.rebase_if_needed('master')), **REBASE_HANDLING) resolve_errors(git_tool.fix_refs(), title="Fixing submodule references") if push: resolve_errors(git_tool.recurse_submodules(git_tool.forcepush), title="Pushing...")
def __call__(self, what, ok_no_ff): check_root() if get_current_branch() != 'master': print "You should be on the master branch before landing a feature, sweetie!" return fetched = False if issue_tracker_tool.ISSUE_BE_LIKE.match(what) is not None: issue = what branchname = branchname_from_issue(issue, test=True, squashed=True) if branchname is None: resolve_errors(git_tool.recurse_submodules(lambda: git_tool.fetch()), **FETCH_HANDLING) fetched = True branchname = branchname_from_issue(what, squashed=True) else: branchname = what issue = issue_from_branchname(what, squashed=True) if not is_squashed_branch(branchname): print YELLOW("Warning: landning non-squashed branch!") if issue is None: print YELLOW("Warning: unknown issue!") def is_ready_to_land(): if not fetched: git_tool.fetch([branchname, 'master']) if git_tool.is_merged_with("origin/%s" % branchname, ref="origin/master"): return None, None err = [] if not git_tool.is_merged_with("origin/master", ref="origin/%s" % branchname): err.append("Not rebased!") approvals = list(cr_tool.get_signed_comments(git_tool.get_repo(), branchname)) body = lambda x: x['body'] built = filter(compose(cr_tool.ApproveBuild.filter_message, body), approvals) cr = filter(compose(cr_tool.ApproveCR.filter_message, body), approvals) qa = filter(compose(cr_tool.ApproveQA.filter_message, body), approvals) ui = filter(compose(cr_tool.ApproveUITests.filter_message, body), approvals) probe = filter(compose(cr_tool.ApproveProbeTests.filter_message, body), approvals) ret = [] if len(built) == 0: err.append("Wasn't built!") else: ret.extend('Built by %s at %s' % (x['author']['name'], x['created_at']) for x in built) if len(cr) == 0: err.append("Wasn't reviewed!") else: ret.extend('Reviewd by %s at %s' % (x['author']['name'], x['created_at']) for x in cr) if len(qa) == 0: err.append("Didn't pass QA!") else: ret.extend("Passed QA's %s at %s" % (x['author']['name'], x['created_at']) for x in qa) if len(ui) == 0: err.append("Didn't pass UI tests!") else: ret.extend("Passed UI Tests at %s" % x['created_at'] for x in ui) if len(probe) == 0: err.append("Didn't pass Probe benchmark test") else: ret.extend("Passed Probe benchmark test at %s" % x['created_at'] for x in probe) return "\n".join(ret), (None if len(err) == 0 else "\n".join(err)) resolve_errors(git_tool.recurse_submodules(is_ready_to_land), **APPROVAL_HANDLING) def do_push(): return git_tool.push('master') def do_merge(): ret, err = git_tool.gitcmd(['merge', '--ff' if ok_no_ff else '--ff-only', 'origin/%s' % branchname]) if err is not None: return ret, err return ret, None merge_success = resolve_errors(git_tool.recurse_submodules(do_merge), **MERGE_HANDLING) if merge_success: resolve_errors(git_tool.fix_refs(), title="Fixing submodule references") push_success = resolve_errors(git_tool.recurse_submodules(do_push), title="Pushing...") # Make sure all MR for this issue in gitlab are closed def check_open_mr(): repo = git_tool.get_repo() project = cr_tool.get_project(repo) mr = cr_tool.get_open_mr(project, branchname) if mr is not None: print RED("ALERT: merge request is still open in GitLab for {}!".format(repo)) return None, "ALERT: merge request is still open in GitLab" return None, None gitlab_check_success = resolve_errors(git_tool.recurse_submodules(check_open_mr), title="Checking GitLab status...") if not gitlab_check_success: print RED("ERROR: there are still open MR in GitLab after land for {}, something is terribly wrong!!".format(issue)) if push_success and issue is not None: update_jira(partial(issue_tracker_tool.land, issue), 'landed in master') return push_success return False