Commit c921e686 authored by Francisco Javier López's avatar Francisco Javier López Committed by Douwe Maan

Moved committer and spec. Added some extra code to run hooks or not depending on the options

parent 1edd5c73
module Gitlab module Gitlab
module Wiki module Git
class CommitterWithHooks < Gollum::Committer class CommitterWithHooks < Gollum::Committer
attr_reader :gl_wiki attr_reader :gl_wiki
...@@ -9,6 +9,9 @@ module Gitlab ...@@ -9,6 +9,9 @@ module Gitlab
end end
def commit def commit
# TODO: Remove after 10.8
return super unless allowed_to_run_hooks?
result = Gitlab::Git::OperationService.new(git_user, gl_wiki.repository).with_branch( result = Gitlab::Git::OperationService.new(git_user, gl_wiki.repository).with_branch(
@wiki.ref, @wiki.ref,
start_branch_name: @wiki.ref start_branch_name: @wiki.ref
...@@ -24,6 +27,11 @@ module Gitlab ...@@ -24,6 +27,11 @@ module Gitlab
private private
# TODO: Remove after 10.8
def allowed_to_run_hooks?
@options[:user_id] != 0 && @options[:username].present?
end
def git_user def git_user
@git_user ||= Gitlab::Git::User.new(@options[:username], @git_user ||= Gitlab::Git::User.new(@options[:username],
@options[:name], @options[:name],
......
...@@ -290,7 +290,7 @@ module Gitlab ...@@ -290,7 +290,7 @@ module Gitlab
end end
def committer_with_hooks(commit_details) def committer_with_hooks(commit_details)
Gitlab::Wiki::CommitterWithHooks.new(self, commit_details.to_h) Gitlab::Git::CommitterWithHooks.new(self, commit_details.to_h)
end end
def with_committer_with_hooks(commit_details, &block) def with_committer_with_hooks(commit_details, &block)
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Wiki::CommitterWithHooks, seed_helper: true do describe Gitlab::Git::CommitterWithHooks, seed_helper: true do
shared_examples 'calling wiki hooks' do shared_examples 'calling wiki hooks' do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:user) { project.owner } let(:user) { project.owner }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment