Commit fb59909b authored by Tom Quirk's avatar Tom Quirk Committed by Luke Duncalfe

Ensure Jira users and labels have `id` attribute

A recent change to Apollo means we require IDs for 
every GraphQL object.

Jira labels and users did not include IDs.

This MR ensures Jira labels and users have `id` 
field defined.

https://gitlab.com/gitlab-org/gitlab/-/issues/347162

Changelog: fixed
EE: true
parent e4de93b4
...@@ -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|
{ {
id: name,
title: name, title: name,
name: name, name: name,
color: '#0052CC', color: '#0052CC',
...@@ -76,12 +77,20 @@ module Integrations ...@@ -76,12 +77,20 @@ module Integrations
def jira_user(user) def jira_user(user)
{ {
id: jira_user_id(user),
name: user['displayName'], name: user['displayName'],
web_url: jira_web_url(user), web_url: jira_web_url(user),
avatar_url: user['avatarUrls']['48x48'] avatar_url: user['avatarUrls']['48x48']
} }
end end
def jira_user_id(user)
# 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
user['accountId'].presence || user['name']
end
def jira_web_url(user) def jira_web_url(user)
# 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.
......
...@@ -86,6 +86,7 @@ RSpec.describe Integrations::JiraSerializers::IssueDetailEntity do ...@@ -86,6 +86,7 @@ RSpec.describe Integrations::JiraSerializers::IssueDetailEntity do
state: 'closed', state: 'closed',
labels: [ labels: [
{ {
id: 'backend',
title: 'backend', title: 'backend',
name: 'backend', name: 'backend',
color: '#0052CC', color: '#0052CC',
...@@ -93,6 +94,7 @@ RSpec.describe Integrations::JiraSerializers::IssueDetailEntity do ...@@ -93,6 +94,7 @@ RSpec.describe Integrations::JiraSerializers::IssueDetailEntity do
} }
], ],
author: hash_including( author: hash_including(
id: 'reporter@reporter.com',
name: 'reporter', name: 'reporter',
avatar_url: 'http://reporter.avatar' avatar_url: 'http://reporter.avatar'
), ),
...@@ -109,6 +111,7 @@ RSpec.describe Integrations::JiraSerializers::IssueDetailEntity do ...@@ -109,6 +111,7 @@ RSpec.describe Integrations::JiraSerializers::IssueDetailEntity do
hash_including( hash_including(
id: '10022', id: '10022',
author: hash_including( author: hash_including(
id: 'comment@author.com',
name: 'comment_author', name: 'comment_author',
avatar_url: 'http://comment_author.avatar' avatar_url: 'http://comment_author.avatar'
), ),
......
...@@ -53,6 +53,7 @@ RSpec.describe Integrations::JiraSerializers::IssueEntity do ...@@ -53,6 +53,7 @@ RSpec.describe Integrations::JiraSerializers::IssueEntity do
status: 'To Do', status: 'To Do',
labels: [ labels: [
{ {
id: 'backend',
title: 'backend', title: 'backend',
name: 'backend', name: 'backend',
color: '#0052CC', color: '#0052CC',
...@@ -60,11 +61,13 @@ RSpec.describe Integrations::JiraSerializers::IssueEntity do ...@@ -60,11 +61,13 @@ RSpec.describe Integrations::JiraSerializers::IssueEntity do
} }
], ],
author: hash_including( author: hash_including(
id: 'reporter@reporter.com',
name: 'reporter', name: 'reporter',
avatar_url: 'http://reporter.avatar' avatar_url: 'http://reporter.avatar'
), ),
assignees: [ assignees: [
hash_including( hash_including(
id: 'assignee@assignee.com',
name: 'assignee', name: 'assignee',
avatar_url: 'http://assignee.avatar' avatar_url: 'http://assignee.avatar'
) )
...@@ -91,6 +94,11 @@ RSpec.describe Integrations::JiraSerializers::IssueEntity do ...@@ -91,6 +94,11 @@ RSpec.describe Integrations::JiraSerializers::IssueEntity do
expect(subject[:assignees].first).to include(web_url: "http://jira.com/secure/ViewProfile.jspa?#{referrer}&name=assignee%40assignee.com") expect(subject[:assignees].first).to include(web_url: "http://jira.com/secure/ViewProfile.jspa?#{referrer}&name=assignee%40assignee.com")
end end
it 'sets user id field to `name`' do
expect(subject[:author][:id]).to eq(reporter['name'])
expect(subject[:assignees].first[:id]).to eq(assignee['name'])
end
context 'with only url' do context 'with only url' do
before do before do
stub_jira_integration_test stub_jira_integration_test
...@@ -123,6 +131,11 @@ RSpec.describe Integrations::JiraSerializers::IssueEntity do ...@@ -123,6 +131,11 @@ RSpec.describe Integrations::JiraSerializers::IssueEntity do
expect(subject[:author]).to include(web_url: "http://jira.com/people/12345?#{referrer}") expect(subject[:author]).to include(web_url: "http://jira.com/people/12345?#{referrer}")
expect(subject[:assignees].first).to include(web_url: "http://jira.com/people/67890?#{referrer}") expect(subject[:assignees].first).to include(web_url: "http://jira.com/people/67890?#{referrer}")
end end
it 'sets user id field to `accountId`' do
expect(subject[:author][:id]).to eq(reporter['accountId'])
expect(subject[:assignees].first[:id]).to eq(assignee['accountId'])
end
end end
context 'without assignee' do context 'without assignee' do
......
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