Fixes #3830 - Zammad ignores relative GitLab URLs.
This commit is contained in:
parent
cb3516e49d
commit
dd92280833
3 changed files with 30 additions and 0 deletions
|
@ -14,6 +14,19 @@ class GitLab
|
|||
@endpoint = endpoint
|
||||
end
|
||||
|
||||
# returns path of the subfolder of the endpoint if exists
|
||||
def endpoint_path
|
||||
path = URI.parse(endpoint).path
|
||||
return if path.blank?
|
||||
return if path == '/api/graphql'
|
||||
|
||||
if path.start_with?('/')
|
||||
path = path[1..]
|
||||
end
|
||||
|
||||
path.sub('api/graphql', '')
|
||||
end
|
||||
|
||||
def perform(payload)
|
||||
response = UserAgent.post(
|
||||
endpoint,
|
||||
|
|
|
@ -106,6 +106,10 @@ class GitLab
|
|||
fullpath = $2
|
||||
id = $3
|
||||
|
||||
if client.endpoint_path.present?
|
||||
fullpath.sub!(client.endpoint_path, '')
|
||||
end
|
||||
|
||||
if client.endpoint.exclude?(host)
|
||||
raise Exceptions::UnprocessableEntity, "Issue link doesn't match configured GitLab endpoint '#{client.endpoint}'"
|
||||
end
|
||||
|
|
|
@ -77,4 +77,17 @@ RSpec.describe GitLab, type: :integration, required_envs: %w[GITLAB_ENDPOINT GIT
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#variables' do
|
||||
describe 'Zammad ignores relative GitLab URLs #3830' do
|
||||
let(:endpoint) { ENV['GITLAB_ENDPOINT'].sub('api/graphql', 'subfolder/api/graphql') }
|
||||
let(:instance) { described_class.new(endpoint, ENV['GITLAB_APITOKEN']) }
|
||||
let(:issue_url) { "https://#{URI.parse(ENV['GITLAB_ISSUE_LINK']).host}/subfolder/group/project/-/issues/1" }
|
||||
let(:linked_issue) { GitLab::LinkedIssue.new(instance.client) }
|
||||
|
||||
it 'does remove the subfolder from the fullpath to get the issue correctly' do
|
||||
expect(linked_issue.send(:variables, issue_url)[:fullpath]).to eq('group/project')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue