summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/gitlab/closing_issue_extractor.rb2
-rw-r--r--lib/gitlab/markdown/external_issue_reference_filter.rb2
-rw-r--r--lib/gitlab/markdown/issue_reference_filter.rb2
-rw-r--r--lib/gitlab/markdown/merge_request_reference_filter.rb2
-rw-r--r--lib/gitlab/markdown/snippet_reference_filter.rb2
-rw-r--r--lib/gitlab/markdown/user_reference_filter.rb9
-rw-r--r--spec/features/gitlab_flavored_markdown_spec.rb34
-rw-r--r--spec/helpers/gitlab_markdown_helper_spec.rb10
-rw-r--r--spec/lib/gitlab/closing_issue_extractor_spec.rb70
-rw-r--r--spec/lib/gitlab/reference_extractor_spec.rb4
-rw-r--r--spec/models/merge_request_spec.rb2
-rw-r--r--spec/services/system_note_service_spec.rb10
12 files changed, 76 insertions, 73 deletions
diff --git a/lib/gitlab/closing_issue_extractor.rb b/lib/gitlab/closing_issue_extractor.rb
index ab184d95c05..aeec595782c 100644
--- a/lib/gitlab/closing_issue_extractor.rb
+++ b/lib/gitlab/closing_issue_extractor.rb
@@ -8,7 +8,7 @@ module Gitlab
def closed_by_message(message)
return [] if message.nil?
-
+
closing_statements = message.scan(ISSUE_CLOSING_REGEX).
map { |ref| ref[0] }.join(" ")
diff --git a/lib/gitlab/markdown/external_issue_reference_filter.rb b/lib/gitlab/markdown/external_issue_reference_filter.rb
index 2e74c6e45e2..afd28dd8cf3 100644
--- a/lib/gitlab/markdown/external_issue_reference_filter.rb
+++ b/lib/gitlab/markdown/external_issue_reference_filter.rb
@@ -48,7 +48,7 @@ module Gitlab
%(<a href="#{url}"
title="#{title}"
- class="#{klass}">#{issue}</a>)
+ class="#{klass}">#{match}</a>)
end
end
diff --git a/lib/gitlab/markdown/issue_reference_filter.rb b/lib/gitlab/markdown/issue_reference_filter.rb
index 2815626e247..dea04761ead 100644
--- a/lib/gitlab/markdown/issue_reference_filter.rb
+++ b/lib/gitlab/markdown/issue_reference_filter.rb
@@ -52,7 +52,7 @@ module Gitlab
%(<a href="#{url}"
title="#{title}"
- class="#{klass}">#{project_ref}##{id}</a>)
+ class="#{klass}">#{match}</a>)
else
match
end
diff --git a/lib/gitlab/markdown/merge_request_reference_filter.rb b/lib/gitlab/markdown/merge_request_reference_filter.rb
index fddc050635f..80779819485 100644
--- a/lib/gitlab/markdown/merge_request_reference_filter.rb
+++ b/lib/gitlab/markdown/merge_request_reference_filter.rb
@@ -52,7 +52,7 @@ module Gitlab
%(<a href="#{url}"
title="#{title}"
- class="#{klass}">#{project_ref}!#{id}</a>)
+ class="#{klass}">#{match}</a>)
else
match
end
diff --git a/lib/gitlab/markdown/snippet_reference_filter.rb b/lib/gitlab/markdown/snippet_reference_filter.rb
index f22f08de27c..174ba58af6c 100644
--- a/lib/gitlab/markdown/snippet_reference_filter.rb
+++ b/lib/gitlab/markdown/snippet_reference_filter.rb
@@ -52,7 +52,7 @@ module Gitlab
%(<a href="#{url}"
title="#{title}"
- class="#{klass}">#{project_ref}$#{id}</a>)
+ class="#{klass}">#{match}</a>)
else
match
end
diff --git a/lib/gitlab/markdown/user_reference_filter.rb b/lib/gitlab/markdown/user_reference_filter.rb
index ca7fd7b0338..c9972957182 100644
--- a/lib/gitlab/markdown/user_reference_filter.rb
+++ b/lib/gitlab/markdown/user_reference_filter.rb
@@ -65,7 +65,8 @@ module Gitlab
url = urls.namespace_project_url(project.namespace, project,
only_path: context[:only_path])
- %(<a href="#{url}" class="#{link_class}">@all</a>)
+ text = User.reference_prefix + 'all'
+ %(<a href="#{url}" class="#{link_class}">#{text}</a>)
end
def link_to_namespace(namespace)
@@ -83,7 +84,8 @@ module Gitlab
url = urls.group_url(group, only_path: context[:only_path])
- %(<a href="#{url}" class="#{link_class}">@#{group}</a>)
+ text = Group.reference_prefix + group
+ %(<a href="#{url}" class="#{link_class}">#{text}</a>)
end
def link_to_user(user, namespace)
@@ -91,7 +93,8 @@ module Gitlab
url = urls.user_url(user, only_path: context[:only_path])
- %(<a href="#{url}" class="#{link_class}">@#{user}</a>)
+ text = User.reference_prefix + user
+ %(<a href="#{url}" class="#{link_class}">#{text}</a>)
end
def user_can_reference_group?(group)
diff --git a/spec/features/gitlab_flavored_markdown_spec.rb b/spec/features/gitlab_flavored_markdown_spec.rb
index 133beba7b98..16d1ca55f8d 100644
--- a/spec/features/gitlab_flavored_markdown_spec.rb
+++ b/spec/features/gitlab_flavored_markdown_spec.rb
@@ -11,7 +11,7 @@ describe "GitLab Flavored Markdown", feature: true do
end
before do
- Commit.any_instance.stub(title: "fix ##{issue.iid}\n\nask @#{fred.username} for details")
+ Commit.any_instance.stub(title: "fix #{issue.to_reference}\n\nask #{fred.to_reference} for details")
end
let(:commit) { project.commit }
@@ -25,25 +25,25 @@ describe "GitLab Flavored Markdown", feature: true do
it "should render title in commits#index" do
visit namespace_project_commits_path(project.namespace, project, 'master', limit: 1)
- expect(page).to have_link("##{issue.iid}")
+ expect(page).to have_link(issue.to_reference)
end
it "should render title in commits#show" do
visit namespace_project_commit_path(project.namespace, project, commit)
- expect(page).to have_link("##{issue.iid}")
+ expect(page).to have_link(issue.to_reference)
end
it "should render description in commits#show" do
visit namespace_project_commit_path(project.namespace, project, commit)
- expect(page).to have_link("@#{fred.username}")
+ expect(page).to have_link(fred.to_reference)
end
it "should render title in repositories#branches" do
visit namespace_project_branches_path(project.namespace, project)
- expect(page).to have_link("##{issue.iid}")
+ expect(page).to have_link(issue.to_reference)
end
end
@@ -57,20 +57,20 @@ describe "GitLab Flavored Markdown", feature: true do
author: @user,
assignee: @user,
project: project,
- title: "fix ##{@other_issue.iid}",
- description: "ask @#{fred.username} for details")
+ title: "fix #{@other_issue.to_reference}",
+ description: "ask #{fred.to_reference} for details")
end
it "should render subject in issues#index" do
visit namespace_project_issues_path(project.namespace, project)
- expect(page).to have_link("##{@other_issue.iid}")
+ expect(page).to have_link(@other_issue.to_reference)
end
it "should render subject in issues#show" do
visit namespace_project_issue_path(project.namespace, project, @issue)
- expect(page).to have_link("##{@other_issue.iid}")
+ expect(page).to have_link(@other_issue.to_reference)
end
it "should render details in issues#show" do
@@ -83,19 +83,19 @@ describe "GitLab Flavored Markdown", feature: true do
describe "for merge requests" do
before do
- @merge_request = create(:merge_request, source_project: project, target_project: project, title: "fix ##{issue.iid}")
+ @merge_request = create(:merge_request, source_project: project, target_project: project, title: "fix #{issue.to_reference}")
end
it "should render title in merge_requests#index" do
visit namespace_project_merge_requests_path(project.namespace, project)
- expect(page).to have_link("##{issue.iid}")
+ expect(page).to have_link(issue.to_reference)
end
it "should render title in merge_requests#show" do
visit namespace_project_merge_request_path(project.namespace, project, @merge_request)
- expect(page).to have_link("##{issue.iid}")
+ expect(page).to have_link(issue.to_reference)
end
end
@@ -104,26 +104,26 @@ describe "GitLab Flavored Markdown", feature: true do
before do
@milestone = create(:milestone,
project: project,
- title: "fix ##{issue.iid}",
- description: "ask @#{fred.username} for details")
+ title: "fix #{issue.to_reference}",
+ description: "ask #{fred.to_reference} for details")
end
it "should render title in milestones#index" do
visit namespace_project_milestones_path(project.namespace, project)
- expect(page).to have_link("##{issue.iid}")
+ expect(page).to have_link(issue.to_reference)
end
it "should render title in milestones#show" do
visit namespace_project_milestone_path(project.namespace, project, @milestone)
- expect(page).to have_link("##{issue.iid}")
+ expect(page).to have_link(issue.to_reference)
end
it "should render description in milestones#show" do
visit namespace_project_milestone_path(project.namespace, project, @milestone)
- expect(page).to have_link("@#{fred.username}")
+ expect(page).to have_link(fred.to_reference)
end
end
end
diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb
index 0d0418f84a7..d0b200a9ff8 100644
--- a/spec/helpers/gitlab_markdown_helper_spec.rb
+++ b/spec/helpers/gitlab_markdown_helper_spec.rb
@@ -26,7 +26,7 @@ describe GitlabMarkdownHelper do
end
describe "referencing multiple objects" do
- let(:actual) { "!#{merge_request.iid} -> #{commit.id} -> ##{issue.iid}" }
+ let(:actual) { "#{merge_request.to_reference} -> #{commit.to_reference} -> #{issue.to_reference}" }
it "should link to the merge request" do
expected = namespace_project_merge_request_path(project.namespace, project, merge_request)
@@ -50,7 +50,7 @@ describe GitlabMarkdownHelper do
let(:issues) { create_list(:issue, 2, project: project) }
it 'should handle references nested in links with all the text' do
- actual = link_to_gfm("This should finally fix ##{issues[0].iid} and ##{issues[1].iid} for real", commit_path)
+ actual = link_to_gfm("This should finally fix #{issues[0].to_reference} and #{issues[1].to_reference} for real", commit_path)
doc = Nokogiri::HTML.parse(actual)
# Make sure we didn't create invalid markup
@@ -63,7 +63,7 @@ describe GitlabMarkdownHelper do
# First issue link
expect(doc.css('a')[1].attr('href')).
to eq namespace_project_issue_path(project.namespace, project, issues[0])
- expect(doc.css('a')[1].text).to eq "##{issues[0].iid}"
+ expect(doc.css('a')[1].text).to eq issues[0].to_reference
# Internal commit link
expect(doc.css('a')[2].attr('href')).to eq commit_path
@@ -72,7 +72,7 @@ describe GitlabMarkdownHelper do
# Second issue link
expect(doc.css('a')[3].attr('href')).
to eq namespace_project_issue_path(project.namespace, project, issues[1])
- expect(doc.css('a')[3].text).to eq "##{issues[1].iid}"
+ expect(doc.css('a')[3].text).to eq issues[1].to_reference
# Trailing commit link
expect(doc.css('a')[4].attr('href')).to eq commit_path
@@ -90,7 +90,7 @@ describe GitlabMarkdownHelper do
end
it "escapes HTML passed in as the body" do
- actual = "This is a <h1>test</h1> - see ##{issues[0].iid}"
+ actual = "This is a <h1>test</h1> - see #{issues[0].to_reference}"
expect(link_to_gfm(actual, commit_path)).
to match('&lt;h1&gt;test&lt;/h1&gt;')
end
diff --git a/spec/lib/gitlab/closing_issue_extractor_spec.rb b/spec/lib/gitlab/closing_issue_extractor_spec.rb
index cb7b0fbb890..63d474c0d1e 100644
--- a/spec/lib/gitlab/closing_issue_extractor_spec.rb
+++ b/spec/lib/gitlab/closing_issue_extractor_spec.rb
@@ -1,131 +1,131 @@
require 'spec_helper'
describe Gitlab::ClosingIssueExtractor do
- let(:project) { create(:project) }
- let(:issue) { create(:issue, project: project) }
- let(:iid1) { issue.iid }
+ let(:project) { create(:project) }
+ let(:issue) { create(:issue, project: project) }
+ let(:reference) { issue.to_reference }
subject { described_class.new(project, project.creator) }
describe "#closed_by_message" do
context 'with a single reference' do
it do
- message = "Awesome commit (Closes ##{iid1})"
+ message = "Awesome commit (Closes #{reference})"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "Awesome commit (closes ##{iid1})"
+ message = "Awesome commit (closes #{reference})"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "Closed ##{iid1}"
+ message = "Closed #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "closed ##{iid1}"
+ message = "closed #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "Closing ##{iid1}"
+ message = "Closing #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "closing ##{iid1}"
+ message = "closing #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "Close ##{iid1}"
+ message = "Close #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "close ##{iid1}"
+ message = "close #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "Awesome commit (Fixes ##{iid1})"
+ message = "Awesome commit (Fixes #{reference})"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "Awesome commit (fixes ##{iid1})"
+ message = "Awesome commit (fixes #{reference})"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "Fixed ##{iid1}"
+ message = "Fixed #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "fixed ##{iid1}"
+ message = "fixed #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "Fixing ##{iid1}"
+ message = "Fixing #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "fixing ##{iid1}"
+ message = "fixing #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "Fix ##{iid1}"
+ message = "Fix #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "fix ##{iid1}"
+ message = "fix #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "Awesome commit (Resolves ##{iid1})"
+ message = "Awesome commit (Resolves #{reference})"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "Awesome commit (resolves ##{iid1})"
+ message = "Awesome commit (resolves #{reference})"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "Resolved ##{iid1}"
+ message = "Resolved #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "resolved ##{iid1}"
+ message = "resolved #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "Resolving ##{iid1}"
+ message = "Resolving #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "resolving ##{iid1}"
+ message = "resolving #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "Resolve ##{iid1}"
+ message = "Resolve #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
- message = "resolve ##{iid1}"
+ message = "resolve #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
end
@@ -133,40 +133,40 @@ describe Gitlab::ClosingIssueExtractor do
context 'with multiple references' do
let(:other_issue) { create(:issue, project: project) }
let(:third_issue) { create(:issue, project: project) }
- let(:iid2) { other_issue.iid }
- let(:iid3) { third_issue.iid }
+ let(:reference2) { other_issue.to_reference }
+ let(:reference3) { third_issue.to_reference }
it 'fetches issues in single line message' do
- message = "Closes ##{iid1} and fix ##{iid2}"
+ message = "Closes #{reference} and fix ##{reference2}"
expect(subject.closed_by_message(message)).
to eq([issue, other_issue])
end
it 'fetches comma-separated issues references in single line message' do
- message = "Closes ##{iid1}, closes ##{iid2}"
+ message = "Closes #{reference}, closes ##{reference2}"
expect(subject.closed_by_message(message)).
to eq([issue, other_issue])
end
it 'fetches comma-separated issues numbers in single line message' do
- message = "Closes ##{iid1}, ##{iid2} and ##{iid3}"
+ message = "Closes #{reference}, ##{reference2} and ##{reference3}"
expect(subject.closed_by_message(message)).
to eq([issue, other_issue, third_issue])
end
it 'fetches issues in multi-line message' do
- message = "Awesome commit (closes ##{iid1})\nAlso fixes ##{iid2}"
+ message = "Awesome commit (closes #{reference})\nAlso fixes ##{reference2}"
expect(subject.closed_by_message(message)).
to eq([issue, other_issue])
end
it 'fetches issues in hybrid message' do
- message = "Awesome commit (closes ##{iid1})\n"\
- "Also fixing issues ##{iid2}, ##{iid3} and #4"
+ message = "Awesome commit (closes #{reference})\n"\
+ "Also fixing issues ##{reference2}, ##{reference3} and #4"
expect(subject.closed_by_message(message)).
to eq([issue, other_issue, third_issue])
diff --git a/spec/lib/gitlab/reference_extractor_spec.rb b/spec/lib/gitlab/reference_extractor_spec.rb
index 9801dc16554..c14f4ac6bf6 100644
--- a/spec/lib/gitlab/reference_extractor_spec.rb
+++ b/spec/lib/gitlab/reference_extractor_spec.rb
@@ -20,7 +20,7 @@ describe Gitlab::ReferenceExtractor do
@i0 = create(:issue, project: project)
@i1 = create(:issue, project: project)
- subject.analyze("##{@i0.iid}, ##{@i1.iid}, and #999.")
+ subject.analyze("#{@i0.to_reference}, #{@i1.to_reference}, and #{Issue.reference_prefix}999.")
expect(subject.issues).to eq([@i0, @i1])
end
@@ -82,7 +82,7 @@ describe Gitlab::ReferenceExtractor do
end
it 'handles project issue references' do
- subject.analyze("this refers issue #{other_project.path_with_namespace}##{issue.iid}")
+ subject.analyze("this refers issue #{issue.to_reference(project)}")
extracted = subject.issues
expect(extracted.size).to eq(1)
expect(extracted).to eq([issue])
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index 57b1b9dfcf0..0465aa34843 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -129,7 +129,7 @@ describe MergeRequest do
it 'detects issues mentioned in the description' do
issue2 = create(:issue, project: subject.project)
- subject.description = "Closes ##{issue2.iid}"
+ subject.description = "Closes #{issue2.to_reference}"
subject.project.stub(default_branch: subject.target_branch)
expect(subject.closes_issues).to include(issue2)
diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb
index 4e4cb6d19ed..ec173fa322d 100644
--- a/spec/services/system_note_service_spec.rb
+++ b/spec/services/system_note_service_spec.rb
@@ -238,13 +238,13 @@ describe SystemNoteService do
let(:mentioner) { project2.repository.commit }
it 'references the mentioning commit' do
- expect(subject.note).to eq "mentioned in commit #{project2.path_with_namespace}@#{mentioner.id}"
+ 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 #{project2.path_with_namespace}##{mentioner.iid}"
+ expect(subject.note).to eq "mentioned in issue #{mentioner.to_reference(project)}"
end
end
end
@@ -254,13 +254,13 @@ describe SystemNoteService do
let(:mentioner) { project.repository.commit }
it 'references the mentioning commit' do
- expect(subject.note).to eq "mentioned in commit #{mentioner.id}"
+ 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.iid}"
+ expect(subject.note).to eq "mentioned in issue #{mentioner.to_reference}"
end
end
end
@@ -270,7 +270,7 @@ describe SystemNoteService do
describe '.cross_reference?' do
it 'is truthy when text begins with expected text' do
- expect(described_class.cross_reference?('mentioned in issue #1')).to be_truthy
+ expect(described_class.cross_reference?('mentioned in something')).to be_truthy
end
it 'is falsey when text does not begin with expected text' do