Commit f2e4ade2 authored by Mario de la Ossa's avatar Mario de la Ossa

Fix Jira integration not using proper API endpoints

Jira needs to be given a bare domain (no path) for its configuration,
otherwise it confuses itself and does not use the proper API endpoints.
This was the reason why we always say requests like `/-/jira/pulls`
before (it uses whatever path is given always)
parent 89b4075d
......@@ -27,10 +27,14 @@ Rails.application.routes.draw do
authorizations: 'oauth/authorizations'
end
scope path: '/-/jira/login/oauth', controller: 'oauth/jira/authorizations', as: :oauth_jira do
# This prefixless path is required because Jira gets confused if we set it up with a path
# More information: https://gitlab.com/gitlab-org/gitlab-ee/issues/6752
scope path: '/login/oauth', controller: 'oauth/jira/authorizations', as: :oauth_jira do
get :authorize, action: :new
get :callback
post :access_token
# This helps minimize merge conflicts with CE for this scope block
match ':action', via: [:get, :post], to: proc { [404, {}, ['']] }
end
namespace :oauth do
......
# frozen_string_literal: true
class RenameLoginRootNamespaces < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
include Gitlab::Database::RenameReservedPathsMigration::V1
DOWNTIME = false
# We're taking over the /login namespace as part of a fix for the Jira integration
def up
rename_root_paths 'login'
end
def down
revert_renames
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180809195358) do
ActiveRecord::Schema.define(version: 20180816193530) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......
......@@ -31,9 +31,9 @@ account, in order to maximize the integrated GitLab projects used by your team.
Enter a useful name for the `Name` field.
For the `Redirect URI` field, enter `https://<your-gitlab-instance-domain>/-/jira/login/oauth/callback`,
For the `Redirect URI` field, enter `https://<your-gitlab-instance-domain>/login/oauth/callback`,
replacing `<your-gitlab-instance-domain>` appropriately. So for example, if you are using GitLab.com,
this would be `https://gitlab.com/-/jira/login/oauth/callback`.
this would be `https://gitlab.com/login/oauth/callback`.
![GitLab Application setup](img/jira_dev_panel_gl_setup_1.png)
- Check `api` in the Scopes section.
......@@ -58,9 +58,9 @@ from the left navigation menu. Click `Link GitHub account` to start creating a n
![Creation of Jira DVCS integration](img/jira_dev_panel_jira_setup_2.png)
For the `Host URL` field, enter `https://<your-gitlab-instance-domain>/-/jira`,
For the `Host URL` field, enter `https://<your-gitlab-instance-domain>/`,
replacing `<your-gitlab-instance-domain>` appropriately. So for example, if you are using GitLab.com,
this would be `https://gitlab.com/-/jira`.
this would be `https://gitlab.com/`.
For the `Client ID` field, use the `Application ID` value from the previous section.
......
---
title: Fix Jira integration duplicating branches and MRs
merge_request: 6876
author:
type: fixed
......@@ -98,30 +98,42 @@ module API
# Jira handles the filtering, presenting just MRs mentioning the Jira
# issue ID on the MR title / description.
resource :repos do
# Keeping for backwards compatibility with old Jira integration instructions
# so that users that do not change it will not suddenly have a broken integration
get '/-/jira/pulls' do
present find_merge_requests, with: ::API::Github::Entities::PullRequest
end
params do
use :project_full_path
end
get ':namespace/:project/pulls', requirements: PROJECT_ENDPOINT_REQUIREMENTS do
user_project = find_project_with_access(params)
merge_requests = MergeRequestsFinder.new(current_user, authorized_only: true, project_id: user_project.id).execute
present paginate(merge_requests), with: ::API::Github::Entities::PullRequest
end
# In Github, each Merge Request is automatically also an issue.
# Therefore we return its comments here.
# It'll present _just_ the comments counting with a link to GitLab on
# Jira dev panel, not the actual note content.
#
get '/-/jira/issues/:id/comments' do
get ':namespace/:project/issues/:id/comments' do
merge_request = find_merge_request_with_access(params[:id])
present find_notes(merge_request), with: ::API::Github::Entities::NoteableComment
end
# This refers to "review" comments but Jira dev panel doesn't seem to
# This refer to "review" comments but Jira dev panel doesn't seem to
# present it accordingly.
get '/-/jira/pulls/:id/comments' do
get ':namespace/:project/pulls/:id/comments' do
present []
end
# Commits are not presented within "Pull Requests" modal on Jira dev
# panel.
get '/-/jira/pulls/:id/commits' do
get ':namespace/:project/pulls/:id/commits' do
present []
end
......@@ -129,7 +141,7 @@ module API
# after fetching branches.
# We need to respond with a 200 request to avoid breaking the
# integration flow (fetching merge requests).
get '/-/jira/events' do
get ':namespace/:project/events' do
present []
end
......
......@@ -35,7 +35,7 @@ describe Oauth::Jira::AuthorizationsController do
'client_id' => 'client-123',
'client_secret' => 'secret-123',
'grant_type' => 'authorization_code',
'redirect_uri' => 'http://test.host/-/jira/login/oauth/callback' }
'redirect_uri' => 'http://test.host/login/oauth/callback' }
expect(Gitlab::HTTP).to receive(:post).with(oauth_token_url, allow_local_requests: true, body: expected_auth_params) do
{ 'access_token' => 'fake-123', 'scope' => 'foo', 'token_type' => 'bar' }
......
......@@ -3,10 +3,12 @@ require 'spec_helper'
describe API::V3::Github do
let(:user) { create(:user) }
let!(:project) { create(:project, :repository, creator: user) }
let!(:project2) { create(:project, :repository, creator: user) }
before do
allow(Gitlab::Jira::Middleware).to receive(:jira_dvcs_connector?) { true }
project.add_maintainer(user)
project2.add_maintainer(user)
end
describe 'GET /orgs/:namespace/repos' do
......@@ -37,91 +39,125 @@ describe API::V3::Github do
end
end
describe 'GET /repos/-/jira/events' do
it 'returns an empty array' do
get v3_api('/repos/-/jira/events', user)
shared_examples_for 'Jira-specific mimicked GitHub endpoints' do
describe 'GET /repos/.../events' do
it 'returns an empty array' do
get v3_api("/repos/#{path}/events", user)
expect(response).to have_gitlab_http_status(200)
expect(json_response).to eq([])
end
end
describe 'GET /-/jira/pulls' do
let(:assignee) { create(:user) }
let!(:merge_request) do
create(:merge_request, source_project: project, target_project: project, author: user, assignee: assignee)
expect(response).to have_gitlab_http_status(200)
expect(json_response).to eq([])
end
end
it 'returns an array of merge requests with github format' do
stub_licensed_features(jira_dev_panel_integration: true)
describe 'GET /.../issues/:id/comments' do
context 'when user has access to the merge request' do
let(:merge_request) do
create(:merge_request, source_project: project, target_project: project)
end
let!(:note) do
create(:note, project: project, noteable: merge_request)
end
get v3_api('/repos/-/jira/pulls', user)
it 'returns an array of notes' do
stub_licensed_features(jira_dev_panel_integration: true)
expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an(Array)
expect(json_response.size).to eq(1)
expect(response).to match_response_schema('entities/github/pull_requests', dir: 'ee')
end
end
get v3_api("/repos/#{path}/issues/#{merge_request.id}/comments", user)
describe 'GET /-/jira/issues/:id/comments' do
context 'when user has access to the merge request' do
let(:merge_request) do
create(:merge_request, source_project: project, target_project: project)
end
let!(:note) do
create(:note, project: project, noteable: merge_request)
expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an(Array)
expect(json_response.size).to eq(1)
end
end
it 'returns an array of notes' do
stub_licensed_features(jira_dev_panel_integration: true)
context 'when user has no access to the merge request' do
let(:private_project) { create(:project, :private) }
let(:merge_request) do
create(:merge_request, source_project: private_project, target_project: private_project)
end
let!(:note) do
create(:note, project: private_project, noteable: merge_request)
end
get v3_api("/repos/-/jira/issues/#{merge_request.id}/comments", user)
before do
private_project.add_guest(user)
end
expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an(Array)
expect(json_response.size).to eq(1)
it 'returns 404' do
stub_licensed_features(jira_dev_panel_integration: true)
get v3_api("/repos/#{path}/issues/#{merge_request.id}/comments", user)
expect(response).to have_gitlab_http_status(404)
end
end
end
context 'when user has no access to the merge request' do
let(:private_project) { create(:project, :private) }
let(:merge_request) do
create(:merge_request, source_project: private_project, target_project: private_project)
end
let!(:note) do
create(:note, project: private_project, noteable: merge_request)
end
describe 'GET /.../pulls/:id/commits' do
it 'returns an empty array' do
get v3_api("/repos/#{path}/pulls/xpto/commits", user)
before do
private_project.add_guest(user)
expect(response).to have_gitlab_http_status(200)
expect(json_response).to eq([])
end
end
it 'returns 404' do
stub_licensed_features(jira_dev_panel_integration: true)
get v3_api("/repos/-/jira/issues/#{merge_request.id}/comments", user)
describe 'GET /.../pulls/:id/comments' do
it 'returns an empty array' do
get v3_api("/repos/#{path}/pulls/xpto/comments", user)
expect(response).to have_gitlab_http_status(404)
expect(response).to have_gitlab_http_status(200)
expect(json_response).to eq([])
end
end
end
describe 'GET /-/jira/pulls/:id/commits' do
it 'returns an empty array' do
get v3_api("/repos/-/jira/pulls/xpto/commits", user)
# Here we test that using /-/jira as namespace/project still works,
# since that is how old Jira setups will talk to us
context 'old /-/jira endpoints' do
it_behaves_like 'Jira-specific mimicked GitHub endpoints' do
let(:path) { '-/jira' }
end
end
expect(response).to have_gitlab_http_status(200)
expect(json_response).to eq([])
context 'new :namespace/:project jira endpoints' do
it_behaves_like 'Jira-specific mimicked GitHub endpoints' do
let(:path) { "#{project.namespace.path}/#{project.path}" }
end
end
describe 'GET /-/jira/pulls/:id/comments' do
it 'returns an empty array' do
get v3_api("/repos/-/jira/pulls/xpto/comments", user)
describe 'repo pulls' do
let(:assignee) { create(:user) }
let!(:merge_request) do
create(:merge_request, source_project: project, target_project: project, author: user, assignee: assignee)
end
let!(:merge_request_2) do
create(:merge_request, source_project: project2, target_project: project2, author: user, assignee: assignee)
end
expect(response).to have_gitlab_http_status(200)
expect(json_response).to eq([])
describe 'GET /-/jira/pulls' do
it 'returns an array of merge requests with github format' do
stub_licensed_features(jira_dev_panel_integration: true)
get v3_api('/repos/-/jira/pulls', user)
expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an(Array)
expect(json_response.size).to eq(2)
expect(response).to match_response_schema('entities/github/pull_requests', dir: 'ee')
end
end
describe 'GET /repos/:namespace/:project/pulls' do
it 'returns an array of merge requests for the proper project in github format' do
stub_licensed_features(jira_dev_panel_integration: true)
get v3_api("/repos/#{project.namespace.path}/#{project.path}/pulls", user)
expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an(Array)
expect(json_response.size).to eq(1)
expect(response).to match_response_schema('entities/github/pull_requests', dir: 'ee')
end
end
end
......
......@@ -40,6 +40,7 @@ module Gitlab
invites
jwt
koding
login
notification_settings
oauth
profile
......
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