From 917c87a5040d3635bac9ed4ec98770d8f8118dd3 Mon Sep 17 00:00:00 2001 From: Jarka Kadlecova Date: Fri, 9 Jun 2017 15:01:55 +0200 Subject: Remove project_key from the Jira configuration --- app/models/project_services/jira_service.rb | 13 +++++-------- .../unreleased/31129-jira-project-key-elim.yml | 4 ++++ doc/user/project/integrations/jira.md | 4 ++-- features/steps/project/services.rb | 1 - lib/api/services.rb | 6 ------ .../projects/services/jira_service_spec.rb | 7 +++---- spec/models/project_services/jira_service_spec.rb | 22 +++++++++++++++------- spec/support/jira_service_helper.rb | 2 +- 8 files changed, 30 insertions(+), 29 deletions(-) create mode 100644 changelogs/unreleased/31129-jira-project-key-elim.yml diff --git a/app/models/project_services/jira_service.rb b/app/models/project_services/jira_service.rb index 2450fb43212..296e09e90a9 100644 --- a/app/models/project_services/jira_service.rb +++ b/app/models/project_services/jira_service.rb @@ -3,10 +3,8 @@ class JiraService < IssueTrackerService validates :url, url: true, presence: true, if: :activated? validates :api_url, url: true, allow_blank: true - validates :project_key, presence: true, if: :activated? - prop_accessor :username, :password, :url, :api_url, :project_key, - :jira_issue_transition_id, :title, :description + prop_accessor :username, :password, :url, :api_url, :jira_issue_transition_id, :title, :description before_update :reset_password @@ -55,7 +53,7 @@ class JiraService < IssueTrackerService end def jira_project - @jira_project ||= jira_request { client.Project.find(project_key) } + @jira_project ||= jira_request { client.Project.all.first } end def help @@ -88,16 +86,15 @@ class JiraService < IssueTrackerService [ { 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: 'project_key', placeholder: 'Project Key', required: true }, { type: 'text', name: 'username', 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 # URLs to redirect from Gitlab issues pages to jira issue tracker def project_url - "#{url}/issues/?jql=project=#{project_key}" + "#{url}/issues" end def issues_url @@ -184,7 +181,7 @@ class JiraService < IssueTrackerService def test_settings return unless client_url.present? # Test settings by getting the project - jira_request { jira_project.present? } + jira_project end private diff --git a/changelogs/unreleased/31129-jira-project-key-elim.yml b/changelogs/unreleased/31129-jira-project-key-elim.yml new file mode 100644 index 00000000000..bfa0e99f250 --- /dev/null +++ b/changelogs/unreleased/31129-jira-project-key-elim.yml @@ -0,0 +1,4 @@ +--- +title: Remove project_key from the Jira configuration +merge_request: 12050 +author: diff --git a/doc/user/project/integrations/jira.md b/doc/user/project/integrations/jira.md index a048260b033..7e4dfd112ae 100644 --- a/doc/user/project/integrations/jira.md +++ b/doc/user/project/integrations/jira.md @@ -99,10 +99,10 @@ in the table below. | ----- | ----------- | | `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. Web URL value will be used if not set. E.g., `https://jira-api.example.com`. | -| `Project key` | The short identifier for your JIRA project, all uppercase, e.g., `PROJ`. | +| `Project key` | The short identifier for your JIRA project, all uppercase, e.g., `PROJ`. (optional) - this key is used for redirecting to the correct project from issues tracker. | | `Username` | The user name 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 with the linked JIRA project. diff --git a/features/steps/project/services.rb b/features/steps/project/services.rb index 6bac4df16f8..62821e4b14e 100644 --- a/features/steps/project/services.rb +++ b/features/steps/project/services.rb @@ -175,7 +175,6 @@ class Spinach::Features::ProjectServices < Spinach::FeatureSteps fill_in 'JIRA API URL', with: 'http://jira.example/api' fill_in 'Username', with: 'gitlab' fill_in 'Password', with: 'gitlab' - fill_in 'Project Key', with: 'GITLAB' click_button 'Save' end diff --git a/lib/api/services.rb b/lib/api/services.rb index 47bd9940f77..77728f13e01 100644 --- a/lib/api/services.rb +++ b/lib/api/services.rb @@ -312,12 +312,6 @@ module API 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' }, - { - required: true, - name: :project_key, - type: String, - desc: 'The short identifier for your JIRA project, all uppercase, e.g., PROJ' - }, { required: false, name: :username, diff --git a/spec/features/projects/services/jira_service_spec.rb b/spec/features/projects/services/jira_service_spec.rb index c96d87e5708..9fc0658a084 100644 --- a/spec/features/projects/services/jira_service_spec.rb +++ b/spec/features/projects/services/jira_service_spec.rb @@ -6,13 +6,12 @@ feature 'Setup Jira service', :feature, :js do let(:service) { project.create_jira_service } let(:url) { 'http://jira.example.com' } - let(:project_url) { 'http://username:password@jira.example.com/rest/api/2/project/GitLabProject' } + let(:project_url) { 'http://username:password@jira.example.com/rest/api/2/project' } def fill_form(active = true) check 'Active' if active fill_in 'service_url', with: url - fill_in 'service_project_key', with: 'GitLabProject' fill_in 'service_username', with: 'username' fill_in 'service_password', with: 'password' fill_in 'service_jira_issue_transition_id', with: '25' @@ -28,7 +27,7 @@ feature 'Setup Jira service', :feature, :js do describe 'user sets and activates Jira Service' do context 'when Jira connection test succeeds' do before do - WebMock.stub_request(:get, project_url) + WebMock.stub_request(:get, project_url).to_return(body: [double(present?: true)].to_json ) end it 'activates the JIRA service' do @@ -44,7 +43,7 @@ feature 'Setup Jira service', :feature, :js do context 'when Jira connection test fails' do before do - WebMock.stub_request(:get, project_url).to_return(status: 401) + WebMock.stub_request(:get, project_url).to_return(body: [].to_json ) end it 'shows errors when some required fields are not filled in' do diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb index 0ee050196e4..519a4ca6ba6 100644 --- a/spec/models/project_services/jira_service_spec.rb +++ b/spec/models/project_services/jira_service_spec.rb @@ -13,7 +13,6 @@ describe JiraService, models: true do before { subject.active = true } 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 end @@ -30,7 +29,6 @@ describe JiraService, models: true do active: true, username: 'username', password: 'test', - project_key: 'TEST', jira_issue_transition_id: 24, url: 'http://jira.test.com' ) @@ -84,7 +82,6 @@ describe JiraService, models: true do url: 'http://jira.example.com', username: 'gitlab_jira_username', password: 'gitlab_jira_password', - project_key: 'GitLabProject', jira_issue_transition_id: "custom-id" ) @@ -192,15 +189,14 @@ describe JiraService, models: true do project: create(:project), url: 'http://jira.example.com', username: 'jira_username', - password: 'jira_password', - project_key: 'GitLabProject' + password: 'jira_password' ) end def test_settings(api_url) - project_url = "http://jira_username:jira_password@#{api_url}/rest/api/2/project/GitLabProject" + project_url = "http://jira_username:jira_password@#{api_url}/rest/api/2/project" - WebMock.stub_request(:get, project_url) + WebMock.stub_request(:get, project_url).to_return(body: ['project'].to_json ) jira_service.test_settings end @@ -382,4 +378,16 @@ describe JiraService, models: true do end end end + + describe '#project_url' do + it 'returns url to all JIRA issues' do + service = described_class.new( + properties: { + url: 'http://jira.example.com' + } + ) + + expect(service.project_url).to eq('http://jira.example.com/issues') + end + end end diff --git a/spec/support/jira_service_helper.rb b/spec/support/jira_service_helper.rb index 97ae0b6afc5..0b5f66597fd 100644 --- a/spec/support/jira_service_helper.rb +++ b/spec/support/jira_service_helper.rb @@ -51,7 +51,7 @@ module JiraServiceHelper end def jira_project_url - JIRA_API + "/project/#{jira_tracker.project_key}" + JIRA_API + "/project" end def jira_api_comment_url(issue_id) -- cgit v1.2.1