diff --git a/lib/gitlab/qa/report/relate_failure_issue.rb b/lib/gitlab/qa/report/relate_failure_issue.rb index 1781e9d76ee0e50d74f01a6e3c463bb27fd7f210..8a35f9f9ffca63487b88de5fbc3d7d123f2382e3 100644 --- a/lib/gitlab/qa/report/relate_failure_issue.rb +++ b/lib/gitlab/qa/report/relate_failure_issue.rb @@ -189,7 +189,11 @@ module Gitlab existing_note = existing_failure_note(issue) if existing_note - gitlab.edit_issue_note(issue_iid: issue.iid, note_id: existing_note.id, note: current_note) + gitlab.edit_issue_note( + issue_iid: issue.iid, + note_id: existing_note.id, + note: "#{existing_note.body.gsub('Failed most recently in', 'Failed in')}\n#{current_note}" + ) else gitlab.create_issue_note(iid: issue.iid, note: current_note) end diff --git a/spec/gitlab/qa/report/relate_failure_issue_spec.rb b/spec/gitlab/qa/report/relate_failure_issue_spec.rb index edf1138f94366ac850c636c2c56acec293404f3d..fa21581d46e581a139f175d9eae956059c3de7cc 100644 --- a/spec/gitlab/qa/report/relate_failure_issue_spec.rb +++ b/spec/gitlab/qa/report/relate_failure_issue_spec.rb @@ -351,9 +351,11 @@ describe Gitlab::QA::Report::RelateFailureIssue do end context 'when there is an existing failure comment' do + existing_note_msg = 'Failed most recently in staging pipeline: http://job-failure-url' + updated_note_msg = 'Failed in staging pipeline: http://job-failure-url' let(:note_class) { Struct.new(:id, :body) } let(:existing_note) do - note_class.new(1, 'Failed most recently in staging pipeline: http://job-failure-url') + note_class.new(1, existing_note_msg) end it 'updates the existing comment with the failed job pipeline and url' do @@ -361,7 +363,7 @@ describe Gitlab::QA::Report::RelateFailureIssue do expect(::Gitlab).to receive(:edit_issue).with(anything, anything, { labels: ['found:staging.gitlab.com'] }) expect(subject).to receive(:post_or_update_failed_job_note).and_call_original expect(subject).to receive(:existing_failure_note).and_return(existing_note) - expect(::Gitlab).to receive(:edit_issue_note).with(project, issue.iid, existing_note.id, expected_posted_note) + expect(::Gitlab).to receive(:edit_issue_note).with(project, issue.iid, existing_note.id, "#{updated_note_msg}\n#{expected_posted_note}") expect { subject.invoke! }.to output.to_stdout end @@ -515,10 +517,12 @@ describe Gitlab::QA::Report::RelateFailureIssue do end context 'when there is an existing failure comment' do + existing_failure_msg = 'Failed most recently in staging pipeline: http://job-failure-url' + updated_failure_msg = 'Failed in staging pipeline: http://job-failure-url' let(:issue_title) { "Hello #{test_name} world!" } let(:note_class) { Struct.new(:id, :body) } let(:existing_note) do - note_class.new(1, 'Failed most recently in staging pipeline: http://job-failure-url') + note_class.new(1, existing_failure_msg) end let(:issue) do @@ -532,7 +536,7 @@ describe Gitlab::QA::Report::RelateFailureIssue do expect(::Gitlab).to receive(:edit_issue).with(project, issue.iid, { labels: ["quarantine", "quarantine::bug", 'found:staging.gitlab.com'] }) expect(subject).to receive(:post_or_update_failed_job_note).and_call_original expect(subject).to receive(:existing_failure_note).and_return(existing_note) - expect(::Gitlab).to receive(:edit_issue_note).with(project, issue.iid, existing_note.id, expected_posted_note) + expect(::Gitlab).to receive(:edit_issue_note).with(project, issue.iid, existing_note.id, "#{updated_failure_msg}\n#{expected_posted_note}") expect { subject.invoke! }.to output.to_stdout end