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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

75 lines
1.6 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
2020-11-24 15:15:51 +05:30
# @param [Wiki] wiki
2020-05-24 23:13:21 +05:30
# @param [Hash] change - must have keys `:oldrev` and `:newrev`
# @param [Gitlab::Git::RawDiffChange] raw_change
2020-11-24 15:15:51 +05:30
def initialize(wiki, change, raw_change)
2021-04-29 21:17:54 +05:30
@wiki = wiki
@raw_change = raw_change
@change = change
2020-05-24 23:13:21 +05:30
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
2020-10-24 23:57:45 +05:30
def sha
change[:newrev]
end
2020-05-24 23:13:21 +05:30
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-09-30 23:02:18 +05:30
encoded_filename = Gitlab::EncodingHelper.encode_utf8(filename.dup)
File.basename(encoded_filename, File.extname(encoded_filename))
2020-05-24 23:13:21 +05:30
end
end
end
end