diff --git a/models/root_action_descriptor.rb b/models/root_action_descriptor.rb index 0adb4ac..2418fae 100644 --- a/models/root_action_descriptor.rb +++ b/models/root_action_descriptor.rb @@ -8,6 +8,7 @@ class GitlabWebHookRootActionDescriptor < Jenkins::Model::DefaultDescriptor MERGE_REQUEST_PROCESSING = 'merge_request_processing' MERGED_BRANCH_PROCESSING = 'merged_branch_triggering' + USE_HTTP_URLS = 'use_http_urls' AUTOMATIC_PROJECT_CREATION_PROPERTY = 'automatic_project_creation' MASTER_BRANCH_PROPERTY = 'master_branch' USE_MASTER_PROJECT_NAME_PROPERTY = 'use_master_project_name' @@ -32,6 +33,10 @@ def merged_branch_triggering? !!@merged_branch_triggering end + def use_http_urls? + !!@use_http_urls + end + def automatic_project_creation? !!@automatic_project_creation end @@ -56,6 +61,7 @@ def load @ignore_usernames = read_property(doc, IGNORE_USERS, DEFAULT_IGNORE_USERS) @merge_request_processing = read_property(doc, MERGE_REQUEST_PROCESSING, "true") == "true" @merged_branch_triggering = read_property(doc, MERGED_BRANCH_PROCESSING, "false") == "true" + @use_http_urls = read_property(doc, USE_HTTP_URLS, "false") == "true" @automatic_project_creation = read_property(doc, AUTOMATIC_PROJECT_CREATION_PROPERTY) == "true" @use_master_project_name = read_property(doc, USE_MASTER_PROJECT_NAME_PROPERTY) == "true" @master_branch = read_property(doc, MASTER_BRANCH_PROPERTY) @@ -79,6 +85,7 @@ def save write_property(doc, MERGE_REQUEST_PROCESSING, merge_request_processing?) write_property(doc, MERGED_BRANCH_PROCESSING, merged_branch_triggering?) + write_property(doc, USE_HTTP_URLS, use_http_urls?) write_property(doc, AUTOMATIC_PROJECT_CREATION_PROPERTY, automatic_project_creation?) write_property(doc, MASTER_BRANCH_PROPERTY, master_branch) write_property(doc, USE_MASTER_PROJECT_NAME_PROPERTY, use_master_project_name?) @@ -136,6 +143,7 @@ def parse(form) @ignore_usernames = form[IGNORE_USERS] @merge_request_processing = form[MERGE_REQUEST_PROCESSING] ? true : false @merged_branch_triggering = form[MERGED_BRANCH_PROCESSING] ? true : false + @use_http_urls = form[USE_HTTP_URLS] ? true : false @automatic_project_creation = form[AUTOMATIC_PROJECT_CREATION_PROPERTY] ? true : false if automatic_project_creation? @master_branch = form[AUTOMATIC_PROJECT_CREATION_PROPERTY][MASTER_BRANCH_PROPERTY] diff --git a/models/values/merge_request_details.rb b/models/values/merge_request_details.rb index 4b9b443..2d38f57 100644 --- a/models/values/merge_request_details.rb +++ b/models/values/merge_request_details.rb @@ -1,10 +1,12 @@ require_relative 'abstract_details' require_relative '../exceptions/bad_request_exception' +require_relative '../util/settings' require 'gitlab' module GitlabWebHook class MergeRequestDetails < AbstractDetails + include Settings def initialize(payload) raise(ArgumentError.new("request payload is required")) unless payload @@ -52,7 +54,7 @@ def merge_status end def repository_url - payload["source"] ? payload["source"]["ssh_url"] : extended["ssh_url_to_repo"] + payload["source"] ? payload["source"][settings.use_http_urls ? "git_http_url" : "ssh_url"] : extended["ssh_url_to_repo"] end def repository_name diff --git a/models/values/payload_request_details.rb b/models/values/payload_request_details.rb index 7011dfa..4a9d233 100644 --- a/models/values/payload_request_details.rb +++ b/models/values/payload_request_details.rb @@ -1,7 +1,10 @@ require_relative 'request_details' +require_relative '../util/settings' module GitlabWebHook class PayloadRequestDetails < RequestDetails + include Settings + def initialize(payload) @payload = payload || raise(ArgumentError.new("request payload is required")) @kind = payload['object_kind'].nil? ? 'webhook' : payload['object_kind'] @@ -13,8 +16,8 @@ def valid? def repository_url return "" unless payload["repository"] - return "" unless payload["repository"]["url"] - payload["repository"]["url"].strip + return "" unless payload["repository"][settings.use_http_urls ? "git_http_url" : "ssh_url"] + payload["repository"][settings.use_http_urls ? "git_http_url" : "ssh_url"].strip end def repository_group diff --git a/spec/fixtures/descriptor.xml b/spec/fixtures/descriptor.xml index 405c92a..8aeeca0 100644 --- a/spec/fixtures/descriptor.xml +++ b/spec/fixtures/descriptor.xml @@ -2,6 +2,7 @@ true false + false true primary true diff --git a/spec/support/shared/settings.rb b/spec/support/shared/settings.rb index a93e928..16a86e7 100644 --- a/spec/support/shared/settings.rb +++ b/spec/support/shared/settings.rb @@ -7,6 +7,7 @@ allow(jenkins_instance).to receive(:descriptor) { settings } allow(settings).to receive(:merge_request_processing?) { true } allow(settings).to receive(:merged_branch_triggering?) { true } + allow(settings).to receive(:use_http_urls?) { true } allow(settings).to receive(:ignore_users) { "user 1, user 2, user 3" } end end \ No newline at end of file diff --git a/views/gitlab_web_hook_root_action/global.erb b/views/gitlab_web_hook_root_action/global.erb index fc433fe..41622cc 100644 --- a/views/gitlab_web_hook_root_action/global.erb +++ b/views/gitlab_web_hook_root_action/global.erb @@ -14,6 +14,10 @@ f.checkbox :checked => "#{descriptor.merged_branch_triggering?}" end + f.entry :title => "Use HTTP URLs instead of SSH URLs", :field => 'use_http_urls' do + f.checkbox :checked => "#{descriptor.use_http_urls?}" + end + f.optionalBlock :title => "Automatic project creation", :name => 'automatic_project_creation', :checked => "#{descriptor.automatic_project_creation?}" do f.entry :title => 'Project master branch', :field => 'master_branch' do f.textbox :default => "#{descriptor.master_branch}" diff --git a/views/gitlab_web_hook_root_action/help-use_http_urls.erb b/views/gitlab_web_hook_root_action/help-use_http_urls.erb new file mode 100644 index 0000000..dc7d227 --- /dev/null +++ b/views/gitlab_web_hook_root_action/help-use_http_urls.erb @@ -0,0 +1,2 @@ +Whether to use HTTP URLs instead of SSH URLs when creating the project. +If enabled it will specifically use the git_http_url payload attribute. \ No newline at end of file diff --git a/work/gitlab-hook-GitlabWebHookRootAction.xml b/work/gitlab-hook-GitlabWebHookRootAction.xml index e64a329..34ab73c 100644 --- a/work/gitlab-hook-GitlabWebHookRootAction.xml +++ b/work/gitlab-hook-GitlabWebHookRootAction.xml @@ -2,6 +2,7 @@ true true + false true master false