Example #1
0
def test_pr_commits_merge(env, git_wpt, git_gecko, git_wpt_upstream,
                          hg_gecko_upstream, upstream_gecko_commit):

    sync = setup_repo(env, git_wpt, git_gecko, hg_gecko_upstream,
                      upstream_gecko_commit)

    # Make changes on master
    git_wpt_upstream.branches.master.checkout()
    base = git_wpt_upstream.head.commit.hexsha
    git_commit(git_wpt_upstream, "Some other Commit",
               {"RANDOME_FILE": "Changes to this\n"})

    pr = env.gh_wpt.get_pull(sync.pr)

    # Create a ref on the upstream to simulate the pr than GH would setup
    git_wpt_upstream.create_head(
        'pr/%d' % pr['number'],
        commit=git_wpt_upstream.refs['gecko/1234'].commit.hexsha)

    # Merge our Sync PR
    git_wpt_upstream.git.merge('gecko/1234')
    pr['merge_commit_sha'] = str(git_wpt_upstream.active_branch.commit.hexsha)
    pr['base'] = {'sha': base}
    git_wpt.remotes.origin.fetch()

    with SyncLock.for_process(sync.process_name) as upstream_sync_lock:
        with sync.as_mut(upstream_sync_lock):
            upstream.update_pr(git_gecko, git_wpt, sync, "closed",
                               pr['merge_commit_sha'], pr['base']['sha'],
                               "test")
    pr_commits = sync.pr_commits

    for wpt_commit, pr_commit in zip(sync.wpt_commits._commits, pr_commits):
        assert wpt_commit.commit == pr_commit.commit
Example #2
0
def test_metadata_update(env, git_gecko, git_wpt, pull_request, pull_request_commit):
    from conftest import gecko_changes, git_commit
    pr = pull_request([("Test commit", {"README": "Example change\n"})],
                      "Test PR")

    downstream.new_wpt_pr(git_gecko, git_wpt, pr)
    sync = load.get_pr_sync(git_gecko, git_wpt, pr["number"])

    assert len(sync.gecko_commits) == 1

    with SyncLock.for_process(sync.process_name) as lock:
        with sync.as_mut(lock):
            gecko_work = sync.gecko_worktree.get()
            changes = gecko_changes(env, meta_changes={"example.ini": "Example change"})
            git_commit(gecko_work, """Update metadata

        wpt-pr: %s
        wpt-type: metadata
        """ % pr.number, changes)

            assert len(sync.gecko_commits) == 2
            assert sync.gecko_commits[-1].metadata.get("wpt-type") == "metadata"
            metadata_commit = sync.gecko_commits[-1]

            head_sha = pull_request_commit(pr.number,
                                           [("fixup! Test commit",
                                             {"README": "Example change 1\n"})])

            downstream.update_repositories(git_gecko, git_wpt)
            sync.update_commits()
            assert len(sync.gecko_commits) == 3
            assert sync.gecko_commits[-1].metadata.get("wpt-type") == "metadata"
            assert sync.gecko_commits[-1].msg == metadata_commit.msg
            assert sync.gecko_commits[-2].metadata.get("wpt-commit") == head_sha
Example #3
0
def test_relanding_changed_upstreamed_pr(env, git_gecko, git_wpt,
                                         hg_gecko_upstream,
                                         upstream_gecko_commit, mock_mach,
                                         git_wpt_upstream):
    trypush.Mach = mock_mach

    sync = create_and_upstream_gecko_bug(env, git_gecko, git_wpt,
                                         hg_gecko_upstream,
                                         upstream_gecko_commit)

    # 'Merge' this upstream PR
    pr = env.gh_wpt.get_pull(sync.pr)
    pr["base"] = {"sha": git_wpt_upstream.head.commit.hexsha}
    pr["user"]["login"] = "******"
    with SyncLock.for_process(sync.process_name) as upstream_sync_lock:
        with sync.as_mut(upstream_sync_lock):
            sync.push_commits()

    git_wpt_upstream.branches['gecko/1234'].checkout()
    extra_commit = git_commit(git_wpt_upstream, "Fixed pr before merge",
                              {"EXTRA": "This fixes it"})
    git_wpt_upstream.branches.master.checkout()
    assert str(git_wpt_upstream.active_branch) == "master"
    git_wpt_upstream.git.merge('gecko/1234')  # TODO avoid hardcoding?

    # Create a ref on the upstream to simulate the pr than GH would setup
    git_wpt_upstream.create_head(
        'pr/%d' % pr['number'],
        commit=git_wpt_upstream.refs['gecko/1234'].commit.hexsha)
    git_wpt.remotes.origin.fetch()
    pr['merge_commit_sha'] = str(git_wpt_upstream.active_branch.commit.hexsha)
    env.gh_wpt.commit_prs[pr['merge_commit_sha']] = pr['number']

    landing_sync = landing.update_landing(git_gecko,
                                          git_wpt,
                                          include_incomplete=True)
    commits = landing_sync.gecko_commits._commits

    assert len(commits) == 2
    # Check that the first commit is our "fix commit" which didn't come from Gecko
    assert commits[0].metadata['wpt-commits'] == extra_commit.hexsha
    # Check that the other commit is the bot's push commit
    assert commits[1].metadata['MANUAL PUSH'] == "wpt sync bot"