Class: Milestone

Inherits:
ApplicationRecord show all
Includes:
FromUnion, Importable, Milestoneish, Sortable, Timebox
Defined in:
app/models/milestone.rb

Constant Summary

Constants included from Milestoneish

Milestoneish::DISPLAY_ISSUES_LIMIT

Constants included from Timebox

Timebox::Any, Timebox::None, Timebox::Started, Timebox::Upcoming

Constants included from Gitlab::SQL::Pattern

Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING, Gitlab::SQL::Pattern::REGEX_QUOTED_WORD

Constants included from CacheMarkdownField

CacheMarkdownField::INVALIDATED_BY

Instance Attribute Summary

Attributes included from Importable

#imported, #importing

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Milestoneish

#closed_issues_count, #complete?, #elapsed_days, #expired?, #expires_at, #human_total_time_estimate, #human_total_time_spent, #issue_labels_visible_by_user, #issue_participants_visible_by_user, #issues_visible_to_user, #merge_requests_visible_to_user, #opened_issues_count, #percent_complete, #remaining_days, #sorted_issues, #sorted_merge_requests, #total_issues_count, #total_time_estimate, #total_time_spent, #upcoming?

Methods included from Timebox

#group_timebox?, #merge_requests_enabled?, #project_timebox?, #reference_link_text, #resource_parent, #safe_title, #timebox_name, #title=, #to_ability_name, #to_reference, #weight_available?

Methods included from StripAttribute

#strip_attributes

Methods included from Referable

#referable_inspect, #reference_link_text, #to_reference, #to_reference_base

Methods included from IidRoutes

#to_param

Methods included from CacheMarkdownField

#attribute_invalidated?, #banzai_render_context, #cached_html_for, #cached_html_up_to_date?, #can_cache_field?, #invalidated_markdown_cache?, #latest_cached_markdown_version, #local_version, #parent_user, #refresh_markdown_cache, #refresh_markdown_cache!, #rendered_field_content, #skip_project_check?, #updated_cached_html_for

Methods included from AtomicInternalId

#internal_id_read_scope, #internal_id_scope_attrs, #internal_id_scope_usage

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Class Method Details


72
73
74
# File 'app/models/milestone.rb', line 72

def self.link_reference_pattern
  @link_reference_pattern ||= super("milestones", /(?<milestone>\d+)/)
end

.reference_patternObject


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/models/milestone.rb', line 53

def self.reference_pattern
  # NOTE: The iid pattern only matches when all characters on the expression
  # are digits, so it will match %2 but not %2.1 because that's probably a
  # milestone name and we want it to be matched as such.
  @reference_pattern ||= %r{
    (#{Project.reference_pattern})?
    #{Regexp.escape(reference_prefix)}
    (?:
      (?<milestone_iid>
        \d+(?!\S\w)\b # Integer-based milestone iid, or
      ) |
      (?<milestone_name>
        [^"\s]+\b |  # String-based single-word milestone title, or
        "[^"]+"      # String-based multi-word milestone surrounded in quotes
      )
    )
  }x
end

.reference_prefixObject


49
50
51
# File 'app/models/milestone.rb', line 49

def self.reference_prefix
  '%'
end

.sort_by_attribute(method) ⇒ Object


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/models/milestone.rb', line 87

def self.sort_by_attribute(method)
  sorted =
    case method.to_s
    when 'due_date_asc'
      reorder_by_due_date_asc
    when 'due_date_desc'
      reorder(Gitlab::Database.nulls_last_order('due_date', 'DESC'))
    when 'name_asc'
      reorder(Arel::Nodes::Ascending.new(arel_table[:title].lower))
    when 'name_desc'
      reorder(Arel::Nodes::Descending.new(arel_table[:title].lower))
    when 'start_date_asc'
      reorder(Gitlab::Database.nulls_last_order('start_date', 'ASC'))
    when 'start_date_desc'
      reorder(Gitlab::Database.nulls_last_order('start_date', 'DESC'))
    else
      order_by(method)
    end

  sorted.with_order_id_desc
end

.states_count(projects, groups = nil) ⇒ Object


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/milestone.rb', line 109

def self.states_count(projects, groups = nil)
  return STATE_COUNT_HASH unless projects || groups

  counts = Milestone
             .for_projects_and_groups(projects, groups)
             .reorder(nil)
             .group(:state)
             .count

  {
      opened: counts['active'] || 0,
      closed: counts['closed'] || 0,
      all: counts.values.sum
  }
end

.upcoming_ids(projects, groups) ⇒ Object


76
77
78
79
80
81
# File 'app/models/milestone.rb', line 76

def self.upcoming_ids(projects, groups)
  unscoped
    .for_projects_and_groups(projects, groups)
    .active.where('milestones.due_date > CURRENT_DATE')
    .order(:project_id, :group_id, :due_date).select('DISTINCT ON (project_id, group_id) id')
end

Instance Method Details

#author_idObject


133
134
135
# File 'app/models/milestone.rb', line 133

def author_id
  nil
end

#can_be_closed?Boolean

Returns:

  • (Boolean)

129
130
131
# File 'app/models/milestone.rb', line 129

def can_be_closed?
  active? && issues.opened.count == 0
end

#for_displayObject


125
126
127
# File 'app/models/milestone.rb', line 125

def for_display
  self
end

#parentObject


145
146
147
148
149
150
151
# File 'app/models/milestone.rb', line 145

def parent
  if group_milestone?
    group
  else
    project
  end
end

#participantsObject


83
84
85
# File 'app/models/milestone.rb', line 83

def participants
  User.joins(assigned_issues: :milestone).where("milestones.id = ?", id).distinct
end

#subgroup_milestone?Boolean

Returns:

  • (Boolean)

153
154
155
# File 'app/models/milestone.rb', line 153

def subgroup_milestone?
  group_milestone? && parent.subgroup?
end