Commit 0942dc0f authored by Rémy Coutable's avatar Rémy Coutable 🏖

Ensure the in progress MR is an UpstreamMergeRequest object

Signed-off-by: Rémy Coutable's avatarRémy Coutable <remy@rymai.me>
parent 51b8454e
......@@ -44,7 +44,9 @@ module Services
end
def open_merge_requests
@open_merge_requests ||= UpstreamMergeRequest.open_mrs
@open_merge_requests ||= UpstreamMergeRequest.open_mrs.map do |upstream_mr|
UpstreamMergeRequest.new(upstream_mr.to_h)
end
end
end
end
......@@ -15,9 +15,8 @@ class SlackWebhook
end
def self.existing_merge_request(merge_request)
created_at = Time.parse(merge_request.created_at)
text = <<~SLACK_MESSAGE.strip
Tried to create a new merge request but <#{merge_request.url}|this one> from #{TimeUtil.time_ago(created_at)} is still pending!
Tried to create a new merge request but <#{merge_request.url}|this one> from #{TimeUtil.time_ago(merge_request.created_at)} is still pending!
SLACK_MESSAGE
new.fire_hook(text: text)
......
This diff is collapsed.
......@@ -50,19 +50,17 @@ describe Services::UpstreamMergeService do
end
describe '#perform' do
context 'when open upstream MR exists' do
context 'when open upstream MR exists', vcr: { cassette_name: 'merge_requests/existing_upstream_mr' } do
context 'when not forced' do
let(:in_progress_mr) { double(web_url: 'http://foo.bar') }
before do
expect(UpstreamMergeRequest).to receive(:open_mrs).and_return([in_progress_mr])
end
it 'returns a non-successful result object' do
result = subject.perform
expect(result).not_to be_success
expect(result.payload).to eq({ in_progress_mr: in_progress_mr })
in_progress_mr = result.payload[:in_progress_mr]
expect(in_progress_mr).to be_an_instance_of(UpstreamMergeRequest)
expect(in_progress_mr.created_at).to be_an_instance_of(Time)
expect(in_progress_mr.url).to eq('https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/4023')
end
end
......
......@@ -10,7 +10,7 @@ describe SlackWebhook do
let(:text) { 'Hello!' }
let(:response_class) { Struct.new(:code) }
let(:response) { response_class.new(200) }
let(:merge_request) { double(url: 'http://gitlab.com/mr', created_at: Time.new(2018, 1, 4, 6).to_s) }
let(:merge_request) { double(url: 'http://gitlab.com/mr', created_at: Time.new(2018, 1, 4, 6)) }
around do |ex|
ClimateControl.modify CI_SLACK_WEBHOOK_URL: CI_SLACK_WEBHOOK_URL, CI_JOB_ID: CI_JOB_ID do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment