Commit 6b04a5f9 authored by Marin Jankovski's avatar Marin Jankovski Committed by Dmitriy Zaporozhets

Add support for Jira ticket mentions in format JIRA-123.

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>

Conflicts:
	CHANGELOG-EE
parent 1f1c59b6
...@@ -2,7 +2,7 @@ GitLab has a great issue tracker but you can also use an external issue tracker ...@@ -2,7 +2,7 @@ GitLab has a great issue tracker but you can also use an external issue tracker
- the 'Issues' link on the GitLab project pages takes you to the appropriate JIRA issue index; - the 'Issues' link on the GitLab project pages takes you to the appropriate JIRA issue index;
- clicking 'New issue' on the project dashboard creates a new JIRA issue; - clicking 'New issue' on the project dashboard creates a new JIRA issue;
- To reference JIRA issue PROJECT-1234 in comments, use syntax #PROJECT-1234. Commit messages get turned into HTML links to the corresponding JIRA issue. - To reference JIRA issue PROJECT-1234 in comments, use syntax PROJECT-1234. Commit messages get turned into HTML links to the corresponding JIRA issue.
![jira screenshot](jira-integration-points.png) ![jira screenshot](jira-integration-points.png)
......
...@@ -98,6 +98,7 @@ module Gitlab ...@@ -98,6 +98,7 @@ module Gitlab
(?<prefix>\W)? # Prefix (?<prefix>\W)? # Prefix
( # Reference ( # Reference
@(?<user>[a-zA-Z][a-zA-Z0-9_\-\.]*) # User name @(?<user>[a-zA-Z][a-zA-Z0-9_\-\.]*) # User name
|(?<issue>([A-Z\-]+-)\d+) # JIRA Issue ID
|\#(?<issue>([a-zA-Z\-]+-)?\d+) # Issue ID |\#(?<issue>([a-zA-Z\-]+-)?\d+) # Issue ID
|!(?<merge_request>\d+) # MR ID |!(?<merge_request>\d+) # MR ID
|\$(?<snippet>\d+) # Snippet ID |\$(?<snippet>\d+) # Snippet ID
...@@ -172,12 +173,16 @@ module Gitlab ...@@ -172,12 +173,16 @@ module Gitlab
end end
def reference_issue(identifier) def reference_issue(identifier)
if @project.used_default_issues_tracker? || !external_issues_tracker_enabled?
if @project.issue_exists? identifier if @project.issue_exists? identifier
url = url_for_issue(identifier) url = url_for_issue(identifier)
title = title_for_issue(identifier) title = title_for_issue(identifier)
link_to("##{identifier}", url, html_options.merge(title: "Issue: #{title}", class: "gfm gfm-issue #{html_options[:class]}")) link_to("##{identifier}", url, html_options.merge(title: "Issue: #{title}", class: "gfm gfm-issue #{html_options[:class]}"))
end end
else
reference_jira_issue(identifier) if @project.issues_tracker == "jira"
end
end end
def reference_merge_request(identifier) def reference_merge_request(identifier)
...@@ -197,5 +202,12 @@ module Gitlab ...@@ -197,5 +202,12 @@ module Gitlab
link_to(identifier, project_commit_url(@project, commit), html_options.merge(title: commit.link_title, class: "gfm gfm-commit #{html_options[:class]}")) link_to(identifier, project_commit_url(@project, commit), html_options.merge(title: commit.link_title, class: "gfm gfm-commit #{html_options[:class]}"))
end end
end end
def reference_jira_issue(identifier)
url = url_for_issue(identifier)
title = Gitlab.config.issues_tracker[@project.issues_tracker]["title"]
link_to("#{identifier}", url, html_options.merge(title: "Issue in #{title}", class: "gfm gfm-issue #{html_options[:class]}"))
end
end end
end end
...@@ -181,6 +181,52 @@ describe GitlabMarkdownHelper do ...@@ -181,6 +181,52 @@ describe GitlabMarkdownHelper do
include_examples 'referenced object' include_examples 'referenced object'
end end
describe "referencing a Jira issue" do
let(:actual) { "Reference to JIRA-#{issue.iid}" }
let(:expected) { "http://jira.example/browse/JIRA-#{issue.iid}" }
let(:reference) { "JIRA-#{issue.iid}" }
before do
hash = { "jira" => { "title" => "JIRA tracker", "issues_url" => "http://jira.example/browse/:id" } }
Gitlab.config.stub(:issues_tracker).and_return(hash)
@project.stub(:issues_tracker).and_return("jira")
@project.stub(:issues_tracker_id).and_return("JIRA")
end
it "should link using a valid id" do
gfm(actual).should match(expected)
end
it "should link with adjacent text" do
# Wrap the reference in parenthesis
gfm(actual.gsub(reference, "(#{reference})")).should match(expected)
# Append some text to the end of the reference
gfm(actual.gsub(reference, "#{reference}, right?")).should match(expected)
end
it "should keep whitespace intact" do
actual = "Referenced #{reference} already."
expected = /Referenced <a.+>[^\s]+<\/a> already/
gfm(actual).should match(expected)
end
it "should not link with an invalid id" do
# Modify the reference string so it's still parsed, but is invalid
invalid_reference = actual.gsub(/(\d+)$/, "r45")
gfm(invalid_reference).should == invalid_reference
end
it "should include a title attribute" do
title = "Issue in JIRA tracker"
gfm(actual).should match(/title="#{title}"/)
end
it "should include standard gfm classes" do
gfm(actual).should match(/class="\s?gfm gfm-issue\s?"/)
end
end
describe "referencing a merge request" do describe "referencing a merge request" do
let(:object) { merge_request } let(:object) { merge_request }
let(:reference) { "!#{merge_request.iid}" } let(:reference) { "!#{merge_request.iid}" }
......
...@@ -11,6 +11,12 @@ describe Gitlab::ReferenceExtractor do ...@@ -11,6 +11,12 @@ describe Gitlab::ReferenceExtractor do
subject.issues.should == ["1234"] subject.issues.should == ["1234"]
end end
it 'extracts JIRA issue references' do
Gitlab.config.gitlab.stub(:issues_tracker).and_return("jira")
subject.analyze "this one talks about issue JIRA-1234"
subject.issues.should == ["JIRA-1234"]
end
it 'extracts merge request references' do it 'extracts merge request references' do
subject.analyze "and here's !43, a merge request" subject.analyze "and here's !43, a merge request"
subject.merge_requests.should == ["43"] subject.merge_requests.should == ["43"]
......
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