Merge branch '31129-jira-project-key-elim' into 'master'

Remove project_key from the JIRA configuration

Closes #31129

See merge request !12050
This commit is contained in:
Sean McGivern 2017-07-26 08:26:47 +00:00
commit fd0823d6e4
8 changed files with 20 additions and 46 deletions

View File

@ -3,10 +3,8 @@ class JiraService < IssueTrackerService
validates :url, url: true, presence: true, if: :activated? validates :url, url: true, presence: true, if: :activated?
validates :api_url, url: true, allow_blank: true validates :api_url, url: true, allow_blank: true
validates :project_key, presence: true, if: :activated?
prop_accessor :username, :password, :url, :api_url, :project_key, prop_accessor :username, :password, :url, :api_url, :jira_issue_transition_id, :title, :description
:jira_issue_transition_id, :title, :description
before_update :reset_password before_update :reset_password
@ -54,10 +52,6 @@ class JiraService < IssueTrackerService
@client ||= JIRA::Client.new(options) @client ||= JIRA::Client.new(options)
end end
def jira_project
@jira_project ||= jira_request { client.Project.find(project_key) }
end
def help def help
"You need to configure JIRA before enabling this service. For more details "You need to configure JIRA before enabling this service. For more details
read the read the
@ -88,18 +82,12 @@ class JiraService < IssueTrackerService
[ [
{ type: 'text', name: 'url', title: 'Web URL', placeholder: 'https://jira.example.com', required: true }, { type: 'text', name: 'url', title: 'Web URL', placeholder: 'https://jira.example.com', required: true },
{ type: 'text', name: 'api_url', title: 'JIRA API URL', placeholder: 'If different from Web URL' }, { type: 'text', name: 'api_url', title: 'JIRA API URL', placeholder: 'If different from Web URL' },
{ type: 'text', name: 'project_key', placeholder: 'Project Key', required: true },
{ type: 'text', name: 'username', placeholder: '', required: true }, { type: 'text', name: 'username', placeholder: '', required: true },
{ type: 'password', name: 'password', placeholder: '', required: true }, { type: 'password', name: 'password', placeholder: '', required: true },
{ type: 'text', name: 'jira_issue_transition_id', placeholder: '' } { type: 'text', name: 'jira_issue_transition_id', title: 'Transition ID', placeholder: '' }
] ]
end end
# URLs to redirect from Gitlab issues pages to jira issue tracker
def project_url
"#{url}/issues/?jql=project=#{project_key}"
end
def issues_url def issues_url
"#{url}/browse/:id" "#{url}/browse/:id"
end end
@ -184,7 +172,7 @@ class JiraService < IssueTrackerService
def test_settings def test_settings
return unless client_url.present? return unless client_url.present?
# Test settings by getting the project # Test settings by getting the project
jira_request { jira_project.present? } jira_request { client.ServerInfo.all.attrs }
end end
private private

View File

@ -0,0 +1,4 @@
---
title: Remove project_key from the Jira configuration
merge_request: 12050
author:

View File

@ -98,11 +98,11 @@ in the table below.
| Field | Description | | Field | Description |
| ----- | ----------- | | ----- | ----------- |
| `Web URL` | The base URL to the JIRA instance web interface which is being linked to this GitLab project. E.g., `https://jira.example.com`. | | `Web URL` | The base URL to the JIRA instance web interface which is being linked to this GitLab project. E.g., `https://jira.example.com`. |
| `JIRA API URL` | The base URL to the JIRA instance API. E.g., `https://jira-api.example.com`. This is optional. If not entered, the Web URL value be used. | | `JIRA API URL` | The base URL to the JIRA instance API. Web URL value will be used if not set. E.g., `https://jira-api.example.com`. |
| `Project key` | Put a JIRA project key (in uppercase), e.g. `MARS` in this field. This is only for testing the configuration settings. JIRA integration in GitLab works with _all_ JIRA projects in your JIRA instance. This field will be removed in a future release. | | `Project key` | Put a JIRA project key (in uppercase), e.g. `MARS` in this field. This is only for testing the configuration settings. JIRA integration in GitLab works with _all_ JIRA projects in your JIRA instance. This field will be removed in a future release. |
| `Username` | The user name created in [configuring JIRA step](#configuring-jira). | | `Username` | The user name created in [configuring JIRA step](#configuring-jira). |
| `Password` |The password of the user created in [configuring JIRA step](#configuring-jira). | | `Password` |The password of the user created in [configuring JIRA step](#configuring-jira). |
| `JIRA issue transition` | This is the ID of a transition that moves issues to a closed state. You can find this number under JIRA workflow administration ([see screenshot](img/jira_workflow_screenshot.png)). **Closing JIRA issues via commits or Merge Requests won't work if you don't set the ID correctly.** | | `Transition ID` | This is the ID of a transition that moves issues to a closed state. You can find this number under JIRA workflow administration ([see screenshot](img/jira_workflow_screenshot.png)). **Closing JIRA issues via commits or Merge Requests won't work if you don't set the ID correctly.** |
After saving the configuration, your GitLab project will be able to interact After saving the configuration, your GitLab project will be able to interact
with all JIRA projects in your JIRA instance. with all JIRA projects in your JIRA instance.

View File

@ -175,7 +175,6 @@ class Spinach::Features::ProjectServices < Spinach::FeatureSteps
fill_in 'JIRA API URL', with: 'http://jira.example/api' fill_in 'JIRA API URL', with: 'http://jira.example/api'
fill_in 'Username', with: 'gitlab' fill_in 'Username', with: 'gitlab'
fill_in 'Password', with: 'gitlab' fill_in 'Password', with: 'gitlab'
fill_in 'Project Key', with: 'GITLAB'
click_button 'Save' click_button 'Save'
end end

View File

@ -312,12 +312,6 @@ module API
type: String, type: String,
desc: 'The base URL to the JIRA instance API. Web URL value will be used if not set. E.g., https://jira-api.example.com' desc: 'The base URL to the JIRA instance API. Web URL value will be used if not set. E.g., https://jira-api.example.com'
}, },
{
required: true,
name: :project_key,
type: String,
desc: 'The short identifier for your JIRA project, all uppercase, e.g., PROJ'
},
{ {
required: false, required: false,
name: :username, name: :username,

View File

@ -6,17 +6,12 @@ feature 'Setup Jira service', :feature, :js do
let(:service) { project.create_jira_service } let(:service) { project.create_jira_service }
let(:url) { 'http://jira.example.com' } let(:url) { 'http://jira.example.com' }
let(:test_url) { 'http://jira.example.com/rest/api/2/serverInfo' }
def stub_project_url
WebMock.stub_request(:get, 'http://jira.example.com/rest/api/2/project/GitLabProject')
.with(basic_auth: %w(username password))
end
def fill_form(active = true) def fill_form(active = true)
check 'Active' if active check 'Active' if active
fill_in 'service_url', with: url fill_in 'service_url', with: url
fill_in 'service_project_key', with: 'GitLabProject'
fill_in 'service_username', with: 'username' fill_in 'service_username', with: 'username'
fill_in 'service_password', with: 'password' fill_in 'service_password', with: 'password'
fill_in 'service_jira_issue_transition_id', with: '25' fill_in 'service_jira_issue_transition_id', with: '25'
@ -31,11 +26,10 @@ feature 'Setup Jira service', :feature, :js do
describe 'user sets and activates Jira Service' do describe 'user sets and activates Jira Service' do
context 'when Jira connection test succeeds' do context 'when Jira connection test succeeds' do
before do
stub_project_url
end
it 'activates the JIRA service' do it 'activates the JIRA service' do
server_info = { key: 'value' }.to_json
WebMock.stub_request(:get, test_url).with(basic_auth: %w(username password)).to_return(body: server_info)
click_link('JIRA') click_link('JIRA')
fill_form fill_form
click_button('Test settings and save changes') click_button('Test settings and save changes')
@ -47,10 +41,6 @@ feature 'Setup Jira service', :feature, :js do
end end
context 'when Jira connection test fails' do context 'when Jira connection test fails' do
before do
stub_project_url.to_return(status: 401)
end
it 'shows errors when some required fields are not filled in' do it 'shows errors when some required fields are not filled in' do
click_link('JIRA') click_link('JIRA')
@ -64,6 +54,9 @@ feature 'Setup Jira service', :feature, :js do
end end
it 'activates the JIRA service' do it 'activates the JIRA service' do
WebMock.stub_request(:get, test_url).with(basic_auth: %w(username password))
.to_raise(JIRA::HTTPError.new(double(message: 'message')))
click_link('JIRA') click_link('JIRA')
fill_form fill_form
click_button('Test settings and save changes') click_button('Test settings and save changes')

View File

@ -15,7 +15,6 @@ describe JiraService, models: true do
end end
it { is_expected.to validate_presence_of(:url) } it { is_expected.to validate_presence_of(:url) }
it { is_expected.to validate_presence_of(:project_key) }
it_behaves_like 'issue tracker service URL attribute', :url it_behaves_like 'issue tracker service URL attribute', :url
end end
@ -34,7 +33,6 @@ describe JiraService, models: true do
active: true, active: true,
username: 'username', username: 'username',
password: 'test', password: 'test',
project_key: 'TEST',
jira_issue_transition_id: 24, jira_issue_transition_id: 24,
url: 'http://jira.test.com' url: 'http://jira.test.com'
) )
@ -88,7 +86,6 @@ describe JiraService, models: true do
url: 'http://jira.example.com', url: 'http://jira.example.com',
username: 'gitlab_jira_username', username: 'gitlab_jira_username',
password: 'gitlab_jira_password', password: 'gitlab_jira_password',
project_key: 'GitLabProject',
jira_issue_transition_id: "custom-id" jira_issue_transition_id: "custom-id"
) )
@ -196,15 +193,14 @@ describe JiraService, models: true do
project: create(:project), project: create(:project),
url: 'http://jira.example.com', url: 'http://jira.example.com',
username: 'jira_username', username: 'jira_username',
password: 'jira_password', password: 'jira_password'
project_key: 'GitLabProject'
) )
end end
def test_settings(api_url) def test_settings(api_url)
project_url = "http://#{api_url}/rest/api/2/project/GitLabProject" test_url = "http://#{api_url}/rest/api/2/serverInfo"
WebMock.stub_request(:get, project_url).with(basic_auth: %w(jira_username jira_password)) WebMock.stub_request(:get, test_url).with(basic_auth: %w(jira_username jira_password)).to_return(body: { url: 'http://url' }.to_json )
jira_service.test_settings jira_service.test_settings
end end

View File

@ -51,7 +51,7 @@ module JiraServiceHelper
end end
def jira_project_url def jira_project_url
JIRA_API + "/project/#{jira_tracker.project_key}" JIRA_API + "/project"
end end
def jira_api_comment_url(issue_id) def jira_api_comment_url(issue_id)