diff options
author | Jonathon Reinhart <Jonathon.Reinhart@gmail.com> | 2017-08-29 22:45:36 -0400 |
---|---|---|
committer | Jonathon Reinhart <Jonathon.Reinhart@gmail.com> | 2018-12-13 22:34:15 -0500 |
commit | 30a06eca35d38ac91c1f2beadb2443f37d28476b (patch) | |
tree | 1f0f5e4e1a9378948effa41be4e803e4b49811ba | |
parent | 857e86a6e666b20679d5cb43ce85fe9576fea678 (diff) | |
download | gitlab-shell-30a06eca35d38ac91c1f2beadb2443f37d28476b.tar.gz |
Pass push options to GitLab /internal/post_receive API
push_opts[] is named as such so that it becomes an array in the
GitLab internal Grape::API params hash. If it were named push_opts, only
the final (scalar) push_opts parameter would be present.
Also update specs to include push_opts parameter:
- gitlab_post_receive_spec
- gitlab_net_spec for the internal API change
-rwxr-xr-x | hooks/post-receive | 5 | ||||
-rw-r--r-- | lib/gitlab_net.rb | 5 | ||||
-rw-r--r-- | lib/gitlab_post_receive.rb | 5 | ||||
-rw-r--r-- | spec/gitlab_net_spec.rb | 5 | ||||
-rw-r--r-- | spec/gitlab_post_receive_spec.rb | 3 |
5 files changed, 15 insertions, 8 deletions
diff --git a/hooks/post-receive b/hooks/post-receive index 30f4be1..5098158 100755 --- a/hooks/post-receive +++ b/hooks/post-receive @@ -9,9 +9,12 @@ gl_repository = ENV['GL_REPOSITORY'] repo_path = Dir.pwd require_relative '../lib/gitlab_custom_hook' +require_relative '../lib/hooks_utils' require_relative '../lib/gitlab_post_receive' -if GitlabPostReceive.new(gl_repository, repo_path, key_id, refs).exec && +push_opts = HooksUtils.get_push_options + +if GitlabPostReceive.new(gl_repository, repo_path, key_id, refs, push_opts).exec && GitlabCustomHook.new(repo_path, key_id).post_receive(refs) exit 0 else diff --git a/lib/gitlab_net.rb b/lib/gitlab_net.rb index cae3bdb..a0e1f12 100644 --- a/lib/gitlab_net.rb +++ b/lib/gitlab_net.rb @@ -119,11 +119,12 @@ class GitlabNet # rubocop:disable Metrics/ClassLength false end - def post_receive(gl_repository, identifier, changes) + def post_receive(gl_repository, identifier, changes, push_opts) params = { gl_repository: gl_repository, identifier: identifier, - changes: changes + changes: changes, + :"push_opts[]" => push_opts, # ruby <2.2 syntax } resp = post("#{internal_api_endpoint}/post_receive", params) diff --git a/lib/gitlab_post_receive.rb b/lib/gitlab_post_receive.rb index ea57f6a..5dd9955 100644 --- a/lib/gitlab_post_receive.rb +++ b/lib/gitlab_post_receive.rb @@ -8,18 +8,19 @@ require 'securerandom' class GitlabPostReceive attr_reader :config, :gl_repository, :repo_path, :changes, :jid - def initialize(gl_repository, repo_path, actor, changes) + def initialize(gl_repository, repo_path, actor, changes, push_opts) @config = GitlabConfig.new @gl_repository = gl_repository @repo_path = repo_path.strip @actor = actor @changes = changes + @push_opts = push_opts @jid = SecureRandom.hex(12) end def exec response = GitlabMetrics.measure("post-receive") do - api.post_receive(gl_repository, @actor, changes) + api.post_receive(gl_repository, @actor, changes, @push_opts) end return false unless response diff --git a/spec/gitlab_net_spec.rb b/spec/gitlab_net_spec.rb index 07b772b..8409b14 100644 --- a/spec/gitlab_net_spec.rb +++ b/spec/gitlab_net_spec.rb @@ -174,8 +174,9 @@ describe GitlabNet, vcr: true do describe '#post_receive' do let(:gl_repository) { "project-1" } let(:changes) { "123456 789012 refs/heads/test\n654321 210987 refs/tags/tag" } + let(:push_opts) { ["ci-skip", "something unexpected"] } let(:params) do - { gl_repository: gl_repository, identifier: key, changes: changes } + { gl_repository: gl_repository, identifier: key, changes: changes, :"push_opts[]" => push_opts } end let(:merge_request_urls) do [{ @@ -185,7 +186,7 @@ describe GitlabNet, vcr: true do }] end - subject { gitlab_net.post_receive(gl_repository, key, changes) } + subject { gitlab_net.post_receive(gl_repository, key, changes, push_opts) } it 'sends the correct parameters' do expect_any_instance_of(Net::HTTP::Post).to receive(:set_form_data).with(hash_including(params)) diff --git a/spec/gitlab_post_receive_spec.rb b/spec/gitlab_post_receive_spec.rb index 7dd1828..ac1cea2 100644 --- a/spec/gitlab_post_receive_spec.rb +++ b/spec/gitlab_post_receive_spec.rb @@ -11,7 +11,8 @@ describe GitlabPostReceive do let(:base64_changes) { Base64.encode64(wrongly_encoded_changes) } let(:repo_path) { File.join(repository_path, repo_name) + ".git" } let(:gl_repository) { "project-1" } - let(:gitlab_post_receive) { GitlabPostReceive.new(gl_repository, repo_path, actor, wrongly_encoded_changes) } + let(:push_opts) { [] } + let(:gitlab_post_receive) { GitlabPostReceive.new(gl_repository, repo_path, actor, wrongly_encoded_changes, push_opts) } let(:broadcast_message) { "test " * 10 + "message " * 10 } let(:enqueued_at) { Time.new(2016, 6, 23, 6, 59) } let(:new_merge_request_urls) do |