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 + %>