modulesync 1.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +9 -3
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +1 -1
- data/.travis.yml +11 -7
- data/CHANGELOG.md +57 -0
- data/Gemfile +5 -1
- data/HISTORY.md +227 -0
- data/README.md +58 -16
- data/Rakefile +25 -0
- data/features/update.feature +55 -0
- data/lib/modulesync.rb +83 -48
- data/lib/modulesync/cli.rb +9 -3
- data/lib/modulesync/pr/github.rb +57 -0
- data/lib/modulesync/pr/gitlab.rb +54 -0
- data/lib/modulesync/renderer.rb +4 -3
- data/lib/modulesync/util.rb +4 -1
- data/modulesync.gemspec +5 -4
- data/spec/unit/modulesync/pr/github_spec.rb +49 -0
- data/spec/unit/modulesync/pr/gitlab_spec.rb +81 -0
- data/spec/unit/modulesync_spec.rb +8 -0
- metadata +37 -10
data/lib/modulesync/renderer.rb
CHANGED
@@ -4,8 +4,9 @@ require 'find'
|
|
4
4
|
module ModuleSync
|
5
5
|
module Renderer
|
6
6
|
class ForgeModuleFile
|
7
|
-
def initialize(configs = {})
|
7
|
+
def initialize(configs = {}, metadata = {})
|
8
8
|
@configs = configs
|
9
|
+
@metadata = metadata
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
@@ -26,8 +27,8 @@ module ModuleSync
|
|
26
27
|
File.delete(file) if File.exist?(file)
|
27
28
|
end
|
28
29
|
|
29
|
-
def self.render(_template, configs = {})
|
30
|
-
ForgeModuleFile.new(configs).render
|
30
|
+
def self.render(_template, configs = {}, metadata = {})
|
31
|
+
ForgeModuleFile.new(configs, metadata).render
|
31
32
|
end
|
32
33
|
|
33
34
|
def self.sync(template, target_name)
|
data/lib/modulesync/util.rb
CHANGED
@@ -3,7 +3,10 @@ require 'yaml'
|
|
3
3
|
module ModuleSync
|
4
4
|
module Util
|
5
5
|
def self.symbolize_keys(hash)
|
6
|
-
hash.inject({})
|
6
|
+
hash.inject({}) do |memo, (k, v)|
|
7
|
+
memo[k.to_sym] = v.is_a?(Hash) ? symbolize_keys(v) : v
|
8
|
+
memo
|
9
|
+
end
|
7
10
|
end
|
8
11
|
|
9
12
|
def self.parse_config(config_file)
|
data/modulesync.gemspec
CHANGED
@@ -3,28 +3,29 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = 'modulesync'
|
6
|
-
spec.version = '
|
6
|
+
spec.version = '2.0.1'
|
7
7
|
spec.authors = ['Vox Pupuli']
|
8
8
|
spec.email = ['voxpupuli@groups.io']
|
9
9
|
spec.summary = 'Puppet Module Synchronizer'
|
10
10
|
spec.description = 'Utility to synchronize common files across puppet modules in Github.'
|
11
11
|
spec.homepage = 'http://github.com/voxpupuli/modulesync'
|
12
12
|
spec.license = 'Apache-2.0'
|
13
|
-
spec.required_ruby_version = '>= 2.
|
13
|
+
spec.required_ruby_version = '>= 2.5.0'
|
14
14
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0")
|
16
16
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ['lib']
|
19
19
|
|
20
|
-
spec.add_development_dependency 'aruba'
|
20
|
+
spec.add_development_dependency 'aruba', '~> 0.14'
|
21
21
|
spec.add_development_dependency 'bundler'
|
22
22
|
spec.add_development_dependency 'rake'
|
23
23
|
spec.add_development_dependency 'rspec'
|
24
24
|
spec.add_development_dependency 'rubocop', '~> 0.50.0'
|
25
25
|
|
26
26
|
spec.add_runtime_dependency 'git', '~>1.3'
|
27
|
+
spec.add_runtime_dependency 'gitlab', '~>4.0'
|
27
28
|
spec.add_runtime_dependency 'octokit', '~>4.0'
|
28
|
-
spec.add_runtime_dependency 'puppet-blacksmith', '
|
29
|
+
spec.add_runtime_dependency 'puppet-blacksmith', '>= 3.0', '< 7'
|
29
30
|
spec.add_runtime_dependency 'thor'
|
30
31
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'modulesync/pr/github'
|
3
|
+
|
4
|
+
describe ModuleSync::PR::GitHub do
|
5
|
+
context '::manage' do
|
6
|
+
before(:each) do
|
7
|
+
@git_repo = 'test/modulesync'
|
8
|
+
@namespace, @repo_name = @git_repo.split('/')
|
9
|
+
@options = {
|
10
|
+
:pr => true,
|
11
|
+
:pr_title => 'Test PR is submitted',
|
12
|
+
:branch => 'test',
|
13
|
+
:message => 'Hello world',
|
14
|
+
:pr_auto_merge => false,
|
15
|
+
}
|
16
|
+
|
17
|
+
@client = double()
|
18
|
+
allow(Octokit::Client).to receive(:new).and_return(@client)
|
19
|
+
@it = ModuleSync::PR::GitHub.new('test', 'https://api.github.com')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'submits PR when --pr is set' do
|
23
|
+
allow(@client).to receive(:pull_requests).with(@git_repo, :state => 'open', :base => 'master', :head => "#{@namespace}:#{@options[:branch]}").and_return([])
|
24
|
+
expect(@client).to receive(:create_pull_request).with(@git_repo, 'master', @options[:branch], @options[:pr_title], @options[:message]).and_return({"html_url" => "http://example.com/pulls/22"})
|
25
|
+
expect { @it.manage(@namespace, @repo_name, @options) }.to output(/Submitted PR/).to_stdout
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'skips submitting PR if one has already been issued' do
|
29
|
+
pr = {
|
30
|
+
"title" => "Test title",
|
31
|
+
"html_url" => "https://example.com/pulls/44",
|
32
|
+
"number" => "44"
|
33
|
+
}
|
34
|
+
|
35
|
+
expect(@client).to receive(:pull_requests).with(@git_repo, :state => 'open', :base => 'master', :head => "#{@namespace}:#{@options[:branch]}").and_return([pr])
|
36
|
+
expect { @it.manage(@namespace, @repo_name, @options) }.to output(/Skipped! 1 PRs found for branch test/).to_stdout
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'adds labels to PR when --pr-labels is set' do
|
40
|
+
@options[:pr_labels] = "HELLO,WORLD"
|
41
|
+
|
42
|
+
allow(@client).to receive(:create_pull_request).and_return({"html_url" => "http://example.com/pulls/22", "number" => "44"})
|
43
|
+
allow(@client).to receive(:pull_requests).with(@git_repo, :state => 'open', :base => 'master', :head => "#{@namespace}:#{@options[:branch]}").and_return([])
|
44
|
+
|
45
|
+
expect(@client).to receive(:add_labels_to_an_issue).with(@git_repo, "44", ["HELLO", "WORLD"])
|
46
|
+
expect { @it.manage(@namespace, @repo_name, @options) }.to output(/Attaching the following labels to PR 44: HELLO, WORLD/).to_stdout
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'modulesync/pr/gitlab'
|
3
|
+
|
4
|
+
describe ModuleSync::PR::GitLab do
|
5
|
+
context '::manage' do
|
6
|
+
before(:each) do
|
7
|
+
@git_repo = 'test/modulesync'
|
8
|
+
@namespace, @repo_name = @git_repo.split('/')
|
9
|
+
@options = {
|
10
|
+
:pr => true,
|
11
|
+
:pr_title => 'Test PR is submitted',
|
12
|
+
:branch => 'test',
|
13
|
+
:message => 'Hello world',
|
14
|
+
:pr_auto_merge => false,
|
15
|
+
}
|
16
|
+
|
17
|
+
@client = double()
|
18
|
+
allow(Gitlab::Client).to receive(:new).and_return(@client)
|
19
|
+
@it = ModuleSync::PR::GitLab.new('test', 'https://gitlab.com/api/v4')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'submits MR when --pr is set' do
|
23
|
+
allow(@client).to receive(:merge_requests)
|
24
|
+
.with(@git_repo,
|
25
|
+
:state => 'opened',
|
26
|
+
:source_branch => "#{@namespace}:#{@options[:branch]}",
|
27
|
+
:target_branch => 'master',
|
28
|
+
).and_return([])
|
29
|
+
|
30
|
+
expect(@client).to receive(:create_merge_request)
|
31
|
+
.with(@git_repo,
|
32
|
+
@options[:pr_title],
|
33
|
+
:labels => [],
|
34
|
+
:source_branch => @options[:branch],
|
35
|
+
:target_branch => 'master',
|
36
|
+
).and_return({"html_url" => "http://example.com/pulls/22"})
|
37
|
+
|
38
|
+
expect { @it.manage(@namespace, @repo_name, @options) }.to output(/Submitted MR/).to_stdout
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'skips submitting MR if one has already been issued' do
|
42
|
+
mr = {
|
43
|
+
"title" => "Test title",
|
44
|
+
"html_url" => "https://example.com/pulls/44",
|
45
|
+
"iid" => "44"
|
46
|
+
}
|
47
|
+
|
48
|
+
expect(@client).to receive(:merge_requests)
|
49
|
+
.with(@git_repo,
|
50
|
+
:state => 'opened',
|
51
|
+
:source_branch => "#{@namespace}:#{@options[:branch]}",
|
52
|
+
:target_branch => 'master',
|
53
|
+
).and_return([mr])
|
54
|
+
|
55
|
+
expect { @it.manage(@namespace, @repo_name, @options) }.to output(/Skipped! 1 MRs found for branch test/).to_stdout
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'adds labels to MR when --pr-labels is set' do
|
59
|
+
@options[:pr_labels] = "HELLO,WORLD"
|
60
|
+
mr = double()
|
61
|
+
allow(mr).to receive(:iid).and_return("42")
|
62
|
+
|
63
|
+
expect(@client).to receive(:create_merge_request)
|
64
|
+
.with(@git_repo,
|
65
|
+
@options[:pr_title],
|
66
|
+
:labels => ["HELLO", "WORLD"],
|
67
|
+
:source_branch => @options[:branch],
|
68
|
+
:target_branch => 'master',
|
69
|
+
).and_return(mr)
|
70
|
+
|
71
|
+
allow(@client).to receive(:merge_requests)
|
72
|
+
.with(@git_repo,
|
73
|
+
:state => 'opened',
|
74
|
+
:source_branch => "#{@namespace}:#{@options[:branch]}",
|
75
|
+
:target_branch => 'master',
|
76
|
+
).and_return([])
|
77
|
+
|
78
|
+
expect { @it.manage(@namespace, @repo_name, @options) }.to output(/Attached the following labels to MR 42: HELLO, WORLD/).to_stdout
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -11,4 +11,12 @@ describe ModuleSync do
|
|
11
11
|
ModuleSync.update(options)
|
12
12
|
end
|
13
13
|
end
|
14
|
+
|
15
|
+
context '::pr' do
|
16
|
+
describe "Raise Error" do
|
17
|
+
it 'raises an error when neither GITHUB_TOKEN nor GITLAB_TOKEN are set for PRs' do
|
18
|
+
expect { ModuleSync.pr({}) }.to raise_error(RuntimeError).and output(/No GitHub or GitLab token specified for --pr/).to_stderr
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
14
22
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modulesync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vox Pupuli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aruba
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '0.14'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '0.14'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '1.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: gitlab
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '4.0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '4.0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: octokit
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,16 +126,22 @@ dependencies:
|
|
112
126
|
name: puppet-blacksmith
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
|
-
- - "
|
129
|
+
- - ">="
|
116
130
|
- !ruby/object:Gem::Version
|
117
131
|
version: '3.0'
|
132
|
+
- - "<"
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '7'
|
118
135
|
type: :runtime
|
119
136
|
prerelease: false
|
120
137
|
version_requirements: !ruby/object:Gem::Requirement
|
121
138
|
requirements:
|
122
|
-
- - "
|
139
|
+
- - ">="
|
123
140
|
- !ruby/object:Gem::Version
|
124
141
|
version: '3.0'
|
142
|
+
- - "<"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '7'
|
125
145
|
- !ruby/object:Gem::Dependency
|
126
146
|
name: thor
|
127
147
|
requirement: !ruby/object:Gem::Requirement
|
@@ -151,6 +171,7 @@ files:
|
|
151
171
|
- ".travis.yml"
|
152
172
|
- CHANGELOG.md
|
153
173
|
- Gemfile
|
174
|
+
- HISTORY.md
|
154
175
|
- LICENSE
|
155
176
|
- README.md
|
156
177
|
- Rakefile
|
@@ -166,12 +187,16 @@ files:
|
|
166
187
|
- lib/modulesync/constants.rb
|
167
188
|
- lib/modulesync/git.rb
|
168
189
|
- lib/modulesync/hook.rb
|
190
|
+
- lib/modulesync/pr/github.rb
|
191
|
+
- lib/modulesync/pr/gitlab.rb
|
169
192
|
- lib/modulesync/renderer.rb
|
170
193
|
- lib/modulesync/settings.rb
|
171
194
|
- lib/modulesync/util.rb
|
172
195
|
- lib/monkey_patches.rb
|
173
196
|
- modulesync.gemspec
|
174
197
|
- spec/spec_helper.rb
|
198
|
+
- spec/unit/modulesync/pr/github_spec.rb
|
199
|
+
- spec/unit/modulesync/pr/gitlab_spec.rb
|
175
200
|
- spec/unit/modulesync/settings_spec.rb
|
176
201
|
- spec/unit/modulesync_spec.rb
|
177
202
|
homepage: http://github.com/voxpupuli/modulesync
|
@@ -186,14 +211,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
186
211
|
requirements:
|
187
212
|
- - ">="
|
188
213
|
- !ruby/object:Gem::Version
|
189
|
-
version: 2.
|
214
|
+
version: 2.5.0
|
190
215
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
216
|
requirements:
|
192
217
|
- - ">="
|
193
218
|
- !ruby/object:Gem::Version
|
194
219
|
version: '0'
|
195
220
|
requirements: []
|
196
|
-
rubygems_version: 3.
|
221
|
+
rubygems_version: 3.1.2
|
197
222
|
signing_key:
|
198
223
|
specification_version: 4
|
199
224
|
summary: Puppet Module Synchronizer
|
@@ -204,5 +229,7 @@ test_files:
|
|
204
229
|
- features/support/env.rb
|
205
230
|
- features/update.feature
|
206
231
|
- spec/spec_helper.rb
|
232
|
+
- spec/unit/modulesync/pr/github_spec.rb
|
233
|
+
- spec/unit/modulesync/pr/gitlab_spec.rb
|
207
234
|
- spec/unit/modulesync/settings_spec.rb
|
208
235
|
- spec/unit/modulesync_spec.rb
|