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
expose :labels do |jira_issue|
jira_issue.labels.map do |name|
{
id: name,
title: name,
name: name,
color: '#0052CC',
......@@ -76,12 +77,20 @@ module Integrations
def jira_user(user)
{
id: jira_user_id(user),
name: user['displayName'],
web_url: jira_web_url(user),
avatar_url: user['avatarUrls']['48x48']
}
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)
# There are differences between Jira Cloud and Jira Server URLs and responses.
# accountId is only available on Jira Cloud.
......
......@@ -86,6 +86,7 @@ RSpec.describe Integrations::JiraSerializers::IssueDetailEntity do
state: 'closed',
labels: [
{
id: 'backend',
title: 'backend',
name: 'backend',
color: '#0052CC',
......@@ -93,6 +94,7 @@ RSpec.describe Integrations::JiraSerializers::IssueDetailEntity do
}
],
author: hash_including(
id: 'reporter@reporter.com',
name: 'reporter',
avatar_url: 'http://reporter.avatar'
),
......@@ -109,6 +111,7 @@ RSpec.describe Integrations::JiraSerializers::IssueDetailEntity do
hash_including(
id: '10022',
author: hash_including(
id: 'comment@author.com',
name: 'comment_author',
avatar_url: 'http://comment_author.avatar'
),
......
......@@ -53,6 +53,7 @@ RSpec.describe Integrations::JiraSerializers::IssueEntity do
status: 'To Do',
labels: [
{
id: 'backend',
title: 'backend',
name: 'backend',
color: '#0052CC',
......@@ -60,11 +61,13 @@ RSpec.describe Integrations::JiraSerializers::IssueEntity do
}
],
author: hash_including(
id: 'reporter@reporter.com',
name: 'reporter',
avatar_url: 'http://reporter.avatar'
),
assignees: [
hash_including(
id: 'assignee@assignee.com',
name: 'assignee',
avatar_url: 'http://assignee.avatar'
)
......@@ -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")
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
before do
stub_jira_integration_test
......@@ -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[:assignees].first).to include(web_url: "http://jira.com/people/67890?#{referrer}")
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
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