Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitde29503

Browse files
mschoettlenejch
authored andcommitted
fix(api): return the new commit when calling cherry_pick
1 parent939505b commitde29503

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

‎gitlab/v4/objects/commits.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ def diff(self, **kwargs: Any) -> Union[gitlab.GitlabList, List[Dict[str, Any]]]:
4848

4949
@cli.register_custom_action(cls_names="ProjectCommit",required=("branch",))
5050
@exc.on_http_error(exc.GitlabCherryPickError)
51-
defcherry_pick(self,branch:str,**kwargs:Any)->None:
51+
defcherry_pick(
52+
self,branch:str,**kwargs:Any
53+
)->Union[Dict[str,Any],requests.Response]:
5254
"""Cherry-pick a commit into a branch.
5355
5456
Args:
@@ -58,10 +60,13 @@ def cherry_pick(self, branch: str, **kwargs: Any) -> None:
5860
Raises:
5961
GitlabAuthenticationError: If authentication is not correct
6062
GitlabCherryPickError: If the cherry-pick could not be performed
63+
64+
Returns:
65+
The new commit data (*not* a RESTObject)
6166
"""
6267
path=f"{self.manager.path}/{self.encoded_id}/cherry_pick"
6368
post_data= {"branch":branch}
64-
self.manager.gitlab.http_post(path,post_data=post_data,**kwargs)
69+
returnself.manager.gitlab.http_post(path,post_data=post_data,**kwargs)
6570

6671
@cli.register_custom_action(cls_names="ProjectCommit",optional=("type",))
6772
@exc.on_http_error(exc.GitlabGetError)

‎tests/functional/api/test_repository.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,28 @@ def test_commit_discussion(project):
165165
note_from_get.delete()
166166

167167

168+
deftest_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+
assertcherry_pick_commit["message"].startswith(expected_message)
184+
185+
withpytest.raises(gitlab.GitlabCherryPickError):
186+
# Two cherry pick attempts should raise GitlabCherryPickError
187+
commit.cherry_pick(branch="test")
188+
189+
168190
deftest_revert_commit(project):
169191
commit=project.commits.list()[0]
170192
revert_commit=commit.revert(branch="main")

‎tests/unit/objects/test_commits.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ def resp_commit():
3737
"short_id":"8b090c1b",
3838
"title":'Revert "Initial commit"',
3939
}
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+
}
4046

4147
withresponses.RequestsMock(assert_all_requests_are_fired=False)asrsps:
4248
rsps.add(
@@ -53,6 +59,13 @@ def resp_commit():
5359
content_type="application/json",
5460
status=200,
5561
)
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+
)
5669
yieldrsps
5770

5871

@@ -118,6 +131,18 @@ def test_create_commit(project, resp_create_commit):
118131
assertcommit.title==data["commit_message"]
119132

120133

134+
deftest_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+
assertcherry_pick_commit["short_id"]=="8b090c1b"
139+
assertcherry_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+
121146
deftest_revert_commit(project,resp_commit):
122147
commit=project.commits.get("6b2257ea",lazy=True)
123148
revert_commit=commit.revert(branch="main")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp