| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 939505b commit de29503
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,7 +48,9 @@ def diff(self, **kwargs: Any) -> Union[gitlab.GitlabList, List[Dict[str, Any]]]: | |||
| 48 | 48 | ||
| 49 | 49 | @cli.register_custom_action(cls_names="ProjectCommit", required=("branch",)) | |
| 50 | 50 | @exc.on_http_error(exc.GitlabCherryPickError) | |
| 51 | - def cherry_pick(self, branch: str, **kwargs: Any) -> None: | ||
| 51 | + def cherry_pick( | ||
| 52 | + self, branch: str, **kwargs: Any | ||
| 53 | + ) -> Union[Dict[str, Any], requests.Response]: | ||
| 52 | 54 | """Cherry-pick a commit into a branch. | |
| 53 | 55 | ||
| 54 | 56 | Args: | |
@@ -58,10 +60,13 @@ def cherry_pick(self, branch: str, **kwargs: Any) -> None: | |||
| 58 | 60 | Raises: | |
| 59 | 61 | GitlabAuthenticationError: If authentication is not correct | |
| 60 | 62 | GitlabCherryPickError: If the cherry-pick could not be performed | |
| 63 | + | ||
| 64 | + Returns: | ||
| 65 | + The new commit data (*not* a RESTObject) | ||
| 61 | 66 | """ | |
| 62 | 67 | path = f"{self.manager.path}/{self.encoded_id}/cherry_pick" | |
| 63 | 68 | post_data = {"branch": branch} | |
| 64 | - self.manager.gitlab.http_post(path, post_data=post_data, **kwargs) | ||
| 69 | + return self.manager.gitlab.http_post(path, post_data=post_data, **kwargs) | ||
| 65 | 70 | ||
| 66 | 71 | @cli.register_custom_action(cls_names="ProjectCommit", optional=("type",)) | |
| 67 | 72 | @exc.on_http_error(exc.GitlabGetError) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -165,6 +165,28 @@ def test_commit_discussion(project): | |||
| 165 | 165 | note_from_get.delete() | |
| 166 | 166 | ||
| 167 | 167 | ||
| 168 | + def test_cherry_pick_commit(project): | ||
| 169 | + commits = project.commits.list() | ||
| 170 | + commit = commits[1] | ||
| 171 | + parent_commit = commit.parent_ids[0] | ||
| 172 | + | ||
| 173 | + # create a branch to cherry pick onto | ||
| 174 | + project.branches.create( | ||
| 175 | + { | ||
| 176 | + "branch": "test", | ||
| 177 | + "ref": parent_commit, | ||
| 178 | + } | ||
| 179 | + ) | ||
| 180 | + cherry_pick_commit = commit.cherry_pick(branch="test") | ||
| 181 | + | ||
| 182 | + expected_message = f"{commit.message}\n\n(cherry picked from commit {commit.id})" | ||
| 183 | + assert cherry_pick_commit["message"].startswith(expected_message) | ||
| 184 | + | ||
| 185 | + with pytest.raises(gitlab.GitlabCherryPickError): | ||
| 186 | + # Two cherry pick attempts should raise GitlabCherryPickError | ||
| 187 | + commit.cherry_pick(branch="test") | ||
| 188 | + | ||
| 189 | + | ||
| 168 | 190 | def test_revert_commit(project): | |
| 169 | 191 | commit = project.commits.list()[0] | |
| 170 | 192 | revert_commit = commit.revert(branch="main") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,6 +37,12 @@ def resp_commit(): | |||
| 37 | 37 | "short_id": "8b090c1b", | |
| 38 | 38 | "title": 'Revert "Initial commit"', | |
| 39 | 39 | } | |
| 40 | + cherry_pick_content = { | ||
| 41 | + "id": "8b090c1b79a14f2bd9e8a738f717824ff53aebad", | ||
| 42 | + "short_id": "8b090c1b", | ||
| 43 | + "title": "Initial commit", | ||
| 44 | + "message": "Initial commit\n\n\n(cherry picked from commit 6b2257eabcec3db1f59dafbd84935e3caea04235)", | ||
| 45 | + } | ||
| 40 | 46 | ||
| 41 | 47 | with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps: | |
| 42 | 48 | rsps.add( | |
@@ -53,6 +59,13 @@ def resp_commit(): | |||
| 53 | 59 | content_type="application/json", | |
| 54 | 60 | status=200, | |
| 55 | 61 | ) | |
| 62 | + rsps.add( | ||
| 63 | + method=responses.POST, | ||
| 64 | + url="http://localhost/api/v4/projects/1/repository/commits/6b2257ea/cherry_pick", | ||
| 65 | + json=cherry_pick_content, | ||
| 66 | + content_type="application/json", | ||
| 67 | + status=200, | ||
| 68 | + ) | ||
| 56 | 69 | yield rsps | |
| 57 | 70 | ||
| 58 | 71 | ||
@@ -118,6 +131,18 @@ def test_create_commit(project, resp_create_commit): | |||
| 118 | 131 | assert commit.title == data["commit_message"] | |
| 119 | 132 | ||
| 120 | 133 | ||
| 134 | + def test_cherry_pick_commit(project, resp_commit): | ||
| 135 | + commit = project.commits.get("6b2257ea", lazy=True) | ||
| 136 | + cherry_pick_commit = commit.cherry_pick(branch="main") | ||
| 137 | + | ||
| 138 | + assert cherry_pick_commit["short_id"] == "8b090c1b" | ||
| 139 | + assert cherry_pick_commit["title"] == "Initial commit" | ||
| 140 | + assert ( | ||
| 141 | + cherry_pick_commit["message"] | ||
| 142 | + == "Initial commit\n\n\n(cherry picked from commit 6b2257eabcec3db1f59dafbd84935e3caea04235)" | ||
| 143 | + ) | ||
| 144 | + | ||
| 145 | + | ||
| 121 | 146 | def test_revert_commit(project, resp_commit): | |
| 122 | 147 | commit = project.commits.get("6b2257ea", lazy=True) | |
| 123 | 148 | revert_commit = commit.revert(branch="main") | |
| Back | FazBrowse Home | New Git URL |
0 commit comments