diff options
author | Christian Couder <chriscool@tuxfamily.org> | 2019-08-15 06:43:33 +0300 |
---|---|---|
committer | Christian Couder <chriscool@tuxfamily.org> | 2019-09-04 13:11:24 +0300 |
commit | f00db0c342d01b33617f269447ff76140944a86e (patch) | |
tree | e1def576ec2f00ce18272d17ee913d2a60d09bed /lib/gitlab/push_options.rb | |
parent | 60adc14473911fd9bd33feef2fbfd62a9824a11c (diff) |
Support adding and removing labels w/ push opts
MergeRequests::PushOptionsHandlerService has been updated to allow
adding and removing labels to a merge request using git push options.
To create a new merge request and add 2 labels to it:
git push -u origin -o merge_request.create \
-o merge_request.label="My label 1" \
-o merge_request.label="My label 2"
To update an existing merge request and remove a label while
adding a different label:
git push -u origin -o merge_request.label="My added label" \
-o merge_request.unlabel="My removed label"
Issue https://gitlab.com/gitlab-org/gitlab-ce/issues/64320
Diffstat (limited to 'lib/gitlab/push_options.rb')
-rw-r--r-- | lib/gitlab/push_options.rb | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/gitlab/push_options.rb b/lib/gitlab/push_options.rb index 682edfc4259..a2296d265cd 100644 --- a/lib/gitlab/push_options.rb +++ b/lib/gitlab/push_options.rb @@ -7,10 +7,12 @@ module Gitlab keys: [ :create, :description, + :label, :merge_when_pipeline_succeeds, :remove_source_branch, :target, - :title + :title, + :unlabel ] }, ci: { @@ -18,6 +20,11 @@ module Gitlab } }).freeze + MULTI_VALUE_OPTIONS = [ + %w[merge_request label], + %w[merge_request unlabel] + ].freeze + NAMESPACE_ALIASES = HashWithIndifferentAccess.new({ mr: :merge_request }).freeze @@ -50,12 +57,22 @@ module Gitlab next if [namespace, key].any?(&:nil?) options[namespace] ||= HashWithIndifferentAccess.new - options[namespace][key] = value + + if option_multi_value?(namespace, key) + options[namespace][key] ||= HashWithIndifferentAccess.new(0) + options[namespace][key][value] += 1 + else + options[namespace][key] = value + end end options end + def option_multi_value?(namespace, key) + MULTI_VALUE_OPTIONS.any? { |arr| arr == [namespace, key] } + end + def parse_option(option) parts = OPTION_MATCHER.match(option) return unless parts |