modulesync 0.9.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,5 +14,15 @@ module ModuleSync
14
14
  {}
15
15
  end
16
16
  end
17
+
18
+ def self.parse_list(option_value)
19
+ if option_value.is_a? String
20
+ option_value.split(',')
21
+ elsif option_value.is_a? Array
22
+ option_value
23
+ else
24
+ []
25
+ end
26
+ end
17
27
  end
18
28
  end
@@ -3,7 +3,7 @@ $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 = '0.9.0'
6
+ spec.version = '1.3.0'
7
7
  spec.authors = ['Vox Pupuli']
8
8
  spec.email = ['voxpupuli@groups.io']
9
9
  spec.summary = 'Puppet Module Synchronizer'
@@ -17,13 +17,15 @@ Gem::Specification.new do |spec|
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'
28
+ spec.add_runtime_dependency 'octokit', '~>4.0'
27
29
  spec.add_runtime_dependency 'puppet-blacksmith', '~>3.0'
28
30
  spec.add_runtime_dependency 'thor'
29
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
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe ModuleSync do
4
4
  context '::update' do
5
5
  it 'loads the managed modules from the specified :managed_modules_conf' do
6
- allow(ModuleSync).to receive(:local_files).and_return([])
6
+ allow(ModuleSync).to receive(:find_template_files).and_return([])
7
7
  allow(ModuleSync::Util).to receive(:parse_config).with('./config_defaults.yml').and_return({})
8
8
  expect(ModuleSync).to receive(:managed_modules).with('./test_file.yml', nil, nil).and_return([])
9
9
 
@@ -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: 0.9.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vox Pupuli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-26 00:00:00.000000000 Z
11
+ date: 2020-07-21 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,34 @@ 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'
111
+ - !ruby/object:Gem::Dependency
112
+ name: octokit
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '4.0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '4.0'
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: puppet-blacksmith
99
127
  requirement: !ruby/object:Gem::Requirement
@@ -152,12 +180,16 @@ files:
152
180
  - lib/modulesync/constants.rb
153
181
  - lib/modulesync/git.rb
154
182
  - lib/modulesync/hook.rb
183
+ - lib/modulesync/pr/github.rb
184
+ - lib/modulesync/pr/gitlab.rb
155
185
  - lib/modulesync/renderer.rb
156
186
  - lib/modulesync/settings.rb
157
187
  - lib/modulesync/util.rb
158
188
  - lib/monkey_patches.rb
159
189
  - modulesync.gemspec
160
190
  - spec/spec_helper.rb
191
+ - spec/unit/modulesync/pr/github_spec.rb
192
+ - spec/unit/modulesync/pr/gitlab_spec.rb
161
193
  - spec/unit/modulesync/settings_spec.rb
162
194
  - spec/unit/modulesync_spec.rb
163
195
  homepage: http://github.com/voxpupuli/modulesync
@@ -179,8 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
211
  - !ruby/object:Gem::Version
180
212
  version: '0'
181
213
  requirements: []
182
- rubyforge_project:
183
- rubygems_version: 2.7.6
214
+ rubygems_version: 3.1.4
184
215
  signing_key:
185
216
  specification_version: 4
186
217
  summary: Puppet Module Synchronizer
@@ -191,5 +222,7 @@ test_files:
191
222
  - features/support/env.rb
192
223
  - features/update.feature
193
224
  - spec/spec_helper.rb
225
+ - spec/unit/modulesync/pr/github_spec.rb
226
+ - spec/unit/modulesync/pr/gitlab_spec.rb
194
227
  - spec/unit/modulesync/settings_spec.rb
195
228
  - spec/unit/modulesync_spec.rb