Commit e971d285 authored by mh's avatar mh

add class to manage gitlab-ticketing plugin

parent e09b2b59
# manage schleuder-gitlab-ticketing config
class schleuder::gitlab_ticketing(
Array[String] $subject_filters = [],
Array[String] $sender_filters = [],
Optional[
Struct[{endpoint => String, token => String }]
] $gitlab = undef,
Hash[String,
Struct[{
Optional[gitlab] => Struct[{
Optional[endpoint] => String,
Optional[token] => String, }],
project => String,
namespace => String,
Optional[ticket_prefix] => String,
Optional[subject_filters] => Array[String],
Optional[sender_filters] => Array[String],
}]] $lists = {},
){
file{'/etc/schleuder/gitlab.yml': }
if !empty($lists) {
File['/etc/schleuder/gitlab.yml']{
content => template('schleuder/gitlab_ticketing/config.yml.erb'),
owner => root,
group => 'schleuder',
mode => '0640',
require => Package['schleuder'],
before => Service['schleuder-api-daemon'],
}
} else {
File['/etc/schleuder/gitlab.yml']{
ensure => absent,
}
}
}
require 'spec_helper'
describe 'schleuder::gitlab_ticketing' do
let(:facts){
{
:operatingsystem => 'CentOS',
:puppetversion => ENV['PUPPET_VERSION'].nil? ? '5.0.0' : ENV['PUPPET_VERSION'],
:concat_basedir => '/tmp',
}
}
let(:pre_condition){
'Exec{ path => "/tmp" }
include schleuder'
}
context 'default' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_file('/etc/schleuder/gitlab.yml').with_ensure('absent') }
end
context 'with params' do
let(:params) {
{
:subject_filters => [
"Encrypt certificate expiration notice",
'Mailman.* post from .* requires approval',
'Uncaught bounce notification',
],
:lists => {
'schleuder@example.com' => {
'project' => 'tickets',
'namespace' => 'group',
'ticket_prefix' => 'tg',
'gitlab' => {
'endpoint' => 'https://gitlab.example.com/api/v4',
'token' => 'hababa',
}
}
}
}
}
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_file('/etc/schleuder/gitlab.yml').with_content("---
subject_filters:
- 'Encrypt certificate expiration notice'
- 'Mailman.* post from .* requires approval'
- 'Uncaught bounce notification'
sender_filters: []
lists:
'schleuder@example.com':
project: 'tickets'
namespace: 'group'
ticket_prefix: 'tg'
gitlab:
endpoint: 'https://gitlab.example.com/api/v4'
token: 'hababa'
") }
end
end
---
<% if !@subject_filters.empty? -%>
subject_filters:
<% @subject_filters.sort.each do |f| -%>
- '<%= f %>'
<% end
else -%>
subject_filters: []
<% end -%>
<% if !@sender_filters.empty? -%>
sender_filters:
<% @sender_filters.sort.each do |f| -%>
- '<%= f %>'
<% end
else -%>
sender_filters: []
<% end -%>
<% if @gitlab -%>
gitlab:
endpoint: '<%= @gitlab['endpoint'] %>'
token: '<%= @gitlab['token'] %>'
<% end -%>
lists:
<% @lists.keys.sort.each do |l| -%>
'<%= l %>':
<% ['project','namespace','ticket_prefix'].each do |v|
if @lists[l][v] -%>
<%= v %>: '<%= @lists[l][v] %>'
<% end
end
if @lists[l]['subject_filters'] -%>
subject_filters:
<% @lists[l]['subject_filters'].sort.each do |f| -%>
- '<%= f %>'
<% end
end
if @lists[l]['sender_filters'] -%>
sender_filters:
<% @lists[l]['sender_filters'].sort.each do |f| -%>
- '<%= f %>'
<% end
end
if @lists[l]['gitlab'] -%>
gitlab:
endpoint: '<%= @lists[l]['gitlab']['endpoint'] %>'
token: '<%= @lists[l]['gitlab']['token'] %>'
<% end
end -%>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment