diff --git a/gems/gitlab-housekeeper/lib/gitlab/housekeeper/runner.rb b/gems/gitlab-housekeeper/lib/gitlab/housekeeper/runner.rb index 1826dff3f7f22c2f97ad1354eaaac342a7c2ae0d..e6a28a92512bc1537b2c80e4815d57ad73f32590 100644 --- a/gems/gitlab-housekeeper/lib/gitlab/housekeeper/runner.rb +++ b/gems/gitlab-housekeeper/lib/gitlab/housekeeper/runner.rb @@ -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 diff --git a/gems/gitlab-housekeeper/spec/gitlab/housekeeper/gitlab_client_spec.rb b/gems/gitlab-housekeeper/spec/gitlab/housekeeper/gitlab_client_spec.rb index c52a98058e3a6510c020c599b4f4a0d56b4df8fb..c6595a4326e9d0b2cd4ed08d2e541b6f7b2d1813 100644 --- a/gems/gitlab-housekeeper/spec/gitlab/housekeeper/gitlab_client_spec.rb +++ b/gems/gitlab-housekeeper/spec/gitlab/housekeeper/gitlab_client_spec.rb @@ -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 diff --git a/gems/gitlab-housekeeper/spec/gitlab/housekeeper/runner_spec.rb b/gems/gitlab-housekeeper/spec/gitlab/housekeeper/runner_spec.rb index 13f58f52771a1a685d14507c50b7ea8c7dfed587..38674d35f310f73ef9b617bd590422da6c9c5850 100644 --- a/gems/gitlab-housekeeper/spec/gitlab/housekeeper/runner_spec.rb +++ b/gems/gitlab-housekeeper/spec/gitlab/housekeeper/runner_spec.rb @@ -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