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

Commit9beff0d

Browse files
authored
Merge pull request#1465 from JohnVillalovos/jlvillal/fix_1452_query_parameters
Switch mr.merge() to use post_data (was using query_data)
2 parents184b94b +8be2838 commit9beff0d

File tree

3 files changed

+140
-1
lines changed

3 files changed

+140
-1
lines changed

‎gitlab/v4/objects/merge_requests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def merge(
342342
ifmerge_when_pipeline_succeeds:
343343
data["merge_when_pipeline_succeeds"]=True
344344

345-
server_data=self.manager.gitlab.http_put(path,query_data=data,**kwargs)
345+
server_data=self.manager.gitlab.http_put(path,post_data=data,**kwargs)
346346
self._update_attrs(server_data)
347347

348348

‎tools/functional/api/test_merge_requests.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
importtime
2+
13
importpytest
24

35
importgitlab
6+
importgitlab.v4.objects
47

58

69
deftest_merge_requests(project):
@@ -95,3 +98,68 @@ def test_merge_request_merge(project):
9598
withpytest.raises(gitlab.GitlabMRClosedError):
9699
# Two merge attempts should raise GitlabMRClosedError
97100
mr.merge()
101+
102+
103+
deftest_merge_request_should_remove_source_branch(
104+
project,merge_request,wait_for_sidekiq
105+
)->None:
106+
"""Test to ensure
107+
https://github.com/python-gitlab/python-gitlab/issues/1120 is fixed.
108+
Bug reported that they could not use 'should_remove_source_branch' in
109+
mr.merge() call"""
110+
111+
source_branch="remove_source_branch"
112+
mr=merge_request(source_branch=source_branch)
113+
114+
mr.merge(should_remove_source_branch=True)
115+
116+
result=wait_for_sidekiq(timeout=60)
117+
assertresultisTrue,"sidekiq process should have terminated but did not"
118+
119+
# Wait until it is merged
120+
mr_iid=mr.iid
121+
for_inrange(60):
122+
mr=project.mergerequests.get(mr_iid)
123+
ifmr.merged_atisnotNone:
124+
break
125+
time.sleep(0.5)
126+
assertmr.merged_atisnotNone
127+
time.sleep(0.5)
128+
129+
# Ensure we can NOT get the MR branch
130+
withpytest.raises(gitlab.exceptions.GitlabGetError):
131+
project.branches.get(source_branch)
132+
133+
134+
deftest_merge_request_large_commit_message(
135+
project,merge_request,wait_for_sidekiq
136+
)->None:
137+
"""Test to ensure https://github.com/python-gitlab/python-gitlab/issues/1452
138+
is fixed.
139+
Bug reported that very long 'merge_commit_message' in mr.merge() would
140+
cause an error: 414 Request too large
141+
"""
142+
143+
source_branch="large_commit_message"
144+
mr=merge_request(source_branch=source_branch)
145+
146+
merge_commit_message="large_message\r\n"*1_000
147+
assertlen(merge_commit_message)>10_000
148+
149+
mr.merge(merge_commit_message=merge_commit_message)
150+
151+
result=wait_for_sidekiq(timeout=60)
152+
assertresultisTrue,"sidekiq process should have terminated but did not"
153+
154+
# Wait until it is merged
155+
mr_iid=mr.iid
156+
for_inrange(60):
157+
mr=project.mergerequests.get(mr_iid)
158+
ifmr.merged_atisnotNone:
159+
break
160+
time.sleep(0.5)
161+
assertmr.merged_atisnotNone
162+
time.sleep(0.5)
163+
164+
# Ensure we can get the MR branch
165+
project.branches.get(source_branch)

‎tools/functional/conftest.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,77 @@ def project(gl):
201201
print(f"Project already deleted:{e}")
202202

203203

204+
@pytest.fixture(scope="function")
205+
defmerge_request(project,wait_for_sidekiq):
206+
"""Fixture used to create a merge_request.
207+
208+
It will create a branch, add a commit to the branch, and then create a
209+
merge request against project.default_branch. The MR will be returned.
210+
211+
When finished any created merge requests and branches will be deleted.
212+
213+
NOTE: No attempt is made to restore project.default_branch to its previous
214+
state. So if the merge request is merged then its content will be in the
215+
project.default_branch branch.
216+
"""
217+
218+
to_delete= []
219+
220+
def_merge_request(*,source_branch:str):
221+
# Wait for processes to be done before we start...
222+
# NOTE(jlvillal): Sometimes the CI would give a "500 Internal Server
223+
# Error". Hoping that waiting until all other processes are done will
224+
# help with that.
225+
result=wait_for_sidekiq(timeout=60)
226+
assertresultisTrue,"sidekiq process should have terminated but did not"
227+
228+
project.refresh()# Gets us the current default branch
229+
project.branches.create(
230+
{"branch":source_branch,"ref":project.default_branch}
231+
)
232+
# NOTE(jlvillal): Must create a commit in the new branch before we can
233+
# create an MR that will work.
234+
project.files.create(
235+
{
236+
"file_path":f"README.{source_branch}",
237+
"branch":source_branch,
238+
"content":"Initial content",
239+
"commit_message":"New commit in new branch",
240+
}
241+
)
242+
mr=project.mergerequests.create(
243+
{
244+
"source_branch":source_branch,
245+
"target_branch":project.default_branch,
246+
"title":"Should remove source branch",
247+
"remove_source_branch":True,
248+
}
249+
)
250+
result=wait_for_sidekiq(timeout=60)
251+
assertresultisTrue,"sidekiq process should have terminated but did not"
252+
253+
mr_iid=mr.iid
254+
for_inrange(60):
255+
mr=project.mergerequests.get(mr_iid)
256+
ifmr.merge_status!="checking":
257+
break
258+
time.sleep(0.5)
259+
assertmr.merge_status!="checking"
260+
261+
to_delete.append((mr.iid,source_branch))
262+
returnmr
263+
264+
yield_merge_request
265+
266+
formr_iid,source_branchinto_delete:
267+
project.mergerequests.delete(mr_iid)
268+
try:
269+
project.branches.delete(source_branch)
270+
exceptgitlab.exceptions.GitlabDeleteError:
271+
# Ignore if branch was already deleted
272+
pass
273+
274+
204275
@pytest.fixture(scope="module")
205276
defproject_file(project):
206277
"""File fixture for tests requiring a project with files and branches."""

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp