blob: 3d1d0fe8c4e0c3b474fe3637cd0254a0c6c88bda (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# frozen_string_literal: true
module Git
class WikiPushService
class Change
include Gitlab::Utils::StrongMemoize
# @param [Wiki] wiki
# @param [Hash] change - must have keys `:oldrev` and `:newrev`
# @param [Gitlab::Git::RawDiffChange] raw_change
def initialize(wiki, change, raw_change)
@wiki, @raw_change, @change = 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
:created
when :deleted
:destroyed
else
:updated
end
end
def last_known_slug
strip_extension(raw_change.old_path || raw_change.new_path)
end
def sha
change[:newrev]
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
|