def test_get_commits_to_cherry_pick_merge(): g = mock.Mock() g_pull = mock.Mock() g_pull.merged = True c1 = mock.Mock() c1.sha = "c1f" c1.parents = [] c2 = mock.Mock() c2.sha = "c2" c2.parents = [c1] def _get_commits(): return [c1, c2] g_pull.get_commits = _get_commits pull = mergify_pull.MergifyPull( g=g, g_pull=g_pull, installation_id=config.INSTALLATION_ID ) base_branch = mock.Mock() base_branch.sha = "base_branch" base_branch.parents = [] merge_commit = mock.Mock() merge_commit.sha = "merge_commit" merge_commit.parents = [base_branch, c2] assert duplicate_pull._get_commits_to_cherrypick(pull, merge_commit) == [c1, c2]
def test_get_commits_to_cherry_pick_rebase(commits): c1 = {"sha": "c1f", "parents": [], "commit": {"message": "foobar"}} c2 = {"sha": "c2", "parents": [c1], "commit": {"message": "foobar"}} commits.return_value = [c1, c2] client = mock.Mock() client.auth.get_access_token.return_value = "<token>" client.items.side_effect = fake_get_github_pulls_from_sha ctxt = context.Context( client, { "number": 6, "merged": True, "state": "closed", "html_url": "<html_url>", "base": { "sha": "sha", "user": { "login": "******" }, "ref": "ref", "repo": { "full_name": "user/ref", "name": "name", "private": False }, }, "head": { "sha": "sha", "ref": "fork", "repo": { "full_name": "fork/other", "name": "other", "private": False }, }, "user": { "login": "******" }, "merged_by": None, "merged_at": None, "mergeable_state": "clean", }, {}, ) base_branch = {"sha": "base_branch", "parents": []} rebased_c1 = {"sha": "rebased_c1", "parents": [base_branch]} rebased_c2 = {"sha": "rebased_c2", "parents": [rebased_c1]} assert duplicate_pull._get_commits_to_cherrypick(ctxt, rebased_c2) == [ rebased_c1, rebased_c2, ]
def test_get_commits_to_cherry_pick_merge(commits): c1 = {"sha": "c1f", "parents": [], "commit": {"message": "foobar"}} c2 = {"sha": "c2", "parents": [c1], "commit": {"message": "foobar"}} commits.return_value = [c1, c2] client = mock.Mock() client.auth.get_access_token.return_value = "<token>" ctxt = mergify_context.MergifyContext( client, { "number": 6, "merged": True, "state": "closed", "html_url": "<html_url>", "base": { "ref": "ref", "repo": { "full_name": "user/ref", "name": "name", "private": False }, }, "head": { "ref": "fork", "repo": { "full_name": "fork/other", "name": "other", "private": False }, }, "user": { "login": "******" }, "merged_at": None, "merged_by": None, "mergeable_state": "clean", }, ) base_branch = {"sha": "base_branch", "parents": []} merge_commit = {"sha": "merge_commit", "parents": [base_branch, c2]} assert duplicate_pull._get_commits_to_cherrypick(ctxt, merge_commit) == [c1, c2]
def test_get_commits_to_cherry_pick_rebase(commits, g_pull, _): c1 = {"sha": "c1f", "parents": [], "commit": {"message": "foobar"}} c2 = {"sha": "c2", "parents": [c1], "commit": {"message": "foobar"}} commits.return_value = [c1, c2] client = mock.Mock() client.auth.get_access_token.return_value = "<token>" pull = mergify_pull.MergifyPull( client, { "number": 6, "merged": True, "state": "closed", "html_url": "<html_url>", "base": { "ref": "ref", "repo": { "name": "name", "private": False } }, "user": { "login": "******" }, "merged_by": None, "merged_at": None, "mergeable_state": "clean", }, ) base_branch = {"sha": "base_branch", "parents": []} rebased_c1 = {"sha": "rebased_c1", "parents": [base_branch]} rebased_c2 = {"sha": "rebased_c2", "parents": [rebased_c1]} assert duplicate_pull._get_commits_to_cherrypick(pull, rebased_c2) == [ rebased_c1, rebased_c2, ]
def test_get_commits_to_cherry_pick_rebase(_): g = mock.Mock() g_pull = mock.Mock() g_pull.merged = True g_pull.number = 6 c1 = mock.Mock() c1.sha = "c1f" c1.parents = [] c2 = mock.Mock() c2.sha = "c2" c2.parents = [c1] def _get_commits(): return [c1, c2] g_pull.get_commits = _get_commits pull = mergify_pull.MergifyPull( g=g, g_pull=g_pull, installation_id=config.INSTALLATION_ID ) base_branch = mock.Mock() base_branch.sha = "base_branch" base_branch.parents = [] rebased_c1 = mock.Mock() rebased_c1.sha = "rebased_c1" rebased_c1.parents = [base_branch] rebased_c2 = mock.Mock() rebased_c2.sha = "rebased_c2" rebased_c2.parents = [rebased_c1] assert duplicate_pull._get_commits_to_cherrypick(pull, rebased_c2) == [ rebased_c1, rebased_c2, ]