diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-09-02 09:17:43 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-09-02 09:17:43 +0000 |
commit | 76f7f349669524809db2daa34d07d4af9b9e9544 (patch) | |
tree | e5e020d921f454b1f61b903e76e31d37a5ffaeb4 /lib/gitlab_post_receive.rb | |
parent | 99fa0c6e878ed7e5e6292a87524bd43edfafbc9f (diff) | |
parent | a71c80721de28e59147dc6b8c8326c98570a1cb8 (diff) | |
download | gitlab-shell-76f7f349669524809db2daa34d07d4af9b9e9544.tar.gz |
Merge branch 'hooks-refactoring' into 'master'
Hooks refactoring
* replace update hook with pre-receive & post-receive hooks
* use pre-receive hook for authorisation
* use post-receive hook to create background job for GitLab worker
Related to https://dev.gitlab.org/gitlab/gitlabhq/issues/1516
See merge request !38
Diffstat (limited to 'lib/gitlab_post_receive.rb')
-rw-r--r-- | lib/gitlab_post_receive.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/gitlab_post_receive.rb b/lib/gitlab_post_receive.rb new file mode 100644 index 0000000..3f9f384 --- /dev/null +++ b/lib/gitlab_post_receive.rb @@ -0,0 +1,31 @@ +require_relative 'gitlab_init' +require 'json' + +class GitlabPostReceive + attr_reader :config, :repo_path, :changes + + def initialize(repo_path, actor, changes) + @config = GitlabConfig.new + @repo_path, @actor = repo_path.strip, actor + @changes = changes.lines + end + + def exec + # reset GL_ID env since we already + # get value from it + ENV['GL_ID'] = nil + + update_redis + end + + protected + + def update_redis + queue = "#{config.redis_namespace}:queue:post_receive" + msg = JSON.dump({'class' => 'PostReceive', 'args' => [@repo_path, @actor, @changes]}) + unless system(*config.redis_command, 'rpush', queue, msg, err: '/dev/null', out: '/dev/null') + puts "GitLab: An unexpected error occurred (redis-cli returned #{$?.exitstatus})." + exit 1 + end + end +end |