diff options
author | Francisco Javier López <fjlopez@gitlab.com> | 2018-04-18 17:50:56 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-04-18 17:50:56 +0000 |
commit | e8a27a67fadfa8e62d1c72979281bcd74c39c489 (patch) | |
tree | 0bb3612890dcce48600c9f88352daaf1cb8b73a2 /lib/gitlab/wiki | |
parent | 6a5de6dd3bc122be0473d80ba213de71be6b0fe8 (diff) | |
download | gitlab-ce-e8a27a67fadfa8e62d1c72979281bcd74c39c489.tar.gz |
Fix Custom hooks are not triggered by UI wiki edit
Diffstat (limited to 'lib/gitlab/wiki')
-rw-r--r-- | lib/gitlab/wiki/committer_with_hooks.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/gitlab/wiki/committer_with_hooks.rb b/lib/gitlab/wiki/committer_with_hooks.rb new file mode 100644 index 00000000000..19f0b3814fd --- /dev/null +++ b/lib/gitlab/wiki/committer_with_hooks.rb @@ -0,0 +1,39 @@ +module Gitlab + module Wiki + class CommitterWithHooks < Gollum::Committer + attr_reader :gl_wiki + + def initialize(gl_wiki, options = {}) + @gl_wiki = gl_wiki + super(gl_wiki.gollum_wiki, options) + end + + def commit + result = Gitlab::Git::OperationService.new(git_user, gl_wiki.repository).with_branch( + @wiki.ref, + start_branch_name: @wiki.ref + ) do |start_commit| + super(false) + end + + result[:newrev] + rescue Gitlab::Git::HooksService::PreReceiveError => e + message = "Custom Hook failed: #{e.message}" + raise Gitlab::Git::Wiki::OperationError, message + end + + private + + def git_user + @git_user ||= Gitlab::Git::User.new(@options[:username], + @options[:name], + @options[:email], + gitlab_id) + end + + def gitlab_id + Gitlab::GlId.gl_id_from_id_value(@options[:user_id]) + end + end + end +end |