<commit_before>require "tyne_core/extensions/issues/workflow"

module TyneCore
  # Represents an issue that affects a particular project.
  # Issues can be part of a sprint and they have an issue type.
  class Issue < ActiveRecord::Base
    include TyneCore::Extensions::Issues::Workflow
    include TyneCore::Extensions::Votable

    belongs_to :reported_by, :class_name => "TyneAuth::User"
    belongs_to :project, :class_name => "TyneCore::Project"
    belongs_to :issue_type, :class_name => "TyneCore::IssueType"
    belongs_to :issue_priority, :class_name => "TyneCore::IssuePriority"
    belongs_to :assigned_to, :class_name => "TyneAuth::User"
    has_many :comments, :class_name => "TyneCore::Comment"

    attr_accessible :project_id, :summary, :description, :issue_type_id, :issue_priority_id, :assigned_to_id

    validates :project_id, :summary, :issue_type_id, :number, :presence => true
    validates :number, :uniqueness => { :scope => :project_id }
    validate :security_assigned_to

    default_scope includes(:project).includes(:reported_by).includes(:issue_type).includes(:comments).includes(:issue_priority)

    after_initialize :set_defaults
    before_validation :set_number, :on => :create

    scope :sort_by_issue_type, lambda { |sord| joins(:issue_type).order("tyne_core_issue_types.name #{sord}") }
    scope :sort_by_issue_priority, lambda { |sord| joins(:issue_priority).order("tyne_core_issue_priorities.number #{sord}") }

    # Returns the issue number prefixed with the projecy key
    # to better identify issues.
    #
    # e.g. TYNE-1337
    #
    # @return [String] issue-key
    def key
      "#{project.key}-#{number}"
    end

    def closed?
      %w(done invalid).include? self.state
    end

    private
    def set_defaults
      self.issue_type_id ||= TyneCore::IssueType.first.id if attributes.include?("issue_type_id")
    end

    def set_number
      self.number = (project.issues.maximum('number') || 0) + 1
    end

    def security_assigned_to
      return true if self.assigned_to_id.blank?

      users = project.workers.uniq { |x| x.user_id }.map { |x| x.user_id }
      errors.add(:assigned_to_id, :value_not_allowed) unless users.include?(self.assigned_to_id)
    end
  end
end
<commit_msg>changes the custom sort scope to use includes instead of joins to not exclude issues without priority<commit_after>require "tyne_core/extensions/issues/workflow"

module TyneCore
  # Represents an issue that affects a particular project.
  # Issues can be part of a sprint and they have an issue type.
  class Issue < ActiveRecord::Base
    include TyneCore::Extensions::Issues::Workflow
    include TyneCore::Extensions::Votable

    belongs_to :reported_by, :class_name => "TyneAuth::User"
    belongs_to :project, :class_name => "TyneCore::Project"
    belongs_to :issue_type, :class_name => "TyneCore::IssueType"
    belongs_to :issue_priority, :class_name => "TyneCore::IssuePriority"
    belongs_to :assigned_to, :class_name => "TyneAuth::User"
    has_many :comments, :class_name => "TyneCore::Comment"

    attr_accessible :project_id, :summary, :description, :issue_type_id, :issue_priority_id, :assigned_to_id

    validates :project_id, :summary, :issue_type_id, :number, :presence => true
    validates :number, :uniqueness => { :scope => :project_id }
    validate :security_assigned_to

    default_scope includes(:project).includes(:reported_by).includes(:issue_type).includes(:comments).includes(:issue_priority)

    after_initialize :set_defaults
    before_validation :set_number, :on => :create

    scope :sort_by_issue_type, lambda { |sord| joins(:issue_type).order("tyne_core_issue_types.name #{sord}") }
    scope :sort_by_issue_priority, lambda { |sord| includes(:issue_priority).order("tyne_core_issue_priorities.number #{sord}") }

    # Returns the issue number prefixed with the projecy key
    # to better identify issues.
    #
    # e.g. TYNE-1337
    #
    # @return [String] issue-key
    def key
      "#{project.key}-#{number}"
    end

    def closed?
      %w(done invalid).include? self.state
    end

    private
    def set_defaults
      self.issue_type_id ||= TyneCore::IssueType.first.id if attributes.include?("issue_type_id")
    end

    def set_number
      self.number = (project.issues.maximum('number') || 0) + 1
    end

    def security_assigned_to
      return true if self.assigned_to_id.blank?

      users = project.workers.uniq { |x| x.user_id }.map { |x| x.user_id }
      errors.add(:assigned_to_id, :value_not_allowed) unless users.include?(self.assigned_to_id)
    end
  end
end

{'fraction_non_alphanumeric': 0.11370071879764757, 'fraction_numerical': 0.002613809627532128, 'mean_word_length': 4.224118316268487, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5259858', 'n_tokens_mistral': 1519, 'n_tokens_neox': 1484, 'n_words': 336}