Commit 8e1f032e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'create_gitlab_internal_issue_service' into 'master'

Create gitlab internal issue service

Part of #1908

Create a default gitlab issue tracker service which will replace having issue tracker fields for project.

See merge request !1449
parents 5914c7e1 68f73024
......@@ -181,7 +181,7 @@ class ApplicationController < ActionController::Base
end
def add_gon_variables
gon.default_issues_tracker = Project.issues_tracker.default_value
gon.default_issues_tracker = Project.new.default_issue_tracker.to_param
gon.api_version = API::API.version
gon.relative_url_root = Gitlab.config.gitlab.relative_url_root
gon.default_avatar_url = URI::join(Gitlab.config.gitlab.url, ActionController::Base.helpers.image_path('no_avatar.png')).to_s
......
......@@ -9,7 +9,7 @@ class Projects::ServicesController < Projects::ApplicationController
def index
@project.build_missing_services
@services = @project.services.reload
@services = @project.services.visible.reload
end
def edit
......@@ -17,9 +17,6 @@ class Projects::ServicesController < Projects::ApplicationController
def update
if @service.update_attributes(service_params)
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
......
......@@ -16,32 +16,19 @@ module IssuesHelper
def url_for_project_issues(project = @project)
return '' if project.nil?
if project.default_issues_tracker?
project_issues_path(project)
else
project.external_issue_tracker.project_url
end
project.issues_tracker.project_url
end
def url_for_new_issue(project = @project)
return '' if project.nil?
if project.default_issues_tracker?
url = new_project_issue_path project_id: project
else
project.external_issue_tracker.new_issue_url
end
project.issues_tracker.new_issue_url
end
def url_for_issue(issue_iid, project = @project)
return '' if project.nil?
if project.default_issues_tracker?
url = project_issue_url project_id: project, id: issue_iid
else
url = project.external_issue_tracker.issues_url
url.gsub(':id', issue_iid.to_s)
end
project.issues_tracker.issue_url(issue_iid)
end
def title_for_issue(issue_iid, project = @project)
......
......@@ -77,6 +77,7 @@ class Project < ActiveRecord::Base
has_one :jira_service, dependent: :destroy
has_one :redmine_service, dependent: :destroy
has_one :custom_issue_tracker_service, dependent: :destroy
has_one :gitlab_issue_tracker_service, dependent: :destroy
has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id"
......@@ -149,8 +150,6 @@ class Project < ActiveRecord::Base
scope :public_and_internal_only, -> { where(visibility_level: Project.public_and_internal_levels) }
scope :non_archived, -> { where(archived: false) }
enumerize :issues_tracker, in: (Service.issue_tracker_service_list).append(:gitlab), default: :gitlab
state_machine :import_status, initial: :none do
event :import_start do
transition [:none, :finished] => :started
......@@ -317,19 +316,28 @@ class Project < ActiveRecord::Base
end
end
def default_issue_tracker
gitlab_issue_tracker_service ||= create_gitlab_issue_tracker_service
end
def issues_tracker
if external_issue_tracker
external_issue_tracker
else
default_issue_tracker
end
end
def default_issues_tracker?
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? }
services.select(&:issue_tracker?).reject(&:default?)
end
def external_issue_tracker
......
class GitlabIssueTrackerService < IssueTrackerService
include Rails.application.routes.url_helpers
prop_accessor :title, :description, :project_url, :issues_url, :new_issue_url
def default?
true
end
def to_param
'gitlab'
end
def project_url
project_issues_path(project)
end
def new_issue_url
new_project_issue_path project_id: project
end
def issue_url(iid)
"#{Gitlab.config.gitlab.url}#{project_issue_path(project_id: project, id: iid)}"
end
end
......@@ -6,6 +6,10 @@ class IssueTrackerService < Service
:issue_tracker
end
def default?
false
end
def project_url
# implement inside child
end
......@@ -18,6 +22,10 @@ class IssueTrackerService < Service
# implement inside child
end
def issue_url(iid)
self.issues_url.gsub(':id', iid.to_s)
end
def fields
[
{ type: 'text', name: 'description', placeholder: description },
......
......@@ -26,6 +26,8 @@ class Service < ActiveRecord::Base
validates :project_id, presence: true
scope :visible, -> { where.not(type: 'GitlabIssueTrackerService') }
def activated?
active
end
......
......@@ -23,6 +23,7 @@ describe GitlabMarkdownHelper do
@project = project
@ref = 'markdown'
@repository = project.repository
@request.host = Gitlab.config.gitlab.host
end
describe "#gfm" do
......
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