debian-mirror-gitlab/app/services/git/wiki_push_service/change.rb

68 lines
1.5 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
module Git
class WikiPushService
class Change
include Gitlab::Utils::StrongMemoize
# @param [ProjectWiki] wiki
# @param [Hash] change - must have keys `:oldrev` and `:newrev`
# @param [Gitlab::Git::RawDiffChange] raw_change
def initialize(project_wiki, change, raw_change)
@wiki, @raw_change, @change = project_wiki, raw_change, change
end
def page
strong_memoize(:page) { wiki.find_page(slug, revision) }
end
# See [Gitlab::Git::RawDiffChange#extract_operation] for the
# definition of the full range of operation values.
def event_action
case raw_change.operation
when :added
2020-06-23 00:09:42 +05:30
:created
2020-05-24 23:13:21 +05:30
when :deleted
2020-06-23 00:09:42 +05:30
:destroyed
2020-05-24 23:13:21 +05:30
else
2020-06-23 00:09:42 +05:30
:updated
2020-05-24 23:13:21 +05:30
end
end
def last_known_slug
strip_extension(raw_change.old_path || raw_change.new_path)
end
private
attr_reader :raw_change, :change, :wiki
def filename
return raw_change.old_path if deleted?
raw_change.new_path
end
def slug
strip_extension(filename)
end
def revision
return change[:oldrev] if deleted?
change[:newrev]
end
def deleted?
raw_change.operation == :deleted
end
def strip_extension(filename)
return unless filename
File.basename(filename, File.extname(filename))
end
end
end
end