Exemplo 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
Exemplo n.º 2
0
def comment(repo_dir, branch_to, commit_range, dry_run=False):
    all_commits = git.log(repo_dir, commit_range, pretty="%H").strip().split("\n")
    comments = {}
    commits_without_bugs = []

    assert branch_to in git.branches(repo_dir), "branch parameter must be a branch"

    i = 0
    for commit in all_commits:
        i += 1
        print "bug %d of %d" % (i, len(all_commits))
        bug_ids = guess_bug_id(repo_dir, commit)
        if bug_ids is None or len(bug_ids) == 0:
            commits_without_bugs.append(commit)
        else:
            for bug_id in bug_ids:
                if not bug_id in comments.keys():
                    comments[bug_id] = []
                comments[bug_id].append(commit)

    failed_bugs = []

    for bug_id in comments.keys():
        comment = []
        flags = branch_logic.flags_to_set([branch_to])
        for commit in comments[bug_id]:
            comment.append("v1.1.0hd: %s" % commit)
        comment = "\n".join(comment)
        print "Commenting on bug %s with:\ntext: %s\nflags: %s" % (bug_id, comment, flags)
        if not dry_run:
            try:
                bzapi.update_bug(bug_id, comment=comment, values=flags)
            except:
                failed_bugs.append(bug_id)
    print "The following commits do not have a bug associated with them:\n%s" % commits_without_bugs
    print "Failed to comment on the following bugs:\n%s" % failed_bugs