Module: Issuable

Extended by:
ActiveSupport::Concern
Includes:
Mentionable, Participable, StripAttribute, Subscribable
Included in:
Issue, MergeRequest
Defined in:
app/models/concerns/issuable.rb

Overview

Issuable concern

Contains common functionality shared between Issues and MergeRequests

Used by Issue, MergeRequest

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Methods included from StripAttribute

#strip_attributes

Methods included from Subscribable

#subscribed?, #subscribers, #toggle_subscription, #unsubscribe

Methods included from Mentionable

#all_references, #create_cross_references!, #create_new_cross_references!, #gfm_reference, #local_reference, #mentioned_users, #referenced_mentionables

Methods included from Participable

#participants

Instance Method Details

#add_labels_by_names(label_names) ⇒ Object


189
190
191
192
193
194
195
# File 'app/models/concerns/issuable.rb', line 189

def add_labels_by_names(label_names)
  label_names.each do |label_name|
    label = project.labels.create_with(color: Label::DEFAULT_COLOR).
      find_or_create_by(title: label_name.strip)
    self.labels << label
  end
end

#can_move?Boolean

Method that checks if issuable can be moved to another project.

Should be overridden if issuable can be moved.

Returns:

  • (Boolean)

229
230
231
# File 'app/models/concerns/issuable.rb', line 229

def can_move?(*)
  false
end

#card_attributesObject

Returns a Hash of attributes to be used for Twitter card metadata


208
209
210
211
212
213
# File 'app/models/concerns/issuable.rb', line 208

def card_attributes
  {
    'Author'   => author.try(:name),
    'Assignee' => assignee.try(:name)
  }
end

#downvotesObject


155
156
157
# File 'app/models/concerns/issuable.rb', line 155

def downvotes
  notes.awards.where(note: "thumbsdown").count
end

#is_assigned?Boolean

Returns:

  • (Boolean)

143
144
145
# File 'app/models/concerns/issuable.rb', line 143

def is_assigned?
  !!assignee_id
end

#is_being_reassigned?Boolean

Returns:

  • (Boolean)

147
148
149
# File 'app/models/concerns/issuable.rb', line 147

def is_being_reassigned?
  assignee_id_changed?
end

#label_namesObject


181
182
183
# File 'app/models/concerns/issuable.rb', line 181

def label_names
  labels.order('title ASC').pluck(:title)
end

#new?Boolean

Returns:

  • (Boolean)

139
140
141
# File 'app/models/concerns/issuable.rb', line 139

def new?
  today? && created_at == updated_at
end

#notes_with_associationsObject


215
216
217
# File 'app/models/concerns/issuable.rb', line 215

def notes_with_associations
  notes.includes(:author, :project)
end

#open?Boolean

Returns:

  • (Boolean)

151
152
153
# File 'app/models/concerns/issuable.rb', line 151

def open?
  opened? || reopened?
end

#remove_labelsObject


185
186
187
# File 'app/models/concerns/issuable.rb', line 185

def remove_labels
  labels.delete_all
end

#subscribed_without_subscriptions?(user) ⇒ Boolean

Returns:

  • (Boolean)

163
164
165
# File 'app/models/concerns/issuable.rb', line 163

def subscribed_without_subscriptions?(user)
  participants(user).include?(user)
end

#to_ability_nameObject

Convert this Issuable class name to a format usable by Ability definitions

Examples:

issuable.class           # => MergeRequest
issuable.to_ability_name # => "merge_request"

203
204
205
# File 'app/models/concerns/issuable.rb', line 203

def to_ability_name
  self.class.to_s.underscore
end

#to_hook_data(user) ⇒ Object


167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'app/models/concerns/issuable.rb', line 167

def to_hook_data(user)
  hook_data = {
    object_kind: self.class.name.underscore,
    user: user.hook_attrs,
    project: project.hook_attrs,
    object_attributes: hook_attrs,
    # DEPRECATED
    repository: project.hook_attrs.slice(:name, :url, :description, :homepage)
  }
  hook_data.merge!(assignee: assignee.hook_attrs) if assignee

  hook_data
end

#today?Boolean

Returns:

  • (Boolean)

135
136
137
# File 'app/models/concerns/issuable.rb', line 135

def today?
  Date.today == created_at.to_date
end

#updated_tasksObject


219
220
221
222
# File 'app/models/concerns/issuable.rb', line 219

def updated_tasks
  Taskable.get_updated_tasks(old_content: previous_changes['description'].first,
                             new_content: description)
end

#upvotesObject


159
160
161
# File 'app/models/concerns/issuable.rb', line 159

def upvotes
  notes.awards.where(note: "thumbsup").count
end