Skip to content
代码片段 群组 项目
提交 bce46d6e 编辑于 作者: Dylan Griffith's avatar Dylan Griffith
浏览文件

Print created MR URL in gitlab-housekeeper

This adds logic to print the newly created (or updated) merge request
URL. This will be a nice shortcut for the user to jump to the MR and
double check it.
上级 33ece4d3
No related branches found
No related tags found
无相关合并请求
......@@ -116,7 +116,7 @@ def create(change, branch_name)
Shell.execute('git', 'push', '-f', 'housekeeper', "#{branch_name}:#{branch_name}")
end
gitlab_client.create_or_update_merge_request(
mr = gitlab_client.create_or_update_merge_request(
change: change,
source_project_id: housekeeper_fork_project_id,
source_branch: branch_name,
......@@ -127,6 +127,8 @@ def create(change, branch_name)
update_labels: !non_housekeeper_changes.include?(:labels),
update_reviewers: !non_housekeeper_changes.include?(:reviewers)
)
puts "Merge request URL: #{mr['web_url'].yellowish}"
end
def housekeeper_fork_project_id
......
......@@ -274,6 +274,10 @@
end
it 'calls the GitLab API passing the token' do
api_response = {
iid: 5678,
web_url: 'https://example.com/api/v4/merge_requests/abc123/5678'
}
stub = stub_request(:post, "https://gitlab.com/api/v4/projects/123/merge_requests")
.with(
body: {
......@@ -290,11 +294,14 @@
'Content-Type' => 'application/json',
'Private-Token' => 'the-api-token'
})
.to_return(status: 200, body: '{}')
.to_return(status: 200, body: api_response.to_json)
client.create_or_update_merge_request(**params)
result = client.create_or_update_merge_request(**params)
expect(stub).to have_been_requested
expect(result['iid']).to eq(5678)
expect(result['web_url']).to eq('https://example.com/api/v4/merge_requests/abc123/5678')
end
context 'when the merge request for the branch already exists' do
......@@ -303,6 +310,10 @@
end
it 'updates the merge request' do
api_response = {
iid: 1234,
web_url: 'https://example.com/api/v4/merge_requests/abc123/1234'
}
stub = stub_request(:put, "https://gitlab.com/api/v4/projects/456/merge_requests/1234")
.with(
body: {
......@@ -315,10 +326,13 @@
'Content-Type' => 'application/json',
'Private-Token' => 'the-api-token'
})
.to_return(status: 200, body: '{}')
.to_return(status: 200, body: api_response.to_json)
client.create_or_update_merge_request(**params)
result = client.create_or_update_merge_request(**params)
expect(stub).to have_been_requested
expect(result['iid']).to eq(1234)
expect(result['web_url']).to eq('https://example.com/api/v4/merge_requests/abc123/1234')
end
context 'when multiple merge requests exist' do
......
......@@ -98,7 +98,7 @@
update_description: true,
update_labels: true,
update_reviewers: true
)
).and_return({ 'web_url' => 'https://example.com' })
expect(gitlab_client).to receive(:create_or_update_merge_request)
.with(
change: change2,
......@@ -110,7 +110,7 @@
update_description: true,
update_labels: true,
update_reviewers: true
)
).and_return({ 'web_url' => 'https://example.com' })
described_class.new(max_mrs: 2, keeps: [fake_keep]).run
end
......@@ -142,7 +142,7 @@
update_description: true,
update_labels: true,
update_reviewers: true
)
).and_return({ 'web_url' => 'https://example.com' })
described_class.new(max_mrs: 2, keeps: [fake_keep], filter_identifiers: [/second/]).run
end
......@@ -186,7 +186,7 @@
update_description: false,
update_labels: true,
update_reviewers: false
)
).and_return({ 'web_url' => 'https://example.com' })
expect(gitlab_client).to receive(:create_or_update_merge_request)
.with(
change: change2,
......@@ -198,7 +198,7 @@
update_description: false,
update_labels: true,
update_reviewers: true
)
).and_return({ 'web_url' => 'https://example.com' })
described_class.new(max_mrs: 2, keeps: [fake_keep]).run
end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册