Commit d45a6b29 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Migrate issue/mr labels from act_as_taggable to own labels

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 6fb9badc
...@@ -125,7 +125,7 @@ class BaseFinder ...@@ -125,7 +125,7 @@ class BaseFinder
def by_label(items) def by_label(items)
if params[:label_name].present? if params[:label_name].present?
items = items.tagged_with(params[:label_name]) items = items.joins(:labels).where("labels.title = ?", params[:label_name])
end end
items items
......
module LabelsHelper module LabelsHelper
def issue_label_names def issue_label_names
@project.issues_labels.map(&:name) @project.labels.pluck(:title)
end end
def labels_autocomplete_source def labels_autocomplete_source
labels = @project.issues_labels labels = @project.labels
labels = labels.map{ |l| { label: l.name, value: l.name } } labels = labels.map { |l| { label: l.name, value: l.name } }
labels.to_json labels.to_json
end end
......
...@@ -13,6 +13,8 @@ module Issuable ...@@ -13,6 +13,8 @@ module Issuable
belongs_to :assignee, class_name: "User" belongs_to :assignee, class_name: "User"
belongs_to :milestone belongs_to :milestone
has_many :notes, as: :noteable, dependent: :destroy has_many :notes, as: :noteable, dependent: :destroy
has_many :label_links, as: :target, dependent: :destroy
has_many :labels, through: :label_links
validates :author, presence: true validates :author, presence: true
validates :title, presence: true, length: { within: 0..255 } validates :title, presence: true, length: { within: 0..255 }
......
...@@ -32,9 +32,6 @@ class Issue < ActiveRecord::Base ...@@ -32,9 +32,6 @@ class Issue < ActiveRecord::Base
scope :of_group, ->(group) { where(project_id: group.project_ids) } scope :of_group, ->(group) { where(project_id: group.project_ids) }
scope :of_user_team, ->(team) { where(project_id: team.project_ids, assignee_id: team.member_ids) } scope :of_user_team, ->(team) { where(project_id: team.project_ids, assignee_id: team.member_ids) }
acts_as_taggable_on :labels
scope :cared, ->(user) { where(assignee_id: user) } scope :cared, ->(user) { where(assignee_id: user) }
scope :open_for, ->(user) { opened.assigned_to(user) } scope :open_for, ->(user) { opened.assigned_to(user) }
......
...@@ -4,4 +4,9 @@ class Label < ActiveRecord::Base ...@@ -4,4 +4,9 @@ class Label < ActiveRecord::Base
validates :color, format: { with: /\A\#[0-9A-Fa-f]{3}{1,2}+\Z/ }, allow_blank: true validates :color, format: { with: /\A\#[0-9A-Fa-f]{3}{1,2}+\Z/ }, allow_blank: true
validates :project, presence: true validates :project, presence: true
validates :title, presence: true
def name
title
end
end end
...@@ -47,9 +47,6 @@ class MergeRequest < ActiveRecord::Base ...@@ -47,9 +47,6 @@ class MergeRequest < ActiveRecord::Base
attr_accessor :can_be_created, :compare_failed, attr_accessor :can_be_created, :compare_failed,
:compare_commits, :compare_diffs :compare_commits, :compare_diffs
ActsAsTaggableOn.strict_case_match = true
acts_as_taggable_on :labels
state_machine :state, initial: :opened do state_machine :state, initial: :opened do
event :close do event :close do
transition [:reopened, :opened] => :closed transition [:reopened, :opened] => :closed
......
...@@ -41,8 +41,7 @@ class Project < ActiveRecord::Base ...@@ -41,8 +41,7 @@ class Project < ActiveRecord::Base
default_value_for :snippets_enabled, gitlab_config_features.snippets default_value_for :snippets_enabled, gitlab_config_features.snippets
ActsAsTaggableOn.strict_case_match = true ActsAsTaggableOn.strict_case_match = true
acts_as_taggable_on :tags
acts_as_taggable_on :tags, :issues_default_labels
attr_accessor :new_default_branch attr_accessor :new_default_branch
...@@ -71,6 +70,7 @@ class Project < ActiveRecord::Base ...@@ -71,6 +70,7 @@ class Project < ActiveRecord::Base
# Merge requests from source project should be kept when source project was removed # Merge requests from source project should be kept when source project was removed
has_many :fork_merge_requests, foreign_key: "source_project_id", class_name: MergeRequest has_many :fork_merge_requests, foreign_key: "source_project_id", class_name: MergeRequest
has_many :issues, -> { order "state DESC, created_at DESC" }, dependent: :destroy has_many :issues, -> { order "state DESC, created_at DESC" }, dependent: :destroy
has_many :labels, dependent: :destroy
has_many :services, dependent: :destroy has_many :services, dependent: :destroy
has_many :events, dependent: :destroy has_many :events, dependent: :destroy
has_many :milestones, dependent: :destroy has_many :milestones, dependent: :destroy
...@@ -282,13 +282,6 @@ class Project < ActiveRecord::Base ...@@ -282,13 +282,6 @@ class Project < ActiveRecord::Base
self.id self.id
end end
# Tags are shared by issues and merge requests
def issues_labels
@issues_labels ||= (issues_default_labels +
merge_requests.tags_on(:labels) +
issues.tags_on(:labels)).uniq.sort_by(&:name)
end
def issue_exists?(issue_id) def issue_exists?(issue_id)
if used_default_issues_tracker? if used_default_issues_tracker?
self.issues.where(iid: issue_id).first.present? self.issues.where(iid: issue_id).first.present?
......
class MigrateTaggableLabels < ActiveRecord::Migration
def up
taggings = ActsAsTaggableOn::Tagging.where(taggable_type: ['Issue', 'MergeRequest'], context: 'labels')
taggings.find_each(batch_size: 500) do |tagging|
create_label_from_tagging(tagging)
end
end
def down
Label.destroy_all
LabelLink.destroy_all
end
private
def create_label_from_tagging(tagging)
target = tagging.taggable
label_name = tagging.tag.name
label = target.project.labels.find_or_create_by(title: label_name)
if LabelLink.create(label: label, target: target)
print '.'
else
print 'F'
end
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: 20140729145339) do ActiveRecord::Schema.define(version: 20140729152420) 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"
......
...@@ -18,10 +18,11 @@ module Gitlab ...@@ -18,10 +18,11 @@ module Gitlab
end end
def generate(project) def generate(project)
labels = important_labels + warning_labels + neutral_labels + positive_labels label_names = important_labels + warning_labels + neutral_labels + positive_labels
project.issues_default_label_list = labels label_names.each do |label_name|
project.save project.labels.create(title: label_name)
end
end end
end end
end end
......
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