Commit 4a1a1ae4 authored by Kerri Miller's avatar Kerri Miller

Merge branch '294155-jira-issue-entity-extra' into 'master'

Update Jira issue entity with extra data

See merge request gitlab-org/gitlab!53997
parents 3583b352 97c4192e
......@@ -10,6 +10,10 @@ module Integrations
expose :state do |jira_issue|
jira_issue.resolutiondate ? 'closed' : 'opened'
end
expose :due_date do |jira_issue|
jira_issue.duedate&.to_datetime&.utc
end
end
end
end
......@@ -32,6 +32,7 @@ module Integrations
expose :labels do |jira_issue|
jira_issue.labels.map do |name|
{
title: name,
name: name,
color: '#EBECF0',
text_color: '#283856'
......@@ -40,19 +41,13 @@ module Integrations
end
expose :author do |jira_issue|
{
name: jira_issue.reporter.displayName,
web_url: author_web_url(jira_issue),
avatar_url: jira_issue.reporter.avatarUrls['48x48']
}
jira_user(jira_issue, :reporter)
end
expose :assignees do |jira_issue|
if jira_issue.assignee.present?
[
{
name: jira_issue.assignee.displayName
}
jira_user(jira_issue, :assignee)
]
else
[]
......@@ -83,16 +78,26 @@ module Integrations
private
def author_web_url(jira_issue)
# rubocop:disable GitlabSecurity/PublicSend
def jira_user(jira_issue, user_type)
{
name: jira_issue.public_send(user_type).displayName,
web_url: jira_web_url(jira_issue, user_type),
avatar_url: jira_issue.public_send(user_type).avatarUrls['48x48']
}
end
def jira_web_url(jira_issue, user_type)
# 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)
"#{base_web_url(jira_issue)}/people/#{jira_issue.reporter.accountId}"
if jira_issue.public_send(user_type).try(:accountId)
"#{base_web_url(jira_issue)}/people/#{jira_issue.public_send(user_type).accountId}"
else
"#{base_web_url(jira_issue)}/secure/ViewProfile.jspa?name=#{jira_issue.reporter.name}"
"#{base_web_url(jira_issue)}/secure/ViewProfile.jspa?name=#{jira_issue.public_send(user_type).name}"
end
end
# rubocop:enable GitlabSecurity/PublicSend
def base_web_url(jira_issue)
site_url = jira_issue.client.options[:site].delete_suffix('/')
......
......@@ -9,20 +9,29 @@ RSpec.describe Integrations::Jira::IssueDetailEntity do
double(
'displayName' => 'reporter',
'avatarUrls' => { '48x48' => 'http://reporter.avatar' },
'name' => double # Default to Jira Server issue response, Jira Cloud replaces name with accountId,
'name' => double
)
end
let(:assignee) do
double(
'displayName' => 'assignee',
'avatarUrls' => { '48x48' => 'http://assignee.avatar' },
'name' => double
)
end
let(:jira_issue) do
double(
renderedFields: { 'description' => '<p>Description</p>' },
summary: 'Title',
renderedFields: { 'description' => '<p>Description</p>' },
created: '2020-06-25T15:39:30.000+0000',
updated: '2020-06-26T15:38:32.000+0000',
duedate: '2020-06-27T15:40:30.000+0000',
resolutiondate: '2020-06-27T13:23:51.000+0000',
labels: ['backend'],
reporter: reporter,
assignee: double('displayName' => 'assignee'),
assignee: assignee,
project: double(key: 'GL'),
key: 'GL-5',
client: jira_client,
......@@ -39,11 +48,13 @@ RSpec.describe Integrations::Jira::IssueDetailEntity do
description_html: "<p dir=\"auto\">Description</p>",
created_at: '2020-06-25T15:39:30.000+0000'.to_datetime.utc,
updated_at: '2020-06-26T15:38:32.000+0000'.to_datetime.utc,
due_date: '2020-06-27T15:40:30.000+0000'.to_datetime.utc,
closed_at: '2020-06-27T13:23:51.000+0000'.to_datetime.utc,
status: 'To Do',
state: 'closed',
labels: [
{
title: 'backend',
name: 'backend',
color: '#EBECF0',
text_color: '#283856'
......@@ -54,7 +65,10 @@ RSpec.describe Integrations::Jira::IssueDetailEntity do
avatar_url: 'http://reporter.avatar'
),
assignees: [
{ name: 'assignee' }
hash_including(
name: 'assignee',
avatar_url: 'http://assignee.avatar'
)
],
web_url: 'http://jira.com/browse/GL-5',
references: { relative: 'GL-5' },
......@@ -65,10 +79,12 @@ RSpec.describe Integrations::Jira::IssueDetailEntity do
context 'with Jira Server configuration' do
before do
allow(reporter).to receive(:name).and_return('reporter@reporter.com')
allow(assignee).to receive(:name).and_return('assignee@assignee.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')
expect(subject[:assignees].first).to include(web_url: 'http://jira.com/secure/ViewProfile.jspa?name=assignee@assignee.com')
end
context 'and context_path' do
......@@ -84,10 +100,12 @@ RSpec.describe Integrations::Jira::IssueDetailEntity do
context 'with Jira Cloud configuration' do
before do
allow(reporter).to receive(:accountId).and_return('12345')
allow(assignee).to receive(:accountId).and_return('67890')
end
it 'returns the Jira Cloud profile URL' do
expect(subject[:author]).to include(web_url: 'http://jira.com/people/12345')
expect(subject[:assignees].first).to include(web_url: 'http://jira.com/people/67890')
end
end
......
......@@ -9,19 +9,27 @@ RSpec.describe Integrations::Jira::IssueEntity do
double(
'displayName' => 'reporter',
'avatarUrls' => { '48x48' => 'http://reporter.avatar' },
'name' => double # Default to Jira Server issue response, Jira Cloud replaces name with accountId
'name' => double
)
end
let(:assignee) do
double(
'displayName' => 'assignee',
'avatarUrls' => { '48x48' => 'http://assignee.avatar' },
'name' => double
)
end
let(:jira_issue) do
double(
summary: 'summary',
summary: 'Title',
created: '2020-06-25T15:39:30.000+0000',
updated: '2020-06-26T15:38:32.000+0000',
resolutiondate: '2020-06-27T13:23:51.000+0000',
labels: ['backend'],
reporter: reporter,
assignee: double('displayName' => 'assignee'),
assignee: assignee,
project: double(key: 'GL'),
key: 'GL-5',
client: jira_client,
......@@ -36,13 +44,14 @@ RSpec.describe Integrations::Jira::IssueEntity do
it 'returns the Jira issues attributes' do
expect(subject).to include(
project_id: project.id,
title: 'summary',
title: 'Title',
created_at: '2020-06-25T15:39:30.000+0000'.to_datetime.utc,
updated_at: '2020-06-26T15:38:32.000+0000'.to_datetime.utc,
closed_at: '2020-06-27T13:23:51.000+0000'.to_datetime.utc,
status: 'To Do',
labels: [
{
title: 'backend',
name: 'backend',
color: '#EBECF0',
text_color: '#283856'
......@@ -53,7 +62,10 @@ RSpec.describe Integrations::Jira::IssueEntity do
avatar_url: 'http://reporter.avatar'
),
assignees: [
{ name: 'assignee' }
hash_including(
name: 'assignee',
avatar_url: 'http://assignee.avatar'
)
],
web_url: 'http://jira.com/browse/GL-5',
gitlab_web_url: Gitlab::Routing.url_helpers.project_integrations_jira_issue_path(project, 'GL-5'),
......@@ -65,10 +77,12 @@ RSpec.describe Integrations::Jira::IssueEntity do
context 'with Jira Server configuration' do
before do
allow(reporter).to receive(:name).and_return('reporter@reporter.com')
allow(assignee).to receive(:name).and_return('assignee@assignee.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')
expect(subject[:assignees].first).to include(web_url: 'http://jira.com/secure/ViewProfile.jspa?name=assignee@assignee.com')
end
context 'and context_path' do
......@@ -84,10 +98,12 @@ RSpec.describe Integrations::Jira::IssueEntity do
context 'with Jira Cloud configuration' do
before do
allow(reporter).to receive(:accountId).and_return('12345')
allow(assignee).to receive(:accountId).and_return('67890')
end
it 'returns the Jira Cloud profile URL' do
expect(subject[:author]).to include(web_url: 'http://jira.com/people/12345')
expect(subject[:assignees].first).to include(web_url: 'http://jira.com/people/67890')
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