def test_revert_pr(env, git_gecko, git_wpt, git_wpt_upstream, pull_request, pull_request_fn, set_pr_status, wpt_worktree): 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"]) commit = sync.wpt_commits[0] sync.wpt_commits.base = sync.data[ "wpt-base"] = git_wpt_upstream.head.commit.hexsha git_wpt_upstream.git.merge(commit.sha1) def revert_fn(): git_wpt.remotes["origin"].fetch() wpt_work = wpt_worktree() wpt_work.git.revert(commit.sha1, no_edit=True) wpt_work.git.push("origin", "HEAD:refs/heads/revert") git_wpt_upstream.commit("revert") return "revert" pr_revert = pull_request_fn(revert_fn, title="Revert Test PR") downstream.new_wpt_pr(git_gecko, git_wpt, pr_revert) sync_revert = load.get_pr_sync(git_gecko, git_wpt, pr_revert["number"]) # Refresh the instance data sync.data._load() assert sync.skip assert sync_revert.skip
def test_new_wpt_pr(env, git_gecko, git_wpt, pull_request, set_pr_status, mock_mach, mock_wpt): pr = pull_request([("Test commit", { "README": "Example change\n" })], "Test PR") mock_mach.set_data( "file-info", """Testing :: web-platform-tests testing/web-platform/tests/README """) mock_wpt.set_data("files-changed", "README\n") downstream.new_wpt_pr(git_gecko, git_wpt, pr) sync = load.get_pr_sync(git_gecko, git_wpt, pr["number"]) env.gh_wpt.set_status(pr["number"], "success", "http://test/", "description", "continuous-integration/travis-ci/pr") assert sync is not None assert sync.status == "open" assert len(sync.gecko_commits) == 1 assert len(sync.wpt_commits) == 1 assert sync.gecko_commits[0].metadata == { "wpt-pr": str(pr["number"]), "wpt-commit": pr["head"] } assert "Creating a bug in component Testing :: web-platform" in env.bz.output.getvalue( )
def test_dependent_commit(env, git_gecko, git_wpt, pull_request, upstream_wpt_commit, pull_request_commit): upstream_wpt_commit("First change", {"README": "Example change\n"}) pr = pull_request([("Test change", { "README": "Example change 1\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) == 2 assert sync.gecko_commits[0].msg.splitlines()[0] == "First change" assert sync.gecko_commits[0].metadata["wpt-type"] == "dependency" assert sync.gecko_commits[1].metadata.get("wpt-type") is None assert "Test change" in sync.gecko_commits[1].msg.splitlines()[0] old_gecko_commits = sync.gecko_commits[:] # Check that rerunning doesn't affect anything sync.update_commits() assert [item.sha1 for item in sync.gecko_commits ] == [item.sha1 for item in old_gecko_commits] head_sha = pull_request_commit(pr.number, [("fixup! Test change", { "README": "Example change 2\n" })]) downstream.update_repositories(git_gecko, git_wpt) sync.update_commits() assert len(sync.gecko_commits) == 3 assert ([item.sha1 for item in sync.gecko_commits[:2] ] == [item.sha1 for item in old_gecko_commits]) assert sync.gecko_commits[-1].metadata["wpt-commit"] == head_sha
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
def inner(pr, status="success"): from sync import load pr = env.gh_wpt.get_pull(pr) check_id = 0 if not pr._commits[ -1]._checks else pr._commits[-1]._checks[0]["id"] + 1 for context in env.gh_wpt.required_checks("master"): pr._commits[-1]._checks.append({ "name": context, "status": "completed", "conclusion": status, "id": check_id, "url": "http://test/", "head_sha": pr._commits[-1].sha, "required": True }) check_id += 1 # Add a non-required check pr._commits[-1]._checks.append({ "name": "another-check", "status": "completed", "conclusion": "failure", "id": check_id, "url": "http://test/", "head_sha": pr._commits[-1].sha, "required": False }) sync = load.get_pr_sync(git_gecko, git_wpt, pr["number"]) return sync
def inner(pr, status="success"): from sync import load env.gh_wpt.set_status(pr["number"], status, "http://test/", "description", "continuous-integration/travis-ci/pr") sync = load.get_pr_sync(git_gecko, git_wpt, pr["number"]) downstream.commit_status_changed( git_gecko, git_wpt, sync, "continuous-integration/travis-ci/pr", status, "http://test/", pr["head"]) return sync
def test_github_label_on_error(env, git_gecko, git_wpt, pull_request): pr = pull_request([("Testing", {"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"]) with SyncLock.for_process(sync.process_name) as lock: with sync.as_mut(lock): sync.error = "Infrastructure Failed" assert env.gh_wpt.get_pull( pr["number"])["labels"] == ["mozilla:gecko-blocked"] with SyncLock.for_process(sync.process_name) as lock: with sync.as_mut(lock): sync.update_commits() assert env.gh_wpt.get_pull(pr["number"])["labels"] == []
def inner(pr, status="success"): from sync import load env.gh_wpt.set_status(pr["number"], status, "http://test/", "description", "continuous-integration/travis-ci/pr") sync = load.get_pr_sync(git_gecko, git_wpt, pr["number"]) with SyncLock.for_process(sync.process_name) as lock: with sync.as_mut(lock): with patch("sync.tree.is_open", Mock(return_value=True)): downstream.commit_status_changed( git_gecko, git_wpt, sync, "continuous-integration/travis-ci/pr", status, "http://test/", pr["head"], raise_on_error=True) return sync
def test_update_metadata(env, git_gecko, git_wpt, pull_request, git_wpt_metadata, mock_mach): results_obj = fx_only_failure() 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"]) mock_mach.set_data( "wpt-test-paths", json.dumps(bugs.fallback_test_ids_to_paths(["/test/test.html"]))) with patch( "sync.notify.bugs.components_for_wpt_paths", return_value={"Testing :: web-platform-tests": ["test/test.html"]}): with patch("sync.notify.bugs.Mach", return_value=mock_mach(None)): with patch("sync.meta.Metadata.github") as mock_github: with SyncLock.for_process(sync.process_name) as lock: with sync.as_mut(lock): bug_data = bugs.for_sync(sync, results_obj) bugs.update_metadata(sync, bug_data) assert mock_github.create_pull.called head = mock_github.method_calls[0].args[-1] bugs_filed = bug_data.keys() assert len(bugs_filed) == 1 bug = bugs_filed[0] metadata = meta.Metadata(sync.process_name, branch=head) links = list(metadata.iterbugs("/test/test.html")) assert len(links) == 1 link = links[0] assert link.url == "%s/show_bug.cgi?id=%s" % (env.bz.bz_url, bug) assert link.test_id == "/test/test.html" assert link.product == "firefox" assert link.subtest is None assert link.status is None
def test_gecko_rebase(env, git_gecko, git_wpt, pull_request): 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): assert sync.data[ "gecko-base"] == downstream.DownstreamSync.gecko_landing_branch( ) sync.gecko_rebase( downstream.DownstreamSync.gecko_integration_branch()) assert sync.data[ "gecko-base"] == downstream.DownstreamSync.gecko_integration_branch( )