From 85dd05b5b3afb27743998b4f3f9f042b5b5bfa81 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Wed, 9 Nov 2016 19:55:21 -0200 Subject: Add JIRA remotelinks and prevent duplicated closing messages --- spec/services/system_note_service_spec.rb | 45 +++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'spec/services/system_note_service_spec.rb') diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb index 5bb107fdd85..56d39e9a005 100644 --- a/spec/services/system_note_service_spec.rb +++ b/spec/services/system_note_service_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe SystemNoteService, services: true do + include Gitlab::Routing.url_helpers + let(:project) { create(:project) } let(:author) { create(:user) } let(:noteable) { create(:issue, project: project) } @@ -543,23 +545,55 @@ describe SystemNoteService, services: true do before { stub_jira_urls(jira_issue.id) } - context 'in JIRA issue tracker' do + context 'in issue' do before { jira_service_settings } describe "new reference" do subject { described_class.cross_reference(jira_issue, commit, author) } it { is_expected.to eq(success_message) } + + it "creates remote link" do + subject + + expect(WebMock).to have_requested(:post, jira_api_remote_link_url(jira_issue)).with( + body: hash_including( + GlobalID: "GitLab", + object: { + url: namespace_project_commit_url(project.namespace, project, commit), + title: "GitLab: Mentioned on commit - #{commit.title}", + icon: { title: "GitLab", url16x16: "https://gitlab.com/favicon.ico" }, + status: { resolved: false } + } + ) + ).once + end end end - context 'issue from an issue' do + context 'in commit' do context 'in JIRA issue tracker' do before { jira_service_settings } subject { described_class.cross_reference(jira_issue, issue, author) } it { is_expected.to eq(success_message) } + + it "creates remote link" do + subject + + expect(WebMock).to have_requested(:post, jira_api_remote_link_url(jira_issue)).with( + body: hash_including( + GlobalID: "GitLab", + object: { + url: namespace_project_issue_url(project.namespace, project, issue), + title: "GitLab: Mentioned on issue - #{issue.title}", + icon: { title: "GitLab", url16x16: "https://gitlab.com/favicon.ico" }, + status: { resolved: false } + } + ) + ).once + end end end @@ -572,6 +606,13 @@ describe SystemNoteService, services: true do subject { described_class.cross_reference(jira_issue, commit, author) } it { is_expected.not_to eq(success_message) } + + it 'does not try to create comment and remote link' do + subject + + expect(WebMock).not_to have_requested(:post, jira_api_comment_url(jira_issue)) + expect(WebMock).not_to have_requested(:post, jira_api_remote_link_url(jira_issue)) + end end end end -- cgit v1.2.1 From d399e1ae2b92bc399962a286fddc59eaa09670a7 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Mon, 14 Nov 2016 19:30:01 -0200 Subject: Allow enabling and disabling commit and MR events for JIRA --- spec/services/system_note_service_spec.rb | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'spec/services/system_note_service_spec.rb') diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb index 56d39e9a005..150e21574a1 100644 --- a/spec/services/system_note_service_spec.rb +++ b/spec/services/system_note_service_spec.rb @@ -536,7 +536,7 @@ describe SystemNoteService, services: true do let(:project) { create(:jira_project) } let(:author) { create(:user) } let(:issue) { create(:issue, project: project) } - let(:mergereq) { create(:merge_request, :simple, target_project: project, source_project: project) } + let(:merge_request) { create(:merge_request, :simple, target_project: project, source_project: project) } let(:jira_issue) { ExternalIssue.new("JIRA-1", project)} let(:jira_tracker) { project.jira_service } let(:commit) { project.commit } @@ -545,7 +545,31 @@ describe SystemNoteService, services: true do before { stub_jira_urls(jira_issue.id) } - context 'in issue' do + noteable_types = ["merge_requests", "commit"] + + noteable_types.each do |type| + context "when noteable is a #{type}" do + it "blocks cross reference when #{type.underscore}_events is false" do + jira_tracker.update("#{type}_events" => false) + + noteable = type == "commit" ? commit : merge_request + result = described_class.cross_reference(jira_issue, noteable, author) + + expect(result).to eq("Events for #{noteable.class.to_s.underscore.humanize.pluralize.downcase} are disabled.") + end + + it "blocks cross reference when #{type.underscore}_events is true" do + jira_tracker.update("#{type}_events" => true) + + noteable = type == "commit" ? commit : merge_request + result = described_class.cross_reference(jira_issue, noteable, author) + + expect(result).to eq(success_message) + end + end + end + + context 'in JIRA issue tracker' do before { jira_service_settings } describe "new reference" do -- cgit v1.2.1 From bd3ae192bb62d522912281b5943073f6ad444fe4 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 21 Nov 2016 10:55:54 +0100 Subject: Rename MWPS in system notes and related tests --- spec/services/system_note_service_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/services/system_note_service_spec.rb') diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb index 56d39e9a005..7f0da4bf03c 100644 --- a/spec/services/system_note_service_spec.rb +++ b/spec/services/system_note_service_spec.rb @@ -225,8 +225,8 @@ describe SystemNoteService, services: true do it_behaves_like 'a system note' - it "posts the Merge When Build Succeeds system note" do - expect(subject.note).to match /Enabled an automatic merge when the build for (\w+\/\w+@)?[0-9a-f]{40} succeeds/ + it "posts the 'merge when pipeline succeeds' system note" do + expect(subject.note).to match /Enabled an automatic merge when the pipeline for (\w+\/\w+@)?[0-9a-f]{40} succeeds/ end end @@ -239,7 +239,7 @@ describe SystemNoteService, services: true do it_behaves_like 'a system note' - it "posts the Merge When Build Succeeds system note" do + it "posts the 'merge when pipeline succeeds' system note" do expect(subject.note).to eq "Canceled the automatic merge" end end -- cgit v1.2.1 From 9c740133a3bb4e992ccd7e3801402e4eab537e29 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Thu, 17 Nov 2016 18:46:31 -0200 Subject: Allow JIRA references for project snippets --- spec/services/system_note_service_spec.rb | 65 +++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 17 deletions(-) (limited to 'spec/services/system_note_service_spec.rb') diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb index 150e21574a1..2a5709c6322 100644 --- a/spec/services/system_note_service_spec.rb +++ b/spec/services/system_note_service_spec.rb @@ -543,7 +543,10 @@ describe SystemNoteService, services: true do let(:comment_url) { jira_api_comment_url(jira_issue.id) } let(:success_message) { "JiraService SUCCESS: Successfully posted to http://jira.example.net." } - before { stub_jira_urls(jira_issue.id) } + before do + stub_jira_urls(jira_issue.id) + jira_service_settings + end noteable_types = ["merge_requests", "commit"] @@ -569,16 +572,16 @@ describe SystemNoteService, services: true do end end - context 'in JIRA issue tracker' do - before { jira_service_settings } - - describe "new reference" do - subject { described_class.cross_reference(jira_issue, commit, author) } + describe "new reference" do + context 'for commits' do + it "creates comment" do + result = described_class.cross_reference(jira_issue, commit, author) - it { is_expected.to eq(success_message) } + expect(result).to eq(success_message) + end it "creates remote link" do - subject + described_class.cross_reference(jira_issue, commit, author) expect(WebMock).to have_requested(:post, jira_api_remote_link_url(jira_issue)).with( body: hash_including( @@ -593,18 +596,18 @@ describe SystemNoteService, services: true do ).once end end - end - context 'in commit' do - context 'in JIRA issue tracker' do - before { jira_service_settings } + context 'for issues' do + let(:issue) { create(:issue, project: project) } - subject { described_class.cross_reference(jira_issue, issue, author) } + it "creates comment" do + result = described_class.cross_reference(jira_issue, issue, author) - it { is_expected.to eq(success_message) } + expect(result).to eq(success_message) + end it "creates remote link" do - subject + described_class.cross_reference(jira_issue, issue, author) expect(WebMock).to have_requested(:post, jira_api_remote_link_url(jira_issue)).with( body: hash_including( @@ -619,6 +622,32 @@ describe SystemNoteService, services: true do ).once end end + + context 'for snippets' do + let(:snippet) { create(:snippet, project: project) } + + it "creates comment" do + result = described_class.cross_reference(jira_issue, snippet, author) + + expect(result).to eq(success_message) + end + + it "creates remote link" do + described_class.cross_reference(jira_issue, snippet, author) + + expect(WebMock).to have_requested(:post, jira_api_remote_link_url(jira_issue)).with( + body: hash_including( + GlobalID: "GitLab", + object: { + url: namespace_project_snippet_url(project.namespace, project, snippet), + title: "GitLab: Mentioned on snippet - #{snippet.title}", + icon: { title: "GitLab", url16x16: "https://gitlab.com/favicon.ico" }, + status: { resolved: false } + } + ) + ).once + end + end end describe "existing reference" do @@ -627,9 +656,11 @@ describe SystemNoteService, services: true do allow_any_instance_of(JIRA::Resource::Issue).to receive(:comments).and_return([OpenStruct.new(body: message)]) end - subject { described_class.cross_reference(jira_issue, commit, author) } + it "does not return success message" do + result = described_class.cross_reference(jira_issue, commit, author) - it { is_expected.not_to eq(success_message) } + expect(result).not_to eq(success_message) + end it 'does not try to create comment and remote link' do subject -- cgit v1.2.1 From 6df22f72c6c312199c547e017ce1f947cf88e34c Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Wed, 23 Nov 2016 14:55:23 +0800 Subject: Rephrase some system notes to be compatible with new system note style --- spec/services/system_note_service_spec.rb | 90 ++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 24 deletions(-) (limited to 'spec/services/system_note_service_spec.rb') diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb index 2a5709c6322..4a8f6c321aa 100644 --- a/spec/services/system_note_service_spec.rb +++ b/spec/services/system_note_service_spec.rb @@ -50,7 +50,7 @@ describe SystemNoteService, services: true do context 'without existing commits' do it 'adds a message header' do - expect(note_lines[0]).to eq "Added #{new_commits.size} commits:" + expect(note_lines[0]).to eq "added #{new_commits.size} commits" end it 'adds a message line for each commit' do @@ -120,7 +120,7 @@ describe SystemNoteService, services: true do context 'when assignee added' do it 'sets the note text' do - expect(subject.note).to eq "Reassigned to @#{assignee.username}" + expect(subject.note).to eq "assigned to @#{assignee.username}" end end @@ -128,7 +128,7 @@ describe SystemNoteService, services: true do let(:assignee) { nil } it 'sets the note text' do - expect(subject.note).to eq 'Assignee removed' + expect(subject.note).to eq 'removed assignee' end end end @@ -147,7 +147,7 @@ describe SystemNoteService, services: true do let(:removed) { [] } it 'sets the note text' do - expect(subject.note).to eq "Added ~#{labels[0].id} ~#{labels[1].id} labels" + expect(subject.note).to eq "added ~#{labels[0].id} ~#{labels[1].id} labels" end end @@ -156,7 +156,7 @@ describe SystemNoteService, services: true do let(:removed) { labels } it 'sets the note text' do - expect(subject.note).to eq "Removed ~#{labels[0].id} ~#{labels[1].id} labels" + expect(subject.note).to eq "removed ~#{labels[0].id} ~#{labels[1].id} labels" end end @@ -165,7 +165,7 @@ describe SystemNoteService, services: true do let(:removed) { [labels[1]] } it 'sets the note text' do - expect(subject.note).to eq "Added ~#{labels[0].id} and removed ~#{labels[1].id} labels" + expect(subject.note).to eq "added ~#{labels[0].id} and removed ~#{labels[1].id} labels" end end end @@ -179,7 +179,7 @@ describe SystemNoteService, services: true do context 'when milestone added' do it 'sets the note text' do - expect(subject.note).to eq "Milestone changed to #{milestone.to_reference}" + expect(subject.note).to eq "changed milestone to #{milestone.to_reference}" end end @@ -187,7 +187,7 @@ describe SystemNoteService, services: true do let(:milestone) { nil } it 'sets the note text' do - expect(subject.note).to eq 'Milestone removed' + expect(subject.note).to eq 'removed milestone' end end end @@ -204,13 +204,13 @@ describe SystemNoteService, services: true do let(:source) { double('commit', gfm_reference: 'commit 123456') } it 'sets the note text' do - expect(subject.note).to eq "Status changed to #{status} by commit 123456" + expect(subject.note).to eq "#{status} via commit 123456" end end context 'without a source' do it 'sets the note text' do - expect(subject.note).to eq "Status changed to #{status}" + expect(subject.note).to eq status end end end @@ -226,7 +226,7 @@ describe SystemNoteService, services: true do it_behaves_like 'a system note' it "posts the Merge When Build Succeeds system note" do - expect(subject.note).to match /Enabled an automatic merge when the build for (\w+\/\w+@)?[0-9a-f]{40} succeeds/ + expect(subject.note).to match /enabled an automatic merge when the build for (\w+\/\w+@)?\h{40} succeeds/ end end @@ -240,7 +240,7 @@ describe SystemNoteService, services: true do it_behaves_like 'a system note' it "posts the Merge When Build Succeeds system note" do - expect(subject.note).to eq "Canceled the automatic merge" + expect(subject.note).to eq "canceled the automatic merge" end end @@ -252,7 +252,7 @@ describe SystemNoteService, services: true do it 'sets the note text' do expect(subject.note). - to eq "Changed title: **{-Old title-}** → **{+#{noteable.title}+}**" + to eq "changed title from **{-Old title-}** to **{+#{noteable.title}+}**" end end end @@ -264,7 +264,7 @@ describe SystemNoteService, services: true do it_behaves_like 'a system note' it 'sets the note text' do - expect(subject.note).to eq 'Made the issue visible' + expect(subject.note).to eq 'made the issue visible to everyone' end end end @@ -278,7 +278,7 @@ describe SystemNoteService, services: true do context 'when target branch name changed' do it 'sets the note text' do - expect(subject.note).to eq "Target branch changed from `#{old_branch}` to `#{new_branch}`" + expect(subject.note).to eq "changed target branch from `#{old_branch}` to `#{new_branch}`" end end end @@ -290,7 +290,7 @@ describe SystemNoteService, services: true do context 'when source branch deleted' do it 'sets the note text' do - expect(subject.note).to eq "Deleted source branch `feature`" + expect(subject.note).to eq "deleted source branch `feature`" end end end @@ -302,7 +302,7 @@ describe SystemNoteService, services: true do context 'when a branch is created from the new branch button' do it 'sets the note text' do - expect(subject.note).to match /\AStarted branch [`1-mepmep`]/ + expect(subject.note).to match /\Acreated branch [`1-mepmep`]/ end end end @@ -338,13 +338,13 @@ describe SystemNoteService, services: true do let(:mentioner) { project2.repository.commit } it 'references the mentioning commit' do - expect(subject.note).to eq "Mentioned in commit #{mentioner.to_reference(project)}" + expect(subject.note).to eq "mentioned in commit #{mentioner.to_reference(project)}" end end context 'from non-Commit' do it 'references the mentioning object' do - expect(subject.note).to eq "Mentioned in issue #{mentioner.to_reference(project)}" + expect(subject.note).to eq "mentioned in issue #{mentioner.to_reference(project)}" end end end @@ -354,13 +354,13 @@ describe SystemNoteService, services: true do let(:mentioner) { project.repository.commit } it 'references the mentioning commit' do - expect(subject.note).to eq "Mentioned in commit #{mentioner.to_reference}" + expect(subject.note).to eq "mentioned in commit #{mentioner.to_reference}" end end context 'from non-Commit' do it 'references the mentioning object' do - expect(subject.note).to eq "Mentioned in issue #{mentioner.to_reference}" + expect(subject.note).to eq "mentioned in issue #{mentioner.to_reference}" end end end @@ -370,7 +370,11 @@ describe SystemNoteService, services: true do describe '.cross_reference?' do it 'is truthy when text begins with expected text' do - expect(described_class.cross_reference?('Mentioned in something')).to be_truthy + expect(described_class.cross_reference?('mentioned in something')).to be_truthy + end + + it 'is truthy when text begins with legacy capitalized expected text' do + expect(described_class.cross_reference?('mentioned in something')).to be_truthy end it 'is falsey when text does not begin with expected text' do @@ -433,6 +437,19 @@ describe SystemNoteService, services: true do expect(described_class.cross_reference_exists?(noteable, commit1)). to be_falsey end + + context 'legacy capitalized cross reference' do + before do + # Mention issue (noteable) from commit0 + system_note = described_class.cross_reference(noteable, commit0, author) + system_note.update(note: system_note.note.capitalize) + end + + it 'is truthy when already mentioned' do + expect(described_class.cross_reference_exists?(noteable, commit0)). + to be_truthy + end + end end context 'commit from commit' do @@ -450,6 +467,19 @@ describe SystemNoteService, services: true do expect(described_class.cross_reference_exists?(commit1, commit0)). to be_falsey end + + context 'legacy capitalized cross reference' do + before do + # Mention commit1 from commit0 + system_note = described_class.cross_reference(commit0, commit1, author) + system_note.update(note: system_note.note.capitalize) + end + + it 'is truthy when already mentioned' do + expect(described_class.cross_reference_exists?(commit0, commit1)). + to be_truthy + end + end end context 'commit with cross-reference from fork' do @@ -465,6 +495,18 @@ describe SystemNoteService, services: true do expect(described_class.cross_reference_exists?(noteable, commit2)). to be true end + + context 'legacy capitalized cross reference' do + before do + system_note = described_class.cross_reference(noteable, commit0, author2) + system_note.update(note: system_note.note.capitalize) + end + + it 'is true when a fork mentions an external issue' do + expect(described_class.cross_reference_exists?(noteable, commit2)). + to be true + end + end end end @@ -498,7 +540,7 @@ describe SystemNoteService, services: true do it_behaves_like 'cross project mentionable' it 'notifies about noteable being moved to' do - expect(subject.note).to match /Moved to/ + expect(subject.note).to match /moved to/ end end @@ -508,7 +550,7 @@ describe SystemNoteService, services: true do it_behaves_like 'cross project mentionable' it 'notifies about noteable being moved from' do - expect(subject.note).to match /Moved from/ + expect(subject.note).to match /moved from/ end end -- cgit v1.2.1 From f272ee6eba37548cbd8919139d583a71ffdac8dc Mon Sep 17 00:00:00 2001 From: Oswaldo Ferreira Date: Wed, 2 Nov 2016 21:49:13 -0200 Subject: Add shorthand support to gitlab markdown references --- spec/services/system_note_service_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/services/system_note_service_spec.rb') diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb index 4a8f6c321aa..835d7467bd9 100644 --- a/spec/services/system_note_service_spec.rb +++ b/spec/services/system_note_service_spec.rb @@ -530,7 +530,7 @@ describe SystemNoteService, services: true do end it 'mentions referenced project' do - expect(subject.note).to include new_project.to_reference + expect(subject.note).to include new_project.path_with_namespace end end -- cgit v1.2.1 From 1123057ab792ac73b1611f4d3a9faf79369dd6da Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Wed, 26 Oct 2016 23:21:50 +0200 Subject: Feature: delegate all open discussions to Issue When a merge request can only be merged when all discussions are resolved. This feature allows to easily delegate those discussions to a new issue, while marking them as resolved in the merge request. The user is presented with a new issue, prepared with mentions of all unresolved discussions, including the first unresolved note of the discussion, time and link to the note. When the issue is created, the discussions in the merge request will get a system note directing the user to the newly created issue. --- spec/services/system_note_service_spec.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'spec/services/system_note_service_spec.rb') diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb index 435cfb07292..07a9d8e1997 100644 --- a/spec/services/system_note_service_spec.rb +++ b/spec/services/system_note_service_spec.rb @@ -712,4 +712,32 @@ describe SystemNoteService, services: true do end end end + + describe '.discussion_continued_in_issue' do + let(:discussion) { Discussion.for_diff_notes([create(:diff_note_on_merge_request)]).first } + let(:merge_request) { discussion.noteable } + let(:project) { merge_request.source_project } + let(:issue) { create(:issue, project: project) } + let(:user) { create(:user) } + + def reloaded_merge_request + MergeRequest.find(merge_request.id) + end + + before do + project.team << [user, :developer] + end + + it 'creates a new note in the discussion' do + # we need to completely rebuild the merge request object, or the `@discussions` on the merge request are not reloaded. + expect { SystemNoteService.discussion_continued_in_issue(discussion, project, user, issue) }. + to change { reloaded_merge_request.discussions.first.notes.size }.by(1) + end + + it 'mentions the created issue in the system note' do + note = SystemNoteService.discussion_continued_in_issue(discussion, project, user, issue) + + expect(note.note).to include(issue.to_reference) + end + end end -- cgit v1.2.1 From 549242c620a812b4ed0f1a3b08f3e315027b9e65 Mon Sep 17 00:00:00 2001 From: Julian Zinn Date: Fri, 4 Nov 2016 12:36:37 -0700 Subject: For single line git commit messages, the close quote should be on the same line as the open quote MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- spec/services/system_note_service_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/services/system_note_service_spec.rb') diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb index 90b7e62bc6f..0e8adb68721 100644 --- a/spec/services/system_note_service_spec.rb +++ b/spec/services/system_note_service_spec.rb @@ -694,7 +694,7 @@ describe SystemNoteService, services: true do describe "existing reference" do before do - message = "[#{author.name}|http://localhost/#{author.username}] mentioned this issue in [a commit of #{project.path_with_namespace}|http://localhost/#{project.path_with_namespace}/commit/#{commit.id}]:\n'#{commit.title}'" + message = "[#{author.name}|http://localhost/#{author.username}] mentioned this issue in [a commit of #{project.path_with_namespace}|http://localhost/#{project.path_with_namespace}/commit/#{commit.id}]:\n'#{commit.title.chomp}'" allow_any_instance_of(JIRA::Resource::Issue).to receive(:comments).and_return([OpenStruct.new(body: message)]) end -- cgit v1.2.1