Merge branch 'move_external_issue_tracker_away_from_yml_config' into 'master'
Move external issue tracker away from yml config See merge request !1442
This commit is contained in:
commit
fc17b440f9
|
|
@ -9,17 +9,3 @@ class @ProjectNew
|
||||||
|
|
||||||
initEvents: ->
|
initEvents: ->
|
||||||
disableButtonIfEmptyField '#project_name', '.project-submit'
|
disableButtonIfEmptyField '#project_name', '.project-submit'
|
||||||
|
|
||||||
$('#project_issues_enabled').change ->
|
|
||||||
if ($(this).is(':checked') == true)
|
|
||||||
$('#project_issues_tracker').removeAttr('disabled')
|
|
||||||
else
|
|
||||||
$('#project_issues_tracker').attr('disabled', 'disabled')
|
|
||||||
|
|
||||||
$('#project_issues_tracker').change()
|
|
||||||
|
|
||||||
$('#project_issues_tracker').change ->
|
|
||||||
if ($(this).val() == gon.default_issues_tracker || $(this).is(':disabled'))
|
|
||||||
$('#project_issues_tracker_id').attr('disabled', 'disabled')
|
|
||||||
else
|
|
||||||
$('#project_issues_tracker_id').removeAttr('disabled')
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,11 @@ class Projects::ServicesController < Projects::ApplicationController
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if @service.update_attributes(service_params)
|
if @service.update_attributes(service_params)
|
||||||
redirect_to edit_project_service_path(@project, @service.to_param)
|
if @service.activated? && @service.issue_tracker?
|
||||||
|
@project.update_attributes(issues_tracker: @service.to_param)
|
||||||
|
end
|
||||||
|
redirect_to edit_project_service_path(@project, @service.to_param),
|
||||||
|
notice: 'Successfully updated.'
|
||||||
else
|
else
|
||||||
render 'edit'
|
render 'edit'
|
||||||
end
|
end
|
||||||
|
|
@ -45,7 +49,8 @@ class Projects::ServicesController < Projects::ApplicationController
|
||||||
:title, :token, :type, :active, :api_key, :subdomain,
|
:title, :token, :type, :active, :api_key, :subdomain,
|
||||||
:room, :recipients, :project_url, :webhook,
|
:room, :recipients, :project_url, :webhook,
|
||||||
:user_key, :device, :priority, :sound, :bamboo_url, :username, :password,
|
:user_key, :device, :priority, :sound, :bamboo_url, :username, :password,
|
||||||
:build_key, :server, :teamcity_url, :build_type
|
:build_key, :server, :teamcity_url, :build_type,
|
||||||
|
:description, :issues_url, :new_issue_url
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -16,45 +16,38 @@ module IssuesHelper
|
||||||
def url_for_project_issues(project = @project)
|
def url_for_project_issues(project = @project)
|
||||||
return '' if project.nil?
|
return '' if project.nil?
|
||||||
|
|
||||||
if project.used_default_issues_tracker? || !external_issues_tracker_enabled?
|
if project.default_issues_tracker?
|
||||||
project_issues_path(project)
|
project_issues_path(project)
|
||||||
else
|
else
|
||||||
url = Gitlab.config.issues_tracker[project.issues_tracker]['project_url']
|
project.external_issue_tracker.project_url
|
||||||
url.gsub(':project_id', project.id.to_s).
|
|
||||||
gsub(':issues_tracker_id', project.issues_tracker_id.to_s)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def url_for_new_issue(project = @project)
|
def url_for_new_issue(project = @project)
|
||||||
return '' if project.nil?
|
return '' if project.nil?
|
||||||
|
|
||||||
if project.used_default_issues_tracker? || !external_issues_tracker_enabled?
|
if project.default_issues_tracker?
|
||||||
url = new_project_issue_path project_id: project
|
url = new_project_issue_path project_id: project
|
||||||
else
|
else
|
||||||
issues_tracker = Gitlab.config.issues_tracker[project.issues_tracker]
|
project.external_issue_tracker.new_issue_url
|
||||||
url = issues_tracker['new_issue_url']
|
|
||||||
url.gsub(':project_id', project.id.to_s).
|
|
||||||
gsub(':issues_tracker_id', project.issues_tracker_id.to_s)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def url_for_issue(issue_iid, project = @project)
|
def url_for_issue(issue_iid, project = @project)
|
||||||
return '' if project.nil?
|
return '' if project.nil?
|
||||||
|
|
||||||
if project.used_default_issues_tracker? || !external_issues_tracker_enabled?
|
if project.default_issues_tracker?
|
||||||
url = project_issue_url project_id: project, id: issue_iid
|
url = project_issue_url project_id: project, id: issue_iid
|
||||||
else
|
else
|
||||||
url = Gitlab.config.issues_tracker[project.issues_tracker]['issues_url']
|
url = project.external_issue_tracker.issues_url
|
||||||
url.gsub(':id', issue_iid.to_s).
|
url.gsub(':id', issue_iid.to_s)
|
||||||
gsub(':project_id', project.id.to_s).
|
|
||||||
gsub(':issues_tracker_id', project.issues_tracker_id.to_s)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def title_for_issue(issue_iid, project = @project)
|
def title_for_issue(issue_iid, project = @project)
|
||||||
return '' if project.nil?
|
return '' if project.nil?
|
||||||
|
|
||||||
if project.used_default_issues_tracker?
|
if project.default_issues_tracker?
|
||||||
issue = project.issues.where(iid: issue_iid).first
|
issue = project.issues.where(iid: issue_iid).first
|
||||||
return issue.title if issue
|
return issue.title if issue
|
||||||
end
|
end
|
||||||
|
|
@ -77,11 +70,6 @@ module IssuesHelper
|
||||||
ts.html_safe
|
ts.html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks if issues_tracker setting exists in gitlab.yml
|
|
||||||
def external_issues_tracker_enabled?
|
|
||||||
Gitlab.config.issues_tracker && Gitlab.config.issues_tracker.values.any?
|
|
||||||
end
|
|
||||||
|
|
||||||
def bulk_update_milestone_options
|
def bulk_update_milestone_options
|
||||||
options_for_select(['None (backlog)']) +
|
options_for_select(['None (backlog)']) +
|
||||||
options_from_collection_for_select(project_active_milestones, 'id',
|
options_from_collection_for_select(project_active_milestones, 'id',
|
||||||
|
|
|
||||||
|
|
@ -72,18 +72,6 @@ module ProjectsHelper
|
||||||
@project.milestones.active.order("due_date, title ASC")
|
@project.milestones.active.order("due_date, title ASC")
|
||||||
end
|
end
|
||||||
|
|
||||||
def project_issues_trackers(current_tracker = nil)
|
|
||||||
values = Project.issues_tracker.values.map do |tracker_key|
|
|
||||||
if tracker_key.to_sym == :gitlab
|
|
||||||
['GitLab', tracker_key]
|
|
||||||
else
|
|
||||||
[Gitlab.config.issues_tracker[tracker_key]['title'] || tracker_key, tracker_key]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
options_for_select(values, current_tracker)
|
|
||||||
end
|
|
||||||
|
|
||||||
def link_to_toggle_star(title, starred, signed_in)
|
def link_to_toggle_star(title, starred, signed_in)
|
||||||
cls = 'star-btn'
|
cls = 'star-btn'
|
||||||
cls << ' disabled' unless signed_in
|
cls << ' disabled' unless signed_in
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,12 @@ class Project < ActiveRecord::Base
|
||||||
has_one :bamboo_service, dependent: :destroy
|
has_one :bamboo_service, dependent: :destroy
|
||||||
has_one :teamcity_service, dependent: :destroy
|
has_one :teamcity_service, dependent: :destroy
|
||||||
has_one :pushover_service, dependent: :destroy
|
has_one :pushover_service, dependent: :destroy
|
||||||
has_one :forked_project_link, dependent: :destroy, foreign_key: 'forked_to_project_id'
|
has_one :jira_service, dependent: :destroy
|
||||||
|
has_one :redmine_service, dependent: :destroy
|
||||||
|
has_one :custom_issue_tracker_service, dependent: :destroy
|
||||||
|
|
||||||
|
has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id"
|
||||||
|
|
||||||
has_one :forked_from_project, through: :forked_project_link
|
has_one :forked_from_project, through: :forked_project_link
|
||||||
# Merge Requests for target project should be removed with it
|
# Merge Requests for target project should be removed with it
|
||||||
has_many :merge_requests, dependent: :destroy, foreign_key: 'target_project_id'
|
has_many :merge_requests, dependent: :destroy, foreign_key: 'target_project_id'
|
||||||
|
|
@ -144,7 +149,7 @@ class Project < ActiveRecord::Base
|
||||||
scope :public_and_internal_only, -> { where(visibility_level: Project.public_and_internal_levels) }
|
scope :public_and_internal_only, -> { where(visibility_level: Project.public_and_internal_levels) }
|
||||||
scope :non_archived, -> { where(archived: false) }
|
scope :non_archived, -> { where(archived: false) }
|
||||||
|
|
||||||
enumerize :issues_tracker, in: (Gitlab.config.issues_tracker.keys).append(:gitlab), default: :gitlab
|
enumerize :issues_tracker, in: (Service.issue_tracker_service_list).append(:gitlab), default: :gitlab
|
||||||
|
|
||||||
state_machine :import_status, initial: :none do
|
state_machine :import_status, initial: :none do
|
||||||
event :import_start do
|
event :import_start do
|
||||||
|
|
@ -305,19 +310,34 @@ class Project < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def issue_exists?(issue_id)
|
def issue_exists?(issue_id)
|
||||||
if used_default_issues_tracker?
|
if default_issues_tracker?
|
||||||
self.issues.where(iid: issue_id).first.present?
|
self.issues.where(iid: issue_id).first.present?
|
||||||
else
|
else
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def used_default_issues_tracker?
|
def default_issues_tracker?
|
||||||
self.issues_tracker == Project.issues_tracker.default_value
|
if external_issue_tracker
|
||||||
|
false
|
||||||
|
else
|
||||||
|
unless self.issues_tracker == Project.issues_tracker.default_value
|
||||||
|
self.update_attributes(issues_tracker: Project.issues_tracker.default_value)
|
||||||
|
end
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def external_issues_trackers
|
||||||
|
services.select { |service| service.issue_tracker? }
|
||||||
|
end
|
||||||
|
|
||||||
|
def external_issue_tracker
|
||||||
|
@external_issues_tracker ||= external_issues_trackers.select(&:activated?).first
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_have_issues_tracker_id?
|
def can_have_issues_tracker_id?
|
||||||
self.issues_enabled && !self.used_default_issues_tracker?
|
self.issues_enabled && !self.default_issues_tracker?
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_missing_services
|
def build_missing_services
|
||||||
|
|
@ -332,7 +352,7 @@ class Project < ActiveRecord::Base
|
||||||
|
|
||||||
def available_services_names
|
def available_services_names
|
||||||
%w(gitlab_ci campfire hipchat pivotaltracker flowdock assembla
|
%w(gitlab_ci campfire hipchat pivotaltracker flowdock assembla
|
||||||
emails_on_push gemnasium slack pushover buildbox bamboo teamcity)
|
emails_on_push gemnasium slack pushover buildbox bamboo teamcity jira redmine custom_issue_tracker)
|
||||||
end
|
end
|
||||||
|
|
||||||
def gitlab_ci?
|
def gitlab_ci?
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
class CustomIssueTrackerService < IssueTrackerService
|
||||||
|
|
||||||
|
prop_accessor :title, :description, :project_url, :issues_url, :new_issue_url
|
||||||
|
|
||||||
|
def title
|
||||||
|
if self.properties && self.properties['title'].present?
|
||||||
|
self.properties['title']
|
||||||
|
else
|
||||||
|
'Custom Issue Tracker'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def description
|
||||||
|
if self.properties && self.properties['description'].present?
|
||||||
|
self.properties['description']
|
||||||
|
else
|
||||||
|
'Custom issue tracker'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_param
|
||||||
|
'custom_issue_tracker'
|
||||||
|
end
|
||||||
|
|
||||||
|
def fields
|
||||||
|
[
|
||||||
|
{ type: 'text', name: 'title', placeholder: title },
|
||||||
|
{ type: 'text', name: 'description', placeholder: description },
|
||||||
|
{ type: 'text', name: 'project_url', placeholder: 'Project url' },
|
||||||
|
{ type: 'text', name: 'issues_url', placeholder: 'Issue url'},
|
||||||
|
{ type: 'text', name: 'new_issue_url', placeholder: 'New Issue url'}
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize_properties
|
||||||
|
self.properties = {} if properties.nil?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
class IssueTrackerService < Service
|
||||||
|
|
||||||
|
validates :project_url, :issues_url, :new_issue_url, presence: true, if: :activated?
|
||||||
|
|
||||||
|
def category
|
||||||
|
:issue_tracker
|
||||||
|
end
|
||||||
|
|
||||||
|
def project_url
|
||||||
|
# implement inside child
|
||||||
|
end
|
||||||
|
|
||||||
|
def issues_url
|
||||||
|
# implement inside child
|
||||||
|
end
|
||||||
|
|
||||||
|
def new_issue_url
|
||||||
|
# implement inside child
|
||||||
|
end
|
||||||
|
|
||||||
|
def fields
|
||||||
|
[
|
||||||
|
{ type: 'text', name: 'description', placeholder: description },
|
||||||
|
{ type: 'text', name: 'project_url', placeholder: 'Project url' },
|
||||||
|
{ type: 'text', name: 'issues_url', placeholder: 'Issue url'},
|
||||||
|
{ type: 'text', name: 'new_issue_url', placeholder: 'New Issue url'}
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize_properties
|
||||||
|
if properties.nil?
|
||||||
|
if enabled_in_gitlab_config
|
||||||
|
self.properties = {
|
||||||
|
title: issues_tracker['title'],
|
||||||
|
project_url: set_project_url,
|
||||||
|
issues_url: issues_tracker['issues_url'],
|
||||||
|
new_issue_url: issues_tracker['new_issue_url']
|
||||||
|
}
|
||||||
|
else
|
||||||
|
self.properties = {}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def enabled_in_gitlab_config
|
||||||
|
Gitlab.config.issues_tracker &&
|
||||||
|
Gitlab.config.issues_tracker.values.any? &&
|
||||||
|
issues_tracker
|
||||||
|
end
|
||||||
|
|
||||||
|
def issues_tracker
|
||||||
|
Gitlab.config.issues_tracker[to_param]
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_project_url
|
||||||
|
id = self.project.issues_tracker_id
|
||||||
|
|
||||||
|
if id
|
||||||
|
issues_tracker['project_url'].gsub(":issues_tracker_id", id)
|
||||||
|
else
|
||||||
|
issues_tracker['project_url']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
class JiraService < IssueTrackerService
|
||||||
|
|
||||||
|
prop_accessor :title, :description, :project_url, :issues_url, :new_issue_url
|
||||||
|
|
||||||
|
def title
|
||||||
|
if self.properties && self.properties['title'].present?
|
||||||
|
self.properties['title']
|
||||||
|
else
|
||||||
|
'JIRA'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def description
|
||||||
|
if self.properties && self.properties['description'].present?
|
||||||
|
self.properties['description']
|
||||||
|
else
|
||||||
|
'Jira issue tracker'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_param
|
||||||
|
'jira'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
class RedmineService < IssueTrackerService
|
||||||
|
|
||||||
|
prop_accessor :title, :description, :project_url, :issues_url, :new_issue_url
|
||||||
|
|
||||||
|
def title
|
||||||
|
if self.properties && self.properties['title'].present?
|
||||||
|
self.properties['title']
|
||||||
|
else
|
||||||
|
'Redmine'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def description
|
||||||
|
if self.properties && self.properties['description'].present?
|
||||||
|
self.properties['description']
|
||||||
|
else
|
||||||
|
'Redmine issue tracker'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_param
|
||||||
|
'redmine'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -86,4 +86,12 @@ class Service < ActiveRecord::Base
|
||||||
def async_execute(data)
|
def async_execute(data)
|
||||||
Sidekiq::Client.enqueue(ProjectServiceWorker, id, data)
|
Sidekiq::Client.enqueue(ProjectServiceWorker, id, data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def issue_tracker?
|
||||||
|
self.category == :issue_tracker
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.issue_tracker_service_list
|
||||||
|
Service.select(&:issue_tracker?).map{ |s| s.to_param }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@
|
||||||
%i.fa.fa-exclamation-circle
|
%i.fa.fa-exclamation-circle
|
||||||
%span
|
%span
|
||||||
Issues
|
Issues
|
||||||
- if @project.used_default_issues_tracker?
|
- if @project.default_issues_tracker?
|
||||||
%span.count.issue_counter= @project.issues.opened.count
|
%span.count.issue_counter= @project.issues.opened.count
|
||||||
|
|
||||||
- if project_nav_tab? :merge_requests
|
- if project_nav_tab? :merge_requests
|
||||||
|
|
|
||||||
|
|
@ -51,15 +51,6 @@
|
||||||
= f.check_box :issues_enabled
|
= f.check_box :issues_enabled
|
||||||
%span.descr Lightweight issue tracking system for this project
|
%span.descr Lightweight issue tracking system for this project
|
||||||
|
|
||||||
- if Project.issues_tracker.values.count > 1
|
|
||||||
.form-group
|
|
||||||
= f.label :issues_tracker, "Issues tracker", class: 'control-label'
|
|
||||||
.col-sm-10= f.select(:issues_tracker, project_issues_trackers(@project.issues_tracker), {}, { disabled: !@project.issues_enabled })
|
|
||||||
|
|
||||||
.form-group
|
|
||||||
= f.label :issues_tracker_id, "Project name or id in issues tracker", class: 'control-label'
|
|
||||||
.col-sm-10= f.text_field :issues_tracker_id, disabled: !@project.can_have_issues_tracker_id?, class: 'form-control'
|
|
||||||
|
|
||||||
.form-group
|
.form-group
|
||||||
= f.label :merge_requests_enabled, "Merge Requests", class: 'control-label'
|
= f.label :merge_requests_enabled, "Merge Requests", class: 'control-label'
|
||||||
.col-sm-10
|
.col-sm-10
|
||||||
|
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
Feature: Project Issue Tracker
|
|
||||||
Background:
|
|
||||||
Given I sign in as a user
|
|
||||||
And I own project "Shop"
|
|
||||||
And project "Shop" has issues enabled
|
|
||||||
And I visit project "Shop" page
|
|
||||||
|
|
||||||
Scenario: I set the issue tracker to "GitLab"
|
|
||||||
When I visit edit project "Shop" page
|
|
||||||
And change the issue tracker to "GitLab"
|
|
||||||
And I save project
|
|
||||||
Then I the project should have "GitLab" as issue tracker
|
|
||||||
|
|
||||||
Scenario: I set the issue tracker to "Redmine"
|
|
||||||
When I visit edit project "Shop" page
|
|
||||||
And change the issue tracker to "Redmine"
|
|
||||||
And I save project
|
|
||||||
Then I the project should have "Redmine" as issue tracker
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
class Spinach::Features::ProjectIssueTracker < Spinach::FeatureSteps
|
|
||||||
include SharedAuthentication
|
|
||||||
include SharedProject
|
|
||||||
include SharedPaths
|
|
||||||
|
|
||||||
step 'project "Shop" has issues enabled' do
|
|
||||||
@project = Project.find_by(name: "Shop")
|
|
||||||
@project ||= create(:project, name: "Shop", namespace: @user.namespace)
|
|
||||||
@project.issues_enabled = true
|
|
||||||
end
|
|
||||||
|
|
||||||
step 'change the issue tracker to "GitLab"' do
|
|
||||||
select 'GitLab', from: 'project_issues_tracker'
|
|
||||||
end
|
|
||||||
|
|
||||||
step 'I the project should have "GitLab" as issue tracker' do
|
|
||||||
find_field('project_issues_tracker').value.should == 'gitlab'
|
|
||||||
end
|
|
||||||
|
|
||||||
step 'change the issue tracker to "Redmine"' do
|
|
||||||
select 'Redmine', from: 'project_issues_tracker'
|
|
||||||
end
|
|
||||||
|
|
||||||
step 'I the project should have "Redmine" as issue tracker' do
|
|
||||||
find_field('project_issues_tracker').value.should == 'redmine'
|
|
||||||
end
|
|
||||||
|
|
||||||
step 'I save project' do
|
|
||||||
click_button 'Save changes'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
@ -208,7 +208,7 @@ module Gitlab
|
||||||
end
|
end
|
||||||
|
|
||||||
def reference_issue(identifier, project = @project, prefix_text = nil)
|
def reference_issue(identifier, project = @project, prefix_text = nil)
|
||||||
if project.used_default_issues_tracker? || !external_issues_tracker_enabled?
|
if project.default_issues_tracker?
|
||||||
if project.issue_exists? identifier
|
if project.issue_exists? identifier
|
||||||
url = url_for_issue(identifier, project)
|
url = url_for_issue(identifier, project)
|
||||||
title = title_for_issue(identifier, project)
|
title = title_for_issue(identifier, project)
|
||||||
|
|
@ -220,10 +220,8 @@ module Gitlab
|
||||||
link_to("#{prefix_text}##{identifier}", url, options)
|
link_to("#{prefix_text}##{identifier}", url, options)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
config = Gitlab.config
|
if project.external_issue_tracker.present?
|
||||||
external_issue_tracker = config.issues_tracker[project.issues_tracker]
|
reference_external_issue(identifier, project,
|
||||||
if external_issue_tracker.present?
|
|
||||||
reference_external_issue(identifier, external_issue_tracker, project,
|
|
||||||
prefix_text)
|
prefix_text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -267,10 +265,10 @@ module Gitlab
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def reference_external_issue(identifier, issue_tracker, project = @project,
|
def reference_external_issue(identifier, project = @project,
|
||||||
prefix_text = nil)
|
prefix_text = nil)
|
||||||
url = url_for_issue(identifier, project)
|
url = url_for_issue(identifier, project)
|
||||||
title = issue_tracker['title']
|
title = project.external_issue_tracker.title
|
||||||
|
|
||||||
options = html_options.merge(
|
options = html_options.merge(
|
||||||
title: "Issue in #{title}",
|
title: "Issue in #{title}",
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,19 @@ FactoryGirl.define do
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :redmine_project, parent: :project do
|
factory :redmine_project, parent: :project do
|
||||||
issues_tracker { "redmine" }
|
after :create do |project|
|
||||||
issues_tracker_id { "project_name_in_redmine" }
|
project.create_redmine_service(
|
||||||
|
active: true,
|
||||||
|
properties: {
|
||||||
|
'project_url' => 'http://redmine/projects/project_name_in_redmine',
|
||||||
|
'issues_url' => "http://redmine/#{project.id}/project_name_in_redmine/:id",
|
||||||
|
'new_issue_url' => 'http://redmine/projects/project_name_in_redmine/issues/new'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
after :create do |project|
|
||||||
|
project.issues_tracker = 'redmine'
|
||||||
|
project.issues_tracker_id = 'project_name_in_redmine'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -296,10 +296,13 @@ describe GitlabMarkdownHelper do
|
||||||
let(:reference) { "JIRA-#{issue.iid}" }
|
let(:reference) { "JIRA-#{issue.iid}" }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
issue_tracker_config = { "jira" => { "title" => "JIRA tracker", "issues_url" => "http://jira.example/browse/:id" } }
|
jira = @project.create_jira_service if @project.jira_service.nil?
|
||||||
Gitlab.config.stub(:issues_tracker).and_return(issue_tracker_config)
|
properties = {"title"=>"JIRA tracker", "project_url"=>"http://jira.example/issues/?jql=project=A", "issues_url"=>"http://jira.example/browse/:id", "new_issue_url"=>"http://jira.example/secure/CreateIssue.jspa"}
|
||||||
@project.stub(:issues_tracker).and_return("jira")
|
jira.update_attributes(properties: properties, active: true)
|
||||||
@project.stub(:issues_tracker_id).and_return("JIRA")
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
@project.jira_service.destroy! unless @project.jira_service.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should link using a valid id" do
|
it "should link using a valid id" do
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ describe IssuesHelper do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe :url_for_project_issues do
|
describe :url_for_project_issues do
|
||||||
let(:project_url) { Gitlab.config.issues_tracker.redmine.project_url}
|
let(:project_url) { ext_project.external_issue_tracker.project_url }
|
||||||
let(:ext_expected) do
|
let(:ext_expected) do
|
||||||
project_url.gsub(':project_id', ext_project.id.to_s)
|
project_url.gsub(':project_id', ext_project.id.to_s)
|
||||||
.gsub(':issues_tracker_id', ext_project.issues_tracker_id.to_s)
|
.gsub(':issues_tracker_id', ext_project.issues_tracker_id.to_s)
|
||||||
|
|
@ -54,17 +54,16 @@ describe IssuesHelper do
|
||||||
Gitlab.config.stub(:issues_tracker).and_return(nil)
|
Gitlab.config.stub(:issues_tracker).and_return(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return path to internal tracker" do
|
it "should return path to external tracker" do
|
||||||
url_for_project_issues.should match(polymorphic_path([@project]))
|
url_for_project_issues.should match(ext_expected)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe :url_for_issue do
|
describe :url_for_issue do
|
||||||
let(:issue_id) { 3 }
|
let(:issues_url) { ext_project.external_issue_tracker.issues_url}
|
||||||
let(:issues_url) { Gitlab.config.issues_tracker.redmine.issues_url}
|
|
||||||
let(:ext_expected) do
|
let(:ext_expected) do
|
||||||
issues_url.gsub(':id', issue_id.to_s)
|
issues_url.gsub(':id', issue.iid.to_s)
|
||||||
.gsub(':project_id', ext_project.id.to_s)
|
.gsub(':project_id', ext_project.id.to_s)
|
||||||
.gsub(':issues_tracker_id', ext_project.issues_tracker_id.to_s)
|
.gsub(':issues_tracker_id', ext_project.issues_tracker_id.to_s)
|
||||||
end
|
end
|
||||||
|
|
@ -78,7 +77,7 @@ describe IssuesHelper do
|
||||||
it "should return path to external tracker" do
|
it "should return path to external tracker" do
|
||||||
@project = ext_project
|
@project = ext_project
|
||||||
|
|
||||||
url_for_issue(issue_id).should match(ext_expected)
|
url_for_issue(issue.iid).should match(ext_expected)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return empty string if project nil" do
|
it "should return empty string if project nil" do
|
||||||
|
|
@ -93,14 +92,14 @@ describe IssuesHelper do
|
||||||
Gitlab.config.stub(:issues_tracker).and_return(nil)
|
Gitlab.config.stub(:issues_tracker).and_return(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return internal path" do
|
it "should return external path" do
|
||||||
url_for_issue(issue.iid).should match(polymorphic_path([@project, issue]))
|
url_for_issue(issue.iid).should match(ext_expected)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe :url_for_new_issue do
|
describe :url_for_new_issue do
|
||||||
let(:issues_url) { Gitlab.config.issues_tracker.redmine.new_issue_url}
|
let(:issues_url) { ext_project.external_issue_tracker.new_issue_url }
|
||||||
let(:ext_expected) do
|
let(:ext_expected) do
|
||||||
issues_url.gsub(':project_id', ext_project.id.to_s)
|
issues_url.gsub(':project_id', ext_project.id.to_s)
|
||||||
.gsub(':issues_tracker_id', ext_project.issues_tracker_id.to_s)
|
.gsub(':issues_tracker_id', ext_project.issues_tracker_id.to_s)
|
||||||
|
|
@ -131,7 +130,7 @@ describe IssuesHelper do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return internal path" do
|
it "should return internal path" do
|
||||||
url_for_new_issue.should match(new_project_issue_path(@project))
|
url_for_new_issue.should match(ext_expected)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,11 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe ProjectsHelper do
|
describe ProjectsHelper do
|
||||||
describe '#project_issues_trackers' do
|
|
||||||
it "returns the correct issues trackers available" do
|
|
||||||
project_issues_trackers.should ==
|
|
||||||
"<option value=\"redmine\">Redmine</option>\n" \
|
|
||||||
"<option value=\"gitlab\">GitLab</option>"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the correct issues trackers available with current tracker 'gitlab' selected" do
|
|
||||||
project_issues_trackers('gitlab').should ==
|
|
||||||
"<option value=\"redmine\">Redmine</option>\n" \
|
|
||||||
"<option selected=\"selected\" value=\"gitlab\">GitLab</option>"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns the correct issues trackers available with current tracker 'redmine' selected" do
|
|
||||||
project_issues_trackers('redmine').should ==
|
|
||||||
"<option selected=\"selected\" value=\"redmine\">Redmine</option>\n" \
|
|
||||||
"<option value=\"gitlab\">GitLab</option>"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#project_status_css_class" do
|
describe "#project_status_css_class" do
|
||||||
it "returns appropriate class" do
|
it "returns appropriate class" do
|
||||||
project_status_css_class("started").should == "active"
|
project_status_css_class("started").should == "active"
|
||||||
project_status_css_class("failed").should == "danger"
|
project_status_css_class("failed").should == "danger"
|
||||||
project_status_css_class("finished").should == "success"
|
project_status_css_class("finished").should == "success"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ describe Gitlab::ReferenceExtractor do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'extracts JIRA issue references' do
|
it 'extracts JIRA issue references' do
|
||||||
Gitlab.config.gitlab.stub(:issues_tracker).and_return('jira')
|
|
||||||
subject.analyze('this one talks about issue JIRA-1234', nil)
|
subject.analyze('this one talks about issue JIRA-1234', nil)
|
||||||
subject.issues.should == [{ project: nil, id: 'JIRA-1234' }]
|
subject.issues.should == [{ project: nil, id: 'JIRA-1234' }]
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,83 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe JiraService do
|
||||||
|
describe "Associations" do
|
||||||
|
it { should belong_to :project }
|
||||||
|
it { should have_one :service_hook }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "Validations" do
|
||||||
|
context "active" do
|
||||||
|
before do
|
||||||
|
subject.active = true
|
||||||
|
end
|
||||||
|
|
||||||
|
it { should validate_presence_of :project_url }
|
||||||
|
it { should validate_presence_of :issues_url }
|
||||||
|
it { should validate_presence_of :new_issue_url }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'description and title' do
|
||||||
|
let(:project) { create(:project) }
|
||||||
|
|
||||||
|
context 'when it is not set' do
|
||||||
|
before do
|
||||||
|
@service = project.create_jira_service(active: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
@service.destroy!
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be initialized' do
|
||||||
|
expect(@service.title).to eq('JIRA')
|
||||||
|
expect(@service.description).to eq("Jira issue tracker")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when it is set' do
|
||||||
|
before do
|
||||||
|
properties = { 'title' => 'Jira One', 'description' => 'Jira One issue tracker' }
|
||||||
|
@service = project.create_jira_service(active: true, properties: properties)
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
@service.destroy!
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should be correct" do
|
||||||
|
expect(@service.title).to eq('Jira One')
|
||||||
|
expect(@service.description).to eq('Jira One issue tracker')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'project and issue urls' do
|
||||||
|
let(:project) { create(:project) }
|
||||||
|
|
||||||
|
context 'when gitlab.yml was initialized' do
|
||||||
|
before do
|
||||||
|
settings = { "jira" => {
|
||||||
|
"title" => "Jira",
|
||||||
|
"project_url" => "http://jira.sample/projects/project_a",
|
||||||
|
"issues_url" => "http://jira.sample/issues/:id",
|
||||||
|
"new_issue_url" => "http://jira.sample/projects/project_a/issues/new"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Gitlab.config.stub(:issues_tracker).and_return(settings)
|
||||||
|
@service = project.create_jira_service(active: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
@service.destroy!
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be prepopulated with the settings' do
|
||||||
|
expect(@service.properties[:project_url]).to eq('http://jira.sample/projects/project_a')
|
||||||
|
expect(@service.properties[:issues_url]).to eq("http://jira.sample/issues/:id")
|
||||||
|
expect(@service.properties[:new_issue_url]).to eq("http://jira.sample/projects/project_a/issues/new")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -198,16 +198,16 @@ describe Project do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe :used_default_issues_tracker? do
|
describe :default_issues_tracker? do
|
||||||
let(:project) { create(:project) }
|
let(:project) { create(:project) }
|
||||||
let(:ext_project) { create(:redmine_project) }
|
let(:ext_project) { create(:redmine_project) }
|
||||||
|
|
||||||
it 'should be true if used internal tracker' do
|
it "should be true if used internal tracker" do
|
||||||
project.used_default_issues_tracker?.should be_true
|
project.default_issues_tracker?.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be false if used other tracker' do
|
it "should be false if used other tracker" do
|
||||||
ext_project.used_default_issues_tracker?.should be_false
|
ext_project.default_issues_tracker?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue