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 ...@@ -10,6 +10,10 @@ module Integrations
expose :state do |jira_issue| expose :state do |jira_issue|
jira_issue.resolutiondate ? 'closed' : 'opened' jira_issue.resolutiondate ? 'closed' : 'opened'
end end
expose :due_date do |jira_issue|
jira_issue.duedate&.to_datetime&.utc
end
end end
end end
end end
...@@ -38,19 +38,13 @@ module Integrations ...@@ -38,19 +38,13 @@ module Integrations
end end
expose :author do |jira_issue| expose :author do |jira_issue|
{ jira_user(jira_issue, :reporter)
name: jira_issue.reporter.displayName,
web_url: author_web_url(jira_issue),
avatar_url: jira_issue.reporter.avatarUrls['48x48']
}
end end
expose :assignees do |jira_issue| expose :assignees do |jira_issue|
if jira_issue.assignee.present? if jira_issue.assignee.present?
[ [
{ jira_user(jira_issue, :assignee)
name: jira_issue.assignee.displayName
}
] ]
else else
[] []
...@@ -73,16 +67,26 @@ module Integrations ...@@ -73,16 +67,26 @@ module Integrations
private 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. # There are differences between Jira Cloud and Jira Server URLs and responses.
# accountId is only available on Jira Cloud. # 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 # 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) if jira_issue.public_send(user_type).try(:accountId)
"#{base_web_url(jira_issue)}/people/#{jira_issue.reporter.accountId}" "#{base_web_url(jira_issue)}/people/#{jira_issue.public_send(user_type).accountId}"
else 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
end end
# rubocop:enable GitlabSecurity/PublicSend
def base_web_url(jira_issue) def base_web_url(jira_issue)
site_url = jira_issue.client.options[:site].delete_suffix('/') site_url = jira_issue.client.options[:site].delete_suffix('/')
......
...@@ -9,20 +9,29 @@ RSpec.describe Integrations::Jira::IssueDetailEntity do ...@@ -9,20 +9,29 @@ RSpec.describe Integrations::Jira::IssueDetailEntity do
double( double(
'displayName' => 'reporter', 'displayName' => 'reporter',
'avatarUrls' => { '48x48' => 'http://reporter.avatar' }, '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 end
let(:jira_issue) do let(:jira_issue) do
double( double(
renderedFields: { 'description' => '<p>Description</p>' },
summary: 'Title', summary: 'Title',
renderedFields: { 'description' => '<p>Description</p>' },
created: '2020-06-25T15:39:30.000+0000', created: '2020-06-25T15:39:30.000+0000',
updated: '2020-06-26T15:38:32.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', resolutiondate: '2020-06-27T13:23:51.000+0000',
labels: ['backend'], labels: ['backend'],
reporter: reporter, reporter: reporter,
assignee: double('displayName' => 'assignee'), assignee: assignee,
project: double(key: 'GL'), project: double(key: 'GL'),
key: 'GL-5', key: 'GL-5',
client: jira_client, client: jira_client,
...@@ -39,6 +48,7 @@ RSpec.describe Integrations::Jira::IssueDetailEntity do ...@@ -39,6 +48,7 @@ RSpec.describe Integrations::Jira::IssueDetailEntity do
description_html: "<p dir=\"auto\">Description</p>", description_html: "<p dir=\"auto\">Description</p>",
created_at: '2020-06-25T15:39:30.000+0000'.to_datetime.utc, created_at: '2020-06-25T15:39:30.000+0000'.to_datetime.utc,
updated_at: '2020-06-26T15:38:32.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, closed_at: '2020-06-27T13:23:51.000+0000'.to_datetime.utc,
status: 'To Do', status: 'To Do',
state: 'closed', state: 'closed',
...@@ -54,7 +64,10 @@ RSpec.describe Integrations::Jira::IssueDetailEntity do ...@@ -54,7 +64,10 @@ RSpec.describe Integrations::Jira::IssueDetailEntity do
avatar_url: 'http://reporter.avatar' avatar_url: 'http://reporter.avatar'
), ),
assignees: [ assignees: [
{ name: 'assignee' } hash_including(
name: 'assignee',
avatar_url: 'http://assignee.avatar'
)
], ],
web_url: 'http://jira.com/browse/GL-5', web_url: 'http://jira.com/browse/GL-5',
references: { relative: 'GL-5' }, references: { relative: 'GL-5' },
...@@ -65,10 +78,12 @@ RSpec.describe Integrations::Jira::IssueDetailEntity do ...@@ -65,10 +78,12 @@ RSpec.describe Integrations::Jira::IssueDetailEntity do
context 'with Jira Server configuration' do context 'with Jira Server configuration' do
before do before do
allow(reporter).to receive(:name).and_return('reporter@reporter.com') allow(reporter).to receive(:name).and_return('reporter@reporter.com')
allow(assignee).to receive(:name).and_return('assignee@assignee.com')
end end
it 'returns the Jira Server profile URL' do 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[: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 end
context 'and context_path' do context 'and context_path' do
...@@ -84,10 +99,12 @@ RSpec.describe Integrations::Jira::IssueDetailEntity do ...@@ -84,10 +99,12 @@ RSpec.describe Integrations::Jira::IssueDetailEntity do
context 'with Jira Cloud configuration' do context 'with Jira Cloud configuration' do
before do before do
allow(reporter).to receive(:accountId).and_return('12345') allow(reporter).to receive(:accountId).and_return('12345')
allow(assignee).to receive(:accountId).and_return('67890')
end end
it 'returns the Jira Cloud profile URL' do it 'returns the Jira Cloud profile URL' do
expect(subject[:author]).to include(web_url: 'http://jira.com/people/12345') 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
end end
......
...@@ -9,19 +9,27 @@ RSpec.describe Integrations::Jira::IssueEntity do ...@@ -9,19 +9,27 @@ RSpec.describe Integrations::Jira::IssueEntity do
double( double(
'displayName' => 'reporter', 'displayName' => 'reporter',
'avatarUrls' => { '48x48' => 'http://reporter.avatar' }, '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 end
let(:jira_issue) do let(:jira_issue) do
double( double(
summary: 'summary', summary: 'Title',
created: '2020-06-25T15:39:30.000+0000', created: '2020-06-25T15:39:30.000+0000',
updated: '2020-06-26T15:38:32.000+0000', updated: '2020-06-26T15:38:32.000+0000',
resolutiondate: '2020-06-27T13:23:51.000+0000', resolutiondate: '2020-06-27T13:23:51.000+0000',
labels: ['backend'], labels: ['backend'],
reporter: reporter, reporter: reporter,
assignee: double('displayName' => 'assignee'), assignee: assignee,
project: double(key: 'GL'), project: double(key: 'GL'),
key: 'GL-5', key: 'GL-5',
client: jira_client, client: jira_client,
...@@ -36,7 +44,7 @@ RSpec.describe Integrations::Jira::IssueEntity do ...@@ -36,7 +44,7 @@ RSpec.describe Integrations::Jira::IssueEntity do
it 'returns the Jira issues attributes' do it 'returns the Jira issues attributes' do
expect(subject).to include( expect(subject).to include(
project_id: project.id, project_id: project.id,
title: 'summary', title: 'Title',
created_at: '2020-06-25T15:39:30.000+0000'.to_datetime.utc, created_at: '2020-06-25T15:39:30.000+0000'.to_datetime.utc,
updated_at: '2020-06-26T15:38:32.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, closed_at: '2020-06-27T13:23:51.000+0000'.to_datetime.utc,
...@@ -53,7 +61,10 @@ RSpec.describe Integrations::Jira::IssueEntity do ...@@ -53,7 +61,10 @@ RSpec.describe Integrations::Jira::IssueEntity do
avatar_url: 'http://reporter.avatar' avatar_url: 'http://reporter.avatar'
), ),
assignees: [ assignees: [
{ name: 'assignee' } hash_including(
name: 'assignee',
avatar_url: 'http://assignee.avatar'
)
], ],
web_url: 'http://jira.com/browse/GL-5', web_url: 'http://jira.com/browse/GL-5',
references: { relative: 'GL-5' }, references: { relative: 'GL-5' },
...@@ -64,10 +75,12 @@ RSpec.describe Integrations::Jira::IssueEntity do ...@@ -64,10 +75,12 @@ RSpec.describe Integrations::Jira::IssueEntity do
context 'with Jira Server configuration' do context 'with Jira Server configuration' do
before do before do
allow(reporter).to receive(:name).and_return('reporter@reporter.com') allow(reporter).to receive(:name).and_return('reporter@reporter.com')
allow(assignee).to receive(:name).and_return('assignee@assignee.com')
end end
it 'returns the Jira Server profile URL' do 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[: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 end
context 'and context_path' do context 'and context_path' do
...@@ -83,10 +96,12 @@ RSpec.describe Integrations::Jira::IssueEntity do ...@@ -83,10 +96,12 @@ RSpec.describe Integrations::Jira::IssueEntity do
context 'with Jira Cloud configuration' do context 'with Jira Cloud configuration' do
before do before do
allow(reporter).to receive(:accountId).and_return('12345') allow(reporter).to receive(:accountId).and_return('12345')
allow(assignee).to receive(:accountId).and_return('67890')
end end
it 'returns the Jira Cloud profile URL' do it 'returns the Jira Cloud profile URL' do
expect(subject[:author]).to include(web_url: 'http://jira.com/people/12345') 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
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