diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-08-24 14:32:17 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-08-24 14:32:17 +0000 |
commit | e46a3d2fda47f96885b38c6c6caf7dc3e0df19bd (patch) | |
tree | 05d362e372d1d84371977fcb8868beffa5fc612f /app/services | |
parent | 88892e43adecd68de7940fdc9856a4557098cb6c (diff) | |
parent | a1a914994f6376b03d95e9d4b05dea422e8610f9 (diff) | |
download | gitlab-ce-e46a3d2fda47f96885b38c6c6caf7dc3e0df19bd.tar.gz |
Merge branch 'git-operation-user' into 'master'
Move GitHooksService into Gitlab::Git
See merge request !13739
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/commits/create_service.rb | 2 | ||||
-rw-r--r-- | app/services/create_branch_service.rb | 2 | ||||
-rw-r--r-- | app/services/delete_branch_service.rb | 2 | ||||
-rw-r--r-- | app/services/git_hooks_service.rb | 32 | ||||
-rw-r--r-- | app/services/git_operation_service.rb | 14 | ||||
-rw-r--r-- | app/services/merge_requests/merge_service.rb | 2 | ||||
-rw-r--r-- | app/services/tags/create_service.rb | 2 | ||||
-rw-r--r-- | app/services/tags/destroy_service.rb | 2 | ||||
-rw-r--r-- | app/services/validate_new_branch_service.rb | 2 |
9 files changed, 15 insertions, 45 deletions
diff --git a/app/services/commits/create_service.rb b/app/services/commits/create_service.rb index c58f04a252b..dbd0b9ef43a 100644 --- a/app/services/commits/create_service.rb +++ b/app/services/commits/create_service.rb @@ -17,7 +17,7 @@ module Commits new_commit = create_commit! success(result: new_commit) - rescue ValidationError, ChangeError, Gitlab::Git::Index::IndexError, Repository::CommitError, GitHooksService::PreReceiveError => ex + rescue ValidationError, ChangeError, Gitlab::Git::Index::IndexError, Repository::CommitError, Gitlab::Git::HooksService::PreReceiveError => ex error(ex.message) end diff --git a/app/services/create_branch_service.rb b/app/services/create_branch_service.rb index 673ed02f952..0ba6a0ac6b5 100644 --- a/app/services/create_branch_service.rb +++ b/app/services/create_branch_service.rb @@ -14,7 +14,7 @@ class CreateBranchService < BaseService else error('Invalid reference name') end - rescue GitHooksService::PreReceiveError => ex + rescue Gitlab::Git::HooksService::PreReceiveError => ex error(ex.message) end diff --git a/app/services/delete_branch_service.rb b/app/services/delete_branch_service.rb index 64b3c0118fb..1f059c31944 100644 --- a/app/services/delete_branch_service.rb +++ b/app/services/delete_branch_service.rb @@ -16,7 +16,7 @@ class DeleteBranchService < BaseService else error('Failed to remove branch') end - rescue GitHooksService::PreReceiveError => ex + rescue Gitlab::Git::HooksService::PreReceiveError => ex error(ex.message) end diff --git a/app/services/git_hooks_service.rb b/app/services/git_hooks_service.rb deleted file mode 100644 index eab65d09299..00000000000 --- a/app/services/git_hooks_service.rb +++ /dev/null @@ -1,32 +0,0 @@ -class GitHooksService - PreReceiveError = Class.new(StandardError) - - attr_accessor :oldrev, :newrev, :ref - - def execute(user, project, oldrev, newrev, ref) - @project = project - @user = Gitlab::GlId.gl_id(user) - @oldrev = oldrev - @newrev = newrev - @ref = ref - - %w(pre-receive update).each do |hook_name| - status, message = run_hook(hook_name) - - unless status - raise PreReceiveError, message - end - end - - yield(self).tap do - run_hook('post-receive') - end - end - - private - - def run_hook(name) - hook = Gitlab::Git::Hook.new(name, @project) - hook.trigger(@user, oldrev, newrev, ref) - end -end diff --git a/app/services/git_operation_service.rb b/app/services/git_operation_service.rb index 545ca0742e4..6b7a56e6922 100644 --- a/app/services/git_operation_service.rb +++ b/app/services/git_operation_service.rb @@ -1,8 +1,10 @@ class GitOperationService - attr_reader :user, :repository + attr_reader :committer, :repository + + def initialize(committer, new_repository) + committer = Gitlab::Git::Committer.from_user(committer) if committer.is_a?(User) + @committer = committer - def initialize(new_user, new_repository) - @user = new_user @repository = new_repository end @@ -118,9 +120,9 @@ class GitOperationService end def with_hooks(ref, newrev, oldrev) - GitHooksService.new.execute( - user, - repository.project, + Gitlab::Git::HooksService.new.execute( + committer, + repository, oldrev, newrev, ref) do |service| diff --git a/app/services/merge_requests/merge_service.rb b/app/services/merge_requests/merge_service.rb index bc846e07f24..5be749cd6a0 100644 --- a/app/services/merge_requests/merge_service.rb +++ b/app/services/merge_requests/merge_service.rb @@ -49,7 +49,7 @@ module MergeRequests raise MergeError, 'Conflicts detected during merge' unless commit_id merge_request.update(merge_commit_sha: commit_id) - rescue GitHooksService::PreReceiveError => e + rescue Gitlab::Git::HooksService::PreReceiveError => e raise MergeError, e.message rescue StandardError => e raise MergeError, "Something went wrong during merge: #{e.message}" diff --git a/app/services/tags/create_service.rb b/app/services/tags/create_service.rb index 674792f6138..b3f4a72d6fe 100644 --- a/app/services/tags/create_service.rb +++ b/app/services/tags/create_service.rb @@ -13,7 +13,7 @@ module Tags new_tag = repository.add_tag(current_user, tag_name, target, message) rescue Rugged::TagError return error("Tag #{tag_name} already exists") - rescue GitHooksService::PreReceiveError => ex + rescue Gitlab::Git::HooksService::PreReceiveError => ex return error(ex.message) end diff --git a/app/services/tags/destroy_service.rb b/app/services/tags/destroy_service.rb index a368f4f5b61..d3d46064729 100644 --- a/app/services/tags/destroy_service.rb +++ b/app/services/tags/destroy_service.rb @@ -21,7 +21,7 @@ module Tags else error('Failed to remove tag') end - rescue GitHooksService::PreReceiveError => ex + rescue Gitlab::Git::HooksService::PreReceiveError => ex error(ex.message) end diff --git a/app/services/validate_new_branch_service.rb b/app/services/validate_new_branch_service.rb index d232e85cd33..7d1ed768ee8 100644 --- a/app/services/validate_new_branch_service.rb +++ b/app/services/validate_new_branch_service.rb @@ -13,7 +13,7 @@ class ValidateNewBranchService < BaseService end success - rescue GitHooksService::PreReceiveError => ex + rescue Gitlab::Git::HooksService::PreReceiveError => ex error(ex.message) end end |