Commit cc3fe6a1 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Allow dots in Jira DVCS API URLs

This moves the `requirements` options to the top-level
route so that all routes inherit the option
parent 6b43b438
---
title: Fix Jira DVCS integration not working when project name has dots
merge_request: 14855
author:
type: fixed
......@@ -10,8 +10,11 @@ module API
class Github < Grape::API
JIRA_DEV_PANEL_FEATURE = :jira_dev_panel_integration.freeze
NO_SLASH_URL_PART_REGEX = %r{[^/]+}.freeze
NAMESPACE_ENDPOINT_REQUIREMENTS = { namespace: NO_SLASH_URL_PART_REGEX }.freeze
PROJECT_ENDPOINT_REQUIREMENTS = NAMESPACE_ENDPOINT_REQUIREMENTS.merge(project: NO_SLASH_URL_PART_REGEX).freeze
ENDPOINT_REQUIREMENTS = {
namespace: NO_SLASH_URL_PART_REGEX,
project: NO_SLASH_URL_PART_REGEX,
username: NO_SLASH_URL_PART_REGEX
}.freeze
# Used to differentiate Jira Cloud requests from Jira Server requests
# Jira Cloud user agent format: Jira DVCS Connector Vertigo/version
......@@ -90,7 +93,7 @@ module API
end
resource :orgs do
get ':namespace/repos', requirements: NAMESPACE_ENDPOINT_REQUIREMENTS do
get ':namespace/repos' do
present []
end
end
......@@ -106,7 +109,7 @@ module API
use :pagination
end
get ':namespace/repos', requirements: NAMESPACE_ENDPOINT_REQUIREMENTS do
get ':namespace/repos' do
namespace = Namespace.find_by_full_path(params[:namespace])
not_found!('Namespace') unless namespace
......@@ -147,7 +150,7 @@ module API
params do
use :project_full_path
end
get ':namespace/:project/pulls', requirements: PROJECT_ENDPOINT_REQUIREMENTS do
get ':namespace/:project/pulls' do
user_project = find_project_with_access(params)
merge_requests = MergeRequestsFinder.new(current_user, authorized_only: true, project_id: user_project.id).execute
......@@ -158,7 +161,7 @@ module API
params do
use :project_full_path
end
get ':namespace/:project/pulls/:id', requirements: PROJECT_ENDPOINT_REQUIREMENTS do
get ':namespace/:project/pulls/:id' do
mr = find_merge_request_with_access(params[:id])
present mr, with: ::API::Github::Entities::PullRequest
......@@ -200,7 +203,7 @@ module API
use :project_full_path
use :pagination
end
get ':namespace/:project/branches', requirements: PROJECT_ENDPOINT_REQUIREMENTS do
get ':namespace/:project/branches' do
user_project = find_project_with_access(params)
update_project_feature_usage_for(user_project)
......@@ -213,7 +216,7 @@ module API
params do
use :project_full_path
end
get ':namespace/:project/commits/:sha', requirements: PROJECT_ENDPOINT_REQUIREMENTS do
get ':namespace/:project/commits/:sha' do
user_project = find_project_with_access(params)
commit = user_project.commit(params[:sha])
......
......@@ -41,9 +41,11 @@ module EE
# they're not deprecated neither should be removed when V3 get
# removed. They're needed as a layer to integrate with Jira
# Development Panel.
namespace '/', requirements: ::API::V3::Github::ENDPOINT_REQUIREMENTS do
mount ::API::V3::Github
end
end
end
end
end
end
......@@ -122,7 +122,7 @@ describe API::V3::Github do
end
describe 'GET /users/:username' do
let!(:user1) { create(:user, username: 'jane') }
let!(:user1) { create(:user, username: 'jane.porter') }
before do
stub_licensed_features(jira_dev_panel_integration: true)
......@@ -130,7 +130,7 @@ describe API::V3::Github do
context 'user exists' do
it 'responds with the expected user' do
jira_get v3_api('/users/jane', user)
jira_get v3_api("/users/#{user.username}", user)
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('entities/github/user', dir: 'ee')
......@@ -154,7 +154,7 @@ describe API::V3::Github do
end
it 'responds with forbidden' do
jira_get v3_api('/users/jane', unauthorized_user)
jira_get v3_api("/users/#{user.username}", unauthorized_user)
expect(response).to have_gitlab_http_status(403)
end
......@@ -163,7 +163,7 @@ describe API::V3::Github do
describe 'GET events' do
let(:group) { create(:group) }
let(:project) { create(:project, :empty_repo, group: group) }
let(:project) { create(:project, :empty_repo, path: 'project.with.dot', group: group) }
let(:events_path) { "/repos/#{group.path}/#{project.path}/events" }
before 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