From fc4da5d323dbfae868bdec4c9c60fd46b59f8180 Mon Sep 17 00:00:00 2001 From: Mick Sheppard Date: Thu, 7 Apr 2016 14:45:32 +0100 Subject: [PATCH 1/2] Job creation : allow a match against a sub-string of the repository description --- jenkins-gitlab-hook.pluginspec | 2 +- models/root_action_descriptor.rb | 15 +++++++++++++++ models/use_cases/process_commit.rb | 6 ++++++ models/values/payload_request_details.rb | 6 ++++++ views/gitlab_web_hook_root_action/global.erb | 13 +++++++++++++ 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/jenkins-gitlab-hook.pluginspec b/jenkins-gitlab-hook.pluginspec index e8c85ae..d97c233 100644 --- a/jenkins-gitlab-hook.pluginspec +++ b/jenkins-gitlab-hook.pluginspec @@ -1,7 +1,7 @@ Jenkins::Plugin::Specification.new do |plugin| plugin.name = "gitlab-hook" plugin.display_name = "Gitlab Hook Plugin" - plugin.version = '1.4.1' + plugin.version = '1.4.1MS' plugin.description = 'Enables Gitlab web hooks to be used to trigger SMC polling on Gitlab projects' plugin.url = 'https://wiki.jenkins-ci.org/display/JENKINS/Gitlab+Hook+Plugin' diff --git a/models/root_action_descriptor.rb b/models/root_action_descriptor.rb index 38dab9c..827ddf2 100644 --- a/models/root_action_descriptor.rb +++ b/models/root_action_descriptor.rb @@ -59,6 +59,7 @@ def load @description = read_property(doc, DESCRIPTION_PROPERTY) @templates = get_templates doc.root.elements['templates'] @group_templates = get_templates doc.root.elements['group_templates'] + @description_templates = get_templates doc.root.elements['description_templates'] @template = doc.root.elements['template'] && doc.root.elements['template'].text end end @@ -90,6 +91,13 @@ def save new.add_element('project').add_text(v) end + tpls = doc.root.add_element( 'description_templates' ) + templated_descriptions.each do |k,v| + new = tpls.add_element('template') + new.add_element('string').add_text(k) + new.add_element('project').add_text(v) + end + tpls = doc.root.add_element( 'group_templates' ) templated_groups.each do |k,v| new = tpls.add_element('template') @@ -114,6 +122,10 @@ def templated_jobs @templates || {} end + def templated_descriptions + @description_templates || {} + end + def templated_groups @group_templates || {} end @@ -137,6 +149,9 @@ def parse(form) @templates = form['templates'] && form2list( form['templates'] ).inject({}) do |hash, item| hash.update( item['string'] => item['project'] ) end + @description_templates = form['description_templates'] && form2list( form['description_templates'] ).inject({}) do |hash, item| + hash.update( item['string'] => item['project'] ) + end @group_templates = form['group_templates'] && form2list( form['group_templates'] ).inject({}) do |hash, item| hash.update( item['string'] => item['project'] ) end diff --git a/models/use_cases/process_commit.rb b/models/use_cases/process_commit.rb index a1d9ff0..15f4b97 100644 --- a/models/use_cases/process_commit.rb +++ b/models/use_cases/process_commit.rb @@ -44,6 +44,12 @@ def search_templates(details, projects) end end return if projects.any? + settings.templated_descriptions.each do |matchstr,template| + if details.repository_description.index matchstr + projects << @create_project_for_branch.from_template(template, details) + end + end + return if projects.any? settings.templated_groups.each do |matchstr,template| if details.repository_group == matchstr projects << @create_project_for_branch.from_template(template, details) diff --git a/models/values/payload_request_details.rb b/models/values/payload_request_details.rb index fbab003..cff61f0 100644 --- a/models/values/payload_request_details.rb +++ b/models/values/payload_request_details.rb @@ -24,6 +24,12 @@ def repository_name payload["repository"]["name"].strip end + def repository_description + return "" unless payload["repository"] + return "" unless payload["repository"]["description"] + payload["repository"]["description"].strip + end + def repository_homepage return "" unless payload["repository"] return "" unless payload["repository"]["homepage"] diff --git a/views/gitlab_web_hook_root_action/global.erb b/views/gitlab_web_hook_root_action/global.erb index cacf21d..8479859 100644 --- a/views/gitlab_web_hook_root_action/global.erb +++ b/views/gitlab_web_hook_root_action/global.erb @@ -49,6 +49,19 @@ An already existing jenkins project will be used as base, and different kind of end + f.entry :title => 'Templates for project description', :description => 'The incoming repository description is compared with the match string' do + f.repeatable :items => descriptor.templated_descriptions.to_a, :var => 'description_templates', :add => 'Add new description template' do + %><% + f.entry :title => 'Match string', :field => 'string' do + f.textbox :default => "#{description_templates.nil? ? '' : description_templates.first }" + end + f.entry :title => 'Base project', :field => 'project' do + f.textbox :default => "#{description_templates.nil? ? '' : description_templates.last }" + end + %>
<%f.repeatableDeleteButton%>
<% + end + end + f.entry :title => 'Templates for gitlab groups', :description => 'Full string comparison is performed with the incoming repository' do f.repeatable :items => descriptor.templated_groups.to_a, :var => 'group_templates', :add => 'Add new group template' do %><% From c0c7af6b9a3a25485b1c2cfb8de047f70541371a Mon Sep 17 00:00:00 2001 From: Mick Sheppard Date: Thu, 7 Apr 2016 15:02:57 +0100 Subject: [PATCH 2/2] Reverted version to original --- jenkins-gitlab-hook.pluginspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins-gitlab-hook.pluginspec b/jenkins-gitlab-hook.pluginspec index d97c233..e8c85ae 100644 --- a/jenkins-gitlab-hook.pluginspec +++ b/jenkins-gitlab-hook.pluginspec @@ -1,7 +1,7 @@ Jenkins::Plugin::Specification.new do |plugin| plugin.name = "gitlab-hook" plugin.display_name = "Gitlab Hook Plugin" - plugin.version = '1.4.1MS' + plugin.version = '1.4.1' plugin.description = 'Enables Gitlab web hooks to be used to trigger SMC polling on Gitlab projects' plugin.url = 'https://wiki.jenkins-ci.org/display/JENKINS/Gitlab+Hook+Plugin'