Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions models/root_action_descriptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand All @@ -114,6 +122,10 @@ def templated_jobs
@templates || {}
end

def templated_descriptions
@description_templates || {}
end

def templated_groups
@group_templates || {}
end
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions models/use_cases/process_commit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions models/values/payload_request_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
13 changes: 13 additions & 0 deletions views/gitlab_web_hook_root_action/global.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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
%><table width="100%"><%
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
%></table><div align="right"><%f.repeatableDeleteButton%></div><%
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
%><table width="100%"><%
Expand Down