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 ...@@ -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
...@@ -32,6 +32,7 @@ module Integrations ...@@ -32,6 +32,7 @@ module Integrations
expose :labels do |jira_issue| expose :labels do |jira_issue|
jira_issue.labels.map do |name| jira_issue.labels.map do |name|
{ {
title: name,
name: name, name: name,
color: '#EBECF0', color: '#EBECF0',
text_color: '#283856' text_color: '#283856'
...@@ -40,19 +41,13 @@ module Integrations ...@@ -40,19 +41,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
[] []
...@@ -83,16 +78,26 @@ module Integrations ...@@ -83,16 +78,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,11 +48,13 @@ RSpec.describe Integrations::Jira::IssueDetailEntity do ...@@ -39,11 +48,13 @@ 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',
labels: [ labels: [
{ {
title: 'backend',
name: 'backend', name: 'backend',
color: '#EBECF0', color: '#EBECF0',
text_color: '#283856' text_color: '#283856'
...@@ -54,7 +65,10 @@ RSpec.describe Integrations::Jira::IssueDetailEntity do ...@@ -54,7 +65,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 +79,12 @@ RSpec.describe Integrations::Jira::IssueDetailEntity do ...@@ -65,10 +79,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 +100,12 @@ RSpec.describe Integrations::Jira::IssueDetailEntity do ...@@ -84,10 +100,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,13 +44,14 @@ RSpec.describe Integrations::Jira::IssueEntity do ...@@ -36,13 +44,14 @@ 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,
status: 'To Do', status: 'To Do',
labels: [ labels: [
{ {
title: 'backend',
name: 'backend', name: 'backend',
color: '#EBECF0', color: '#EBECF0',
text_color: '#283856' text_color: '#283856'
...@@ -53,7 +62,10 @@ RSpec.describe Integrations::Jira::IssueEntity do ...@@ -53,7 +62,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',
gitlab_web_url: Gitlab::Routing.url_helpers.project_integrations_jira_issue_path(project, '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 ...@@ -65,10 +77,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
...@@ -84,10 +98,12 @@ RSpec.describe Integrations::Jira::IssueEntity do ...@@ -84,10 +98,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