gitlab-org--gitlab-foss/app/models/label.rb
Dmitriy Zaporozhets 0602c5d027
Change default label color
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2014-08-15 10:20:12 +03:00

28 lines
695 B
Ruby

class Label < ActiveRecord::Base
DEFAULT_COLOR = '#428bca'
belongs_to :project
has_many :label_links, dependent: :destroy
has_many :issues, through: :label_links, source: :target, source_type: 'Issue'
validates :color,
format: { with: /\A\#[0-9A-Fa-f]{6}+\Z/ },
allow_blank: false
validates :project, presence: true
# Don't allow '?', '&', and ',' for label titles
validates :title,
presence: true,
format: { with: /\A[^&\?,&]*\z/ },
uniqueness: { scope: :project_id }
scope :order_by_name, -> { reorder("labels.title ASC") }
def name
title
end
def open_issues_count
issues.opened.count
end
end