Commit 4d8b9cfe authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '227099-jira-serializer-author-link' into 'master'

Add author link to the Jira issue entity

See merge request gitlab-org/gitlab!36310
parents 6c00ffc5 9a286f3c
......@@ -39,7 +39,8 @@ module Integrations
expose :author do |jira_issue|
{
name: jira_issue.reporter.displayName
name: jira_issue.reporter.displayName,
web_url: author_web_url(jira_issue)
}
end
......@@ -68,6 +69,19 @@ module Integrations
expose :external_tracker do |_jira_issue|
'jira'
end
private
def author_web_url(jira_issue)
# There are differences between Jira Cloud and Jira Server URLs and responses.
# accountId is only available on Jira Cloud.
# https://community.atlassian.com/t5/Jira-Questions/How-to-find-account-id-on-jira-on-premise/qaq-p/1168652
if jira_issue.reporter.try(:accountId)
"#{jira_issue.client.options[:site]}people/#{jira_issue.reporter.accountId}"
else
"#{jira_issue.client.options[:site]}secure/ViewProfile.jspa?name=#{jira_issue.reporter.name}"
end
end
end
end
end
......@@ -4,6 +4,14 @@ require 'spec_helper'
RSpec.describe Integrations::Jira::IssueEntity do
let(:project) { build(:project) }
let(:reporter) do
double(
'displayName' => 'reporter',
'name' => double # Default to Jira Server issue response, Jira Cloud replaces name with accountId
)
end
let(:jira_issue) do
double(
summary: 'summary',
......@@ -11,7 +19,7 @@ RSpec.describe Integrations::Jira::IssueEntity do
updated: '2020-06-26T15:38:32.000+0000',
resolutiondate: '2020-06-27T13:23:51.000+0000',
labels: ['backend'],
reporter: double('displayName' => 'reporter'),
reporter: reporter,
assignee: double('displayName' => 'assignee'),
project: double(key: 'GL'),
key: 'GL-5',
......@@ -35,7 +43,7 @@ RSpec.describe Integrations::Jira::IssueEntity do
text_color: '#FFFFFF'
}
],
author: { name: 'reporter' },
author: hash_including(name: 'reporter'),
assignees: [
{ name: 'assignee' }
],
......@@ -45,6 +53,26 @@ RSpec.describe Integrations::Jira::IssueEntity do
)
end
context 'with Jira Server configuration' do
before do
allow(reporter).to receive(:name).and_return('reporter@reporter.com')
end
it 'returns the Jira Server profile URL' do
expect(subject[:author]).to include(web_url: 'http://jira.com/secure/ViewProfile.jspa?name=reporter@reporter.com')
end
end
context 'with Jira Cloud configuration' do
before do
allow(reporter).to receive(:accountId).and_return('12345')
end
it 'returns the Jira Cloud profile URL' do
expect(subject[:author]).to include(web_url: 'http://jira.com/people/12345')
end
end
context 'without assignee' do
before do
allow(jira_issue).to receive(:assignee).and_return(nil)
......
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