diff options
Diffstat (limited to 'app/models/sent_notification.rb')
-rw-r--r-- | app/models/sent_notification.rb | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/app/models/sent_notification.rb b/app/models/sent_notification.rb index 6caab24143b..31a6ba2191f 100644 --- a/app/models/sent_notification.rb +++ b/app/models/sent_notification.rb @@ -11,7 +11,7 @@ class SentNotification < ActiveRecord::Base validates :reply_key, presence: true, uniqueness: true validates :noteable_id, presence: true, unless: :for_commit? validates :commit_id, presence: true, if: :for_commit? - validates :in_reply_to_discussion_id, format: { with: /\A\h{40}\z/, allow_nil: true } + validates :in_reply_to_discussion_id, format: {with: /\A\h{40}\z/, allow_nil: true} validate :note_valid after_save :keep_around_commit, if: :for_commit? @@ -63,12 +63,16 @@ class SentNotification < ActiveRecord::Base end def for_snippet? - noteable_type.end_with?('Snippet') + noteable_type.end_with?("Snippet") end def noteable if for_commit? - project.commit(commit_id) rescue nil + begin + project.commit(commit_id) + rescue + nil + end else super end @@ -76,7 +80,11 @@ class SentNotification < ActiveRecord::Base def position=(new_position) if new_position.is_a?(String) - new_position = JSON.parse(new_position) rescue nil + new_position = begin + JSON.parse(new_position) + rescue + nil + end end if new_position.is_a?(Hash) @@ -88,34 +96,34 @@ class SentNotification < ActiveRecord::Base end def to_param - self.reply_key + reply_key end def create_reply(message, dryrun: false) klass = dryrun ? Notes::BuildService : Notes::CreateService - klass.new(self.project, self.recipient, reply_params.merge(note: message)).execute + klass.new(project, recipient, reply_params.merge(note: message)).execute end private def reply_params { - noteable_type: self.noteable_type, - noteable_id: self.noteable_id, - commit_id: self.commit_id, - in_reply_to_discussion_id: self.in_reply_to_discussion_id + noteable_type: noteable_type, + noteable_id: noteable_id, + commit_id: commit_id, + in_reply_to_discussion_id: in_reply_to_discussion_id, } end def note_valid - note = create_reply('Test', dryrun: true) + note = create_reply("Test", dryrun: true) unless note.valid? - self.errors.add(:base, "Note parameters are invalid: #{note.errors.full_messages.to_sentence}") + errors.add(:base, "Note parameters are invalid: #{note.errors.full_messages.to_sentence}") end end def keep_around_commit - project.repository.keep_around(self.commit_id) + project.repository.keep_around(commit_id) end end |