Commit a7ae2679 authored by Marin Jankovski's avatar Marin Jankovski

Put the call for external tracker mention in the same place as gitlab default...

Put the call for external tracker mention in the same place as gitlab default mention. Add git push service spec.
parent 03f16a95
......@@ -90,8 +90,13 @@ class Note < ActiveRecord::Base
note_options.merge!(noteable: noteable)
end
if noteable.is_a?(ExternalIssue)
project.issues_tracker.create_cross_reference_note(noteable, mentioner, author)
else
create(note_options) unless cross_reference_disallowed?(noteable, mentioner)
end
end
def create_milestone_change_note(noteable, project, author, milestone)
body = if milestone.nil?
......@@ -169,9 +174,7 @@ class Note < ActiveRecord::Base
# eg. mentioning a commit in MR comments which exists inside a MR
# should not create "mentioned in" note.
def cross_reference_disallowed?(noteable, mentioner)
if noteable.is_a?(ExternalIssue)
true
elsif mentioner.kind_of?(MergeRequest)
if mentioner.kind_of?(MergeRequest)
mentioner.commits.map(&:id).include? noteable.id
end
end
......
......@@ -54,8 +54,15 @@ class JiraService < IssueTrackerService
close_issue(push, issue.id) if issue
end
def create_cross_reference_note(mentioned, noteable, author, project)
def create_cross_reference_note(mentioned, noteable, author)
issue_name = mentioned.id
project = self.project
noteable_name = noteable.class.name.downcase.to_sym
noteable_id = if noteable.is_a?(Commit)
noteable.id
else
noteable.iid
end
data = {
user: {
......@@ -68,7 +75,7 @@ class JiraService < IssueTrackerService
},
entity: {
name: noteable.class.name.underscore.humanize.downcase,
url: resource_url(polymorphic_url([project, noteable], routing_type: :path))
url: resource_url(polymorphic_url([project, noteable_name], id: noteable_id, routing_type: :path))
}
}
......
......@@ -15,14 +15,10 @@ module Notes
# Create a cross-reference note if this Note contains GFM that names an
# issue, merge request, or commit.
note.references.each do |mentioned|
if mentioned.is_a?(ExternalIssue)
note.project.issues_tracker.create_cross_reference_note(mentioned, note.noteable, note.author, note.project)
else
Note.create_cross_reference_note(mentioned, note.noteable, note.author, note.project)
end
end
end
end
note
end
......
......@@ -238,7 +238,8 @@ describe GitPushService do
end
context "for jira issue tracker" do
let(:api_url) { 'http://jira.example/rest/api/2/issue/JIRA-1/transitions' }
let(:api_transition_url) { 'http://jira.example/rest/api/2/issue/JIRA-1/transitions' }
let(:api_mention_url) { 'http://jira.example/rest/api/2/issue/JIRA-1/comment' }
let(:jira_tracker) { project.create_jira_service if project.jira_service.nil? }
before do
......@@ -250,7 +251,8 @@ describe GitPushService do
}
jira_tracker.update_attributes(properties: properties, active: true)
WebMock.stub_request(:post, api_url)
WebMock.stub_request(:post, api_transition_url)
WebMock.stub_request(:post, api_mention_url)
closing_commit.stub({
issue_closing_regex: Regexp.new(Gitlab.config.gitlab.issue_closing_pattern),
......@@ -266,7 +268,7 @@ describe GitPushService do
jira_tracker.destroy!
end
it "should initiate one api call to jira server" do
it "should initiate one api call to jira server to close the issue" do
message = {
'update' => {
'comment' => [{
......@@ -281,11 +283,19 @@ describe GitPushService do
}.to_json
service.execute(project, user, @oldrev, @newrev, @ref)
WebMock.should have_requested(:post, api_url).with(
WebMock.should have_requested(:post, api_transition_url).with(
body: message
).once
end
it "should initiate one api call to jira server to mention the issue" do
service.execute(project, user, @oldrev, @newrev, @ref)
WebMock.should have_requested(:post, api_mention_url).with(
body: /mentioned JIRA-1 in/
).once
end
end
end
end
......
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