示例#1
0
文件: uplift.py 项目: jhford/uplift
def uplift(repo_dir, gaia_url, requirements):
    # Setup stuff
    t=util.time_start()
    print "Updating Gaia"
    git.create_gaia(repo_dir, gaia_url) # This is sadly broken
    print "Created Gaia in %0.2f seconds" % util.time_end(t)

    # Determining what needs to be uplifted
    with_commits = {}
    for bug_id in requirements.keys():
        if requirements[bug_id].has_key('commits'):
            with_commits[bug_id] = requirements[bug_id]

    ordered_commits = order_commits(repo_dir, with_commits)

    uplift = dict([(x, {}) for x in ordered_commits])

    # Uplifting
    for commit in ordered_commits:
        needed_on = []
        for bug_id in with_commits.keys():
            if commit in with_commits[bug_id]['commits']:
                for i in with_commits[bug_id]['needed_on']:
                    if not i in needed_on:
                        needed_on.append(i)
        print "\n", "="*80
        print "Attempting to uplift %s commit to %s" % (commit, util.e_join(needed_on))
        uplift[commit]['needed_on'] = needed_on
        result = uplift_commit(repo_dir, commit, needed_on)
        print "Sucess on %s" % util.e_join(result['success'].keys())
        print "Failure on %s" % util.e_join(result['failure'])
        uplift[commit]['uplift_status'] = result

    uplift_report = copy.deepcopy(with_commits)

    # Determinging which commits belong to which bugs
    for bug_id in uplift_report.keys():
        successful_branches = []
        failed_branches = []
        for commit in git.sort_commits(repo_dir, uplift_report[bug_id]['commits'], 'master'):
            if commit in uplift.keys():
                if not uplift_report[bug_id].has_key('uplift_status'):
                    uplift_report[bug_id]['uplift_status'] = {}
                u = uplift_report[bug_id]['uplift_status']
                u[commit] = copy.deepcopy(uplift[commit]['uplift_status'])
                failed_branches.extend([x for x in u[commit]['failure'] if x not in failed_branches])
                successful_branches.extend([x for x in u[commit]['success'].keys() if x not in successful_branches])
        # Because we might have multiple commits, we want to make sure that the list of successful branches
        # includes only those with *no* failing uplifts
        for i in range(len(successful_branches) - 1, -1, -1):
            if successful_branches[i] in failed_branches:
                del successful_branches[i]
        uplift_report[bug_id]['flags_to_set'] = branch_logic.flags_to_set(successful_branches)

    util.write_json(uplift_dated_file, uplift_report)
    util.write_json(uplift_report_file, uplift_report)
    return uplift_report
示例#2
0
文件: merge_hd.py 项目: jhford/uplift
def merge(repo_dir, gaia_url, branch_to, branch_from):
    git.delete_gaia(repo_dir)
    t = util.time_start()
    if os.path.exists(repo_dir):
        print "Updating Gaia"
        git.update_gaia(repo_dir, gaia_url)
        print "Updated Gaia in %0.2f seconds" % util.time_end(t)
    else:
        print "Creating Gaia"
        git.create_gaia(repo_dir, gaia_url)  # This is sadly broken
        print "Created Gaia in %0.2f seconds" % util.time_end(t)

    print "Merging %s into branch %s" % (branch_from, branch_to)
    if not branch_to in git.branches(repo_dir):
        print >> sys.stderr, "Asking to merge into a branch that doesn't exist (%s)" % branch_to
        return None
    if not branch_from in git.branches(repo_dir):
        print >> sys.stderr, "Asking to merge from a branch that doesn't exist (%s)" % branch_from
        return None

    git.checkout(repo_dir, branch_to)
    start_commit = git.get_rev(repo_dir)
    git.merge(repo_dir, branch_from, strategy="recursive")
    end_commit = git.get_rev(repo_dir)
    print "Merge range is %s..%s" % (start_commit[:7], end_commit[:7])
    print git.log(repo_dir, "%s..%s" % (start_commit, end_commit), pretty="oneline")
    print "Dry Run push"
    git.push(repo_dir, remote="origin", branches=[branch_to], dry_run=True)
    info = git.push(repo_dir, remote="origin", branches=[branch_to])
    print "Would be pusing to %s" % info["url"]
    for branch in info["branches"].keys():
        s, e = info["branches"][branch]
        print "  %s: %s..%s" % (branch, s, e)
    if util.ask_yn("Push for realises?"):
        info = git.push(repo_dir, remote="origin", branches=[branch_to], dry_run=False)
        print "Pushed to %s" % info["url"]
        for branch in info["branches"].keys():
            s, e = info["branches"][branch]
            print "  %s: %s..%s" % (branch, s, e)
        comment(repo_dir, branch_to, "%s..%s" % (start_commit, end_commit))
示例#3
0
文件: driver.py 项目: jhford/uplift
def main():
    args = sys.argv
    gaia_url = c.read_value('repository.url')
    gaia_path = os.path.join(os.getcwd(), gaia_url.split('/')[-1])

    if len(args) < 2:
        print "You must specify a command"
        exit(1)

    cmd = args[1]
    cmd_args = args[2:]

    if cmd == 'show':
        bugs = uplift.build_uplift_requirements(gaia_path)
        print "\n\nRequirements for Bug uplift:"
        print reporting.display_uplift_requirements(bugs)
    elif cmd == 'uplift':
        requirements = uplift.build_uplift_requirements(gaia_path)
        full_requirements = find_commits.for_all_bugs(gaia_path, requirements)

        print "\n\nUplift requirements:"
        print reporting.display_uplift_requirements(full_requirements)
        uplift_report = uplift.uplift(gaia_path, gaia_url, full_requirements)
        print reporting.display_uplift_report(uplift_report)
        try:
            push_info = uplift.push(gaia_path)
            if push_info:
                try:
                    reporting.comment(gaia_path, uplift_report)
                except Exception as e:
                    print "ERROR: Commenting on the bugs failed"
                    print "  Fix the error and try again with:"
                    print "  uplift comments %s" % uplift.uplift_dated_file
                    print "DEBUG INFO FOLLOWS:"
                    print e
                    traceback.print_exc()
            else:
                print "To replay the comments for this push, run:"
                print "  uplift comments %s" % uplift.uplift_dated_file
        except git.PushFailure:
            print "ERROR: Pushing failed.  Try doing another uplift, and tell it to 'reuse' commits"
            exit(1)

    elif cmd == 'update':
        git.create_gaia(gaia_path, gaia_url)
    elif cmd == 'merge':
        merge_hd.merge(gaia_path, gaia_url, cmd_args[0], cmd_args[1])
    elif cmd == 'comments':
        if len(cmd_args) == 0:
            uplift_report_file = uplift.uplift_report_file
        elif len(cmd_args) == 1 and os.path.exists(cmd_args[0]):
            uplift_report_file = os.path.abspath(cmd_args[0])
        else:
            print "ERROR: missing or too many json files"
            exit(1)
        with open(uplift_report_file, 'rb') as f:
            uplift_report = json.load(f)
        reporting.comment(gaia_path, uplift_report)

    elif cmd == 'merge-comments':
        merge_hd.comment(gaia_path, cmd_args[0], cmd_args[1])
    elif cmd == "sort-commits":
        if len(cmd_args) < 3:
            print "ERROR: You must have a branch and at least one commit to sort"
            exit(1)
        branch = cmd_args[1]
        commits = cmd_args[2:]
        print "->".join(git.sort_commits(gaia_path, commits, branch))
    else:
        print "ERROR: You did not specify a command!"
        exit(1)