Commit 9dc0317b authored by Sean McGivern's avatar Sean McGivern

Merge branch '6752-jira-branches' into 'master'

Resolve "All Gitlab branches listed in Jira task in Development section"

Closes #6752

See merge request gitlab-org/gitlab-ee!6876
parents c712406c f2e4ade2
...@@ -27,10 +27,14 @@ Rails.application.routes.draw do ...@@ -27,10 +27,14 @@ Rails.application.routes.draw do
authorizations: 'oauth/authorizations' authorizations: 'oauth/authorizations'
end 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 :authorize, action: :new
get :callback get :callback
post :access_token post :access_token
# This helps minimize merge conflicts with CE for this scope block
match ':action', via: [:get, :post], to: proc { [404, {}, ['']] }
end end
namespace :oauth do 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 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
......
...@@ -31,9 +31,9 @@ account, in order to maximize the integrated GitLab projects used by your team. ...@@ -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. 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, 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) ![GitLab Application setup](img/jira_dev_panel_gl_setup_1.png)
- Check `api` in the Scopes section. - Check `api` in the Scopes section.
...@@ -58,9 +58,9 @@ from the left navigation menu. Click `Link GitHub account` to start creating a n ...@@ -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) ![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, 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. 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 ...@@ -98,30 +98,42 @@ module API
# Jira handles the filtering, presenting just MRs mentioning the Jira # Jira handles the filtering, presenting just MRs mentioning the Jira
# issue ID on the MR title / description. # issue ID on the MR title / description.
resource :repos do 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 get '/-/jira/pulls' do
present find_merge_requests, with: ::API::Github::Entities::PullRequest present find_merge_requests, with: ::API::Github::Entities::PullRequest
end 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. # In Github, each Merge Request is automatically also an issue.
# Therefore we return its comments here. # Therefore we return its comments here.
# It'll present _just_ the comments counting with a link to GitLab on # It'll present _just_ the comments counting with a link to GitLab on
# Jira dev panel, not the actual note content. # Jira dev panel, not the actual note content.
# get ':namespace/:project/issues/:id/comments' do
get '/-/jira/issues/:id/comments' do
merge_request = find_merge_request_with_access(params[:id]) merge_request = find_merge_request_with_access(params[:id])
present find_notes(merge_request), with: ::API::Github::Entities::NoteableComment present find_notes(merge_request), with: ::API::Github::Entities::NoteableComment
end 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. # present it accordingly.
get '/-/jira/pulls/:id/comments' do get ':namespace/:project/pulls/:id/comments' do
present [] present []
end end
# Commits are not presented within "Pull Requests" modal on Jira dev # Commits are not presented within "Pull Requests" modal on Jira dev
# panel. # panel.
get '/-/jira/pulls/:id/commits' do get ':namespace/:project/pulls/:id/commits' do
present [] present []
end end
...@@ -129,7 +141,7 @@ module API ...@@ -129,7 +141,7 @@ module API
# after fetching branches. # after fetching branches.
# We need to respond with a 200 request to avoid breaking the # We need to respond with a 200 request to avoid breaking the
# integration flow (fetching merge requests). # integration flow (fetching merge requests).
get '/-/jira/events' do get ':namespace/:project/events' do
present [] present []
end end
......
...@@ -35,7 +35,7 @@ describe Oauth::Jira::AuthorizationsController do ...@@ -35,7 +35,7 @@ describe Oauth::Jira::AuthorizationsController do
'client_id' => 'client-123', 'client_id' => 'client-123',
'client_secret' => 'secret-123', 'client_secret' => 'secret-123',
'grant_type' => 'authorization_code', '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 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' } { 'access_token' => 'fake-123', 'scope' => 'foo', 'token_type' => 'bar' }
......
...@@ -3,10 +3,12 @@ require 'spec_helper' ...@@ -3,10 +3,12 @@ require 'spec_helper'
describe API::V3::Github do describe API::V3::Github do
let(:user) { create(:user) } let(:user) { create(:user) }
let!(:project) { create(:project, :repository, creator: user) } let!(:project) { create(:project, :repository, creator: user) }
let!(:project2) { create(:project, :repository, creator: user) }
before do before do
allow(Gitlab::Jira::Middleware).to receive(:jira_dvcs_connector?) { true } allow(Gitlab::Jira::Middleware).to receive(:jira_dvcs_connector?) { true }
project.add_maintainer(user) project.add_maintainer(user)
project2.add_maintainer(user)
end end
describe 'GET /orgs/:namespace/repos' do describe 'GET /orgs/:namespace/repos' do
...@@ -37,34 +39,17 @@ describe API::V3::Github do ...@@ -37,34 +39,17 @@ describe API::V3::Github do
end end
end end
describe 'GET /repos/-/jira/events' do shared_examples_for 'Jira-specific mimicked GitHub endpoints' do
describe 'GET /repos/.../events' do
it 'returns an empty array' do it 'returns an empty array' do
get v3_api('/repos/-/jira/events', user) get v3_api("/repos/#{path}/events", user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response).to eq([]) expect(json_response).to eq([])
end end
end end
describe 'GET /-/jira/pulls' do describe 'GET /.../issues/:id/comments' do
let(:assignee) { create(:user) }
let!(:merge_request) do
create(:merge_request, source_project: project, target_project: project, author: user, assignee: assignee)
end
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(1)
expect(response).to match_response_schema('entities/github/pull_requests', dir: 'ee')
end
end
describe 'GET /-/jira/issues/:id/comments' do
context 'when user has access to the merge request' do context 'when user has access to the merge request' do
let(:merge_request) do let(:merge_request) do
create(:merge_request, source_project: project, target_project: project) create(:merge_request, source_project: project, target_project: project)
...@@ -76,7 +61,7 @@ describe API::V3::Github do ...@@ -76,7 +61,7 @@ describe API::V3::Github do
it 'returns an array of notes' do it 'returns an array of notes' do
stub_licensed_features(jira_dev_panel_integration: true) stub_licensed_features(jira_dev_panel_integration: true)
get v3_api("/repos/-/jira/issues/#{merge_request.id}/comments", user) get v3_api("/repos/#{path}/issues/#{merge_request.id}/comments", user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response).to be_an(Array) expect(json_response).to be_an(Array)
...@@ -100,30 +85,81 @@ describe API::V3::Github do ...@@ -100,30 +85,81 @@ describe API::V3::Github do
it 'returns 404' do it 'returns 404' do
stub_licensed_features(jira_dev_panel_integration: true) stub_licensed_features(jira_dev_panel_integration: true)
get v3_api("/repos/-/jira/issues/#{merge_request.id}/comments", user) get v3_api("/repos/#{path}/issues/#{merge_request.id}/comments", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
end end
end end
describe 'GET /-/jira/pulls/:id/commits' do describe 'GET /.../pulls/:id/commits' do
it 'returns an empty array' do it 'returns an empty array' do
get v3_api("/repos/-/jira/pulls/xpto/commits", user) get v3_api("/repos/#{path}/pulls/xpto/commits", user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response).to eq([]) expect(json_response).to eq([])
end end
end end
describe 'GET /-/jira/pulls/:id/comments' do describe 'GET /.../pulls/:id/comments' do
it 'returns an empty array' do it 'returns an empty array' do
get v3_api("/repos/-/jira/pulls/xpto/comments", user) get v3_api("/repos/#{path}/pulls/xpto/comments", user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response).to eq([]) expect(json_response).to eq([])
end end
end end
end
# 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
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 '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
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
describe 'GET /users/:namespace/repos' do describe 'GET /users/:namespace/repos' do
let(:group) { create(:group, name: 'foo') } let(:group) { create(:group, name: 'foo') }
......
...@@ -40,6 +40,7 @@ module Gitlab ...@@ -40,6 +40,7 @@ module Gitlab
invites invites
jwt jwt
koding koding
login
notification_settings notification_settings
oauth oauth
profile 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