2020-05-11 23:09:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Git
|
|
|
|
class WikiPushService
|
|
|
|
class Change
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2020-09-09 17:08:33 -04:00
|
|
|
# @param [Wiki] wiki
|
2020-05-11 23:09:31 -04:00
|
|
|
# @param [Hash] change - must have keys `:oldrev` and `:newrev`
|
|
|
|
# @param [Gitlab::Git::RawDiffChange] raw_change
|
2020-09-09 17:08:33 -04:00
|
|
|
def initialize(wiki, change, raw_change)
|
2021-04-19 17:09:27 -04:00
|
|
|
@wiki = wiki
|
|
|
|
@raw_change = raw_change
|
|
|
|
@change = change
|
2020-05-11 23:09:31 -04:00
|
|
|
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-05-28 11:08:02 -04:00
|
|
|
:created
|
2020-05-11 23:09:31 -04:00
|
|
|
when :deleted
|
2020-05-28 11:08:02 -04:00
|
|
|
:destroyed
|
2020-05-11 23:09:31 -04:00
|
|
|
else
|
2020-05-28 11:08:02 -04:00
|
|
|
:updated
|
2020-05-11 23:09:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def last_known_slug
|
|
|
|
strip_extension(raw_change.old_path || raw_change.new_path)
|
|
|
|
end
|
|
|
|
|
2020-07-20 08:09:34 -04:00
|
|
|
def sha
|
|
|
|
change[:newrev]
|
|
|
|
end
|
|
|
|
|
2020-05-11 23:09:31 -04:00
|
|
|
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
|
|
|
|
|
2021-06-30 11:08:27 -04:00
|
|
|
encoded_filename = Gitlab::EncodingHelper.encode_utf8(filename.dup)
|
|
|
|
File.basename(encoded_filename, File.extname(encoded_filename))
|
2020-05-11 23:09:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|