Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
def generate_bad_bug_msg(repo_dir, bug):
    comment = [
        "I was not able to uplift this bug to %s.  " % util.e_join(bug['needed_on']),
        " If this bug has dependencies which are not marked in this bug ",
        "please comment on this bug.  If this bug depends on patches that ",
        "aren't approved for %s, " % util.e_join(bug['needed_on']),
        "we need to re-evaluate the approval.  ",
        "Otherwise, if this is just a merge conflict, ",
        "you might be able to resolve it with:"
    ]

    comment = textwrap.wrap(''.join(comment), 75)
    for commit in git.sort_commits(repo_dir, bug['commits'], 'master'):
        comment.append(merge_script(repo_dir, commit, bug['uplift_status'][commit]['failure']))


    return '\n'.join(comment)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
def order_commits(repo_dir, requirements):
    commits = []
    for bug_id in requirements.keys():
        if requirements[bug_id].has_key('commits'):
            commits.extend(requirements[bug_id]['commits'])
    return git.sort_commits(repo_dir, commits, "master")