Commit c249433d authored by Andy Soiron's avatar Andy Soiron Committed by Jarka Košanová

Consider context path in Jira issue links

parent cd2ff96f
...@@ -58,7 +58,7 @@ module Integrations ...@@ -58,7 +58,7 @@ module Integrations
end end
expose :web_url do |jira_issue| expose :web_url do |jira_issue|
"#{jira_issue.client.options[:site]}browse/#{jira_issue.key}" "#{base_web_url(jira_issue)}/browse/#{jira_issue.key}"
end end
expose :references do |jira_issue| expose :references do |jira_issue|
...@@ -78,11 +78,20 @@ module Integrations ...@@ -78,11 +78,20 @@ module Integrations
# 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.reporter.try(:accountId)
"#{jira_issue.client.options[:site]}people/#{jira_issue.reporter.accountId}" "#{base_web_url(jira_issue)}/people/#{jira_issue.reporter.accountId}"
else else
"#{jira_issue.client.options[:site]}secure/ViewProfile.jspa?name=#{jira_issue.reporter.name}" "#{base_web_url(jira_issue)}/secure/ViewProfile.jspa?name=#{jira_issue.reporter.name}"
end end
end end
def base_web_url(jira_issue)
site_url = jira_issue.client.options[:site].delete_suffix('/')
context_path = jira_issue.client.options[:context_path].to_s.delete_prefix('/')
return site_url if context_path.empty?
[site_url, context_path].join('/')
end
end end
end end
end end
---
title: Fix Jira issue list links when Jira runs on a subpath
merge_request: 51797
author:
type: fixed
...@@ -22,7 +22,7 @@ RSpec.describe Resolvers::ExternalIssueResolver do ...@@ -22,7 +22,7 @@ RSpec.describe Resolvers::ExternalIssueResolver do
labels: [], labels: [],
reporter: double(displayName: 'User', accountId: '10000'), reporter: double(displayName: 'User', accountId: '10000'),
assignee: nil, assignee: nil,
client: double(options: { site: nil }) client: double(options: { site: 'http://jira.com/' })
) )
end end
...@@ -37,10 +37,10 @@ RSpec.describe Resolvers::ExternalIssueResolver do ...@@ -37,10 +37,10 @@ RSpec.describe Resolvers::ExternalIssueResolver do
'labels' => [], 'labels' => [],
'author' => { 'author' => {
'name' => 'User', 'name' => 'User',
'web_url' => 'people/10000' 'web_url' => 'http://jira.com/people/10000'
}, },
'assignees' => [], 'assignees' => [],
'web_url' => 'browse/GV-1', 'web_url' => 'http://jira.com/browse/GV-1',
'references' => { 'references' => {
'relative' => 'GV-1' 'relative' => 'GV-1'
}, },
......
...@@ -23,11 +23,13 @@ RSpec.describe Integrations::Jira::IssueEntity do ...@@ -23,11 +23,13 @@ RSpec.describe Integrations::Jira::IssueEntity do
assignee: double('displayName' => 'assignee'), assignee: double('displayName' => 'assignee'),
project: double(key: 'GL'), project: double(key: 'GL'),
key: 'GL-5', key: 'GL-5',
client: double(options: { site: 'http://jira.com/' }), client: jira_client,
status: double(name: 'To Do') status: double(name: 'To Do')
) )
end end
let(:jira_client) { double(options: { site: 'http://jira.com/' }) }
subject { described_class.new(jira_issue, project: project).as_json } subject { described_class.new(jira_issue, project: project).as_json }
it 'returns the Jira issues attributes' do it 'returns the Jira issues attributes' do
...@@ -63,6 +65,15 @@ RSpec.describe Integrations::Jira::IssueEntity do ...@@ -63,6 +65,15 @@ RSpec.describe Integrations::Jira::IssueEntity do
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')
end end
context 'and context_path' do
let(:jira_client) { double(options: { site: 'http://jira.com/', context_path: '/jira-sub-path' }) }
it 'returns URLs including context path' do
expect(subject[:author]).to include(web_url: 'http://jira.com/jira-sub-path/secure/ViewProfile.jspa?name=reporter@reporter.com')
expect(subject[:web_url]).to eq('http://jira.com/jira-sub-path/browse/GL-5')
end
end
end end
context 'with Jira Cloud configuration' do context 'with Jira Cloud configuration' 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