Commit e5141fc4 authored by Arturo Herrero's avatar Arturo Herrero

Update Jira issue entity with extra data

This adds due_date and expands the assignee with web_url and avatar_url.
parent 401d2d96
......@@ -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
......@@ -38,19 +38,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
[]
......@@ -73,16 +67,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,6 +48,7 @@ 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',
......@@ -54,7 +64,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 +78,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 +99,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,7 +44,7 @@ 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,
......@@ -53,7 +61,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',
references: { relative: 'GL-5' },
......@@ -64,10 +75,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
......@@ -83,10 +96,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