modulesync 0.10.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +9 -3
- data/.rubocop.yml +7 -0
- data/.rubocop_todo.yml +1 -6
- data/.travis.yml +11 -7
- data/CHANGELOG.md +54 -0
- data/Gemfile +5 -1
- data/HISTORY.md +227 -0
- data/README.md +58 -16
- data/Rakefile +25 -0
- data/features/step_definitions/git_steps.rb +1 -1
- data/features/update.feature +101 -27
- data/lib/modulesync.rb +110 -65
- data/lib/modulesync/cli.rb +21 -9
- data/lib/modulesync/git.rb +2 -1
- data/lib/modulesync/pr/github.rb +56 -0
- data/lib/modulesync/pr/gitlab.rb +53 -0
- data/lib/modulesync/renderer.rb +4 -3
- data/lib/modulesync/settings.rb +1 -2
- data/lib/modulesync/util.rb +4 -1
- data/modulesync.gemspec +4 -3
- 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 +9 -1
- metadata +29 -8
data/Rakefile
CHANGED
@@ -19,3 +19,28 @@ Cucumber::Rake::Task.new do |t|
|
|
19
19
|
end
|
20
20
|
|
21
21
|
task :test => %i[clean spec cucumber rubocop]
|
22
|
+
task :default => %i[test]
|
23
|
+
|
24
|
+
begin
|
25
|
+
require 'github_changelog_generator/task'
|
26
|
+
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
27
|
+
config.header = "# Changelog\n\nAll notable changes to this project will be documented in this file."
|
28
|
+
config.exclude_labels = %w[duplicate question invalid wontfix wont-fix modulesync skip-changelog]
|
29
|
+
config.user = 'voxpupuli'
|
30
|
+
config.project = 'modulesync'
|
31
|
+
config.future_release = Gem::Specification.load("#{config.project}.gemspec").version
|
32
|
+
end
|
33
|
+
|
34
|
+
# Workaround for https://github.com/github-changelog-generator/github-changelog-generator/issues/715
|
35
|
+
require 'rbconfig'
|
36
|
+
if RbConfig::CONFIG['host_os'] =~ /linux/
|
37
|
+
task :changelog do
|
38
|
+
puts 'Fixing line endings...'
|
39
|
+
changelog_file = File.join(__dir__, 'CHANGELOG.md')
|
40
|
+
changelog_txt = File.read(changelog_file)
|
41
|
+
new_contents = changelog_txt.gsub(/\r\n/, "\n")
|
42
|
+
File.open(changelog_file, 'w') { |file| file.puts new_contents }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
rescue LoadError
|
46
|
+
end
|
@@ -23,7 +23,7 @@ Given 'a remote module repository' do
|
|
23
23
|
CONFIG
|
24
24
|
end
|
25
25
|
|
26
|
-
Given /a remote module repository with "(.+?)" as the default branch/ do |branch|
|
26
|
+
Given Regexp.new(/a remote module repository with "(.+?)" as the default branch/) do |branch|
|
27
27
|
steps %(
|
28
28
|
Given a directory named "sources"
|
29
29
|
And I run `git clone --mirror https://github.com/maestrodev/puppet-test sources/puppet-test`
|
data/features/update.feature
CHANGED
@@ -31,7 +31,7 @@ Feature: update
|
|
31
31
|
Files added:
|
32
32
|
test
|
33
33
|
"""
|
34
|
-
Given I run `cat modules/puppet-test/test`
|
34
|
+
Given I run `cat modules/maestrodev/puppet-test/test`
|
35
35
|
Then the output should contain "aruba"
|
36
36
|
|
37
37
|
Scenario: Using skip_broken option and adding a new file to repo without write access
|
@@ -113,14 +113,14 @@ Feature: update
|
|
113
113
|
Then the exit status should be 0
|
114
114
|
And the output should match:
|
115
115
|
"""
|
116
|
-
Warning: using './moduleroot
|
116
|
+
Warning: using './moduleroot/test' as template without '.erb' suffix
|
117
117
|
"""
|
118
118
|
And the output should match:
|
119
119
|
"""
|
120
120
|
Files added:
|
121
121
|
test
|
122
122
|
"""
|
123
|
-
Given I run `cat modules/puppet-test/test`
|
123
|
+
Given I run `cat modules/maestrodev/puppet-test/test`
|
124
124
|
Then the output should contain "aruba"
|
125
125
|
|
126
126
|
Scenario: Adding a new file using global values
|
@@ -153,7 +153,7 @@ Feature: update
|
|
153
153
|
Files added:
|
154
154
|
test
|
155
155
|
"""
|
156
|
-
Given I run `cat modules/puppet-test/test`
|
156
|
+
Given I run `cat modules/maestrodev/puppet-test/test`
|
157
157
|
Then the output should contain "aruba"
|
158
158
|
|
159
159
|
Scenario: Adding a new file overriding global values
|
@@ -189,7 +189,7 @@ Feature: update
|
|
189
189
|
Files added:
|
190
190
|
test
|
191
191
|
"""
|
192
|
-
Given I run `cat modules/puppet-test/test`
|
192
|
+
Given I run `cat modules/maestrodev/puppet-test/test`
|
193
193
|
Then the output should contain "aruba"
|
194
194
|
|
195
195
|
Scenario: Adding a new file ignoring global values
|
@@ -225,7 +225,7 @@ Feature: update
|
|
225
225
|
Files added:
|
226
226
|
test
|
227
227
|
"""
|
228
|
-
Given I run `cat modules/puppet-test/test`
|
228
|
+
Given I run `cat modules/maestrodev/puppet-test/test`
|
229
229
|
Then the output should contain "aruba"
|
230
230
|
|
231
231
|
Scenario: Adding a file that ERB can't parse
|
@@ -342,7 +342,7 @@ Feature: update
|
|
342
342
|
Files changed:
|
343
343
|
+diff --git a/Gemfile b/Gemfile
|
344
344
|
"""
|
345
|
-
Given I run `cat modules/puppet-test/Gemfile`
|
345
|
+
Given I run `cat modules/maestrodev/puppet-test/Gemfile`
|
346
346
|
Then the output should contain:
|
347
347
|
"""
|
348
348
|
source 'https://somehost.com'
|
@@ -405,7 +405,7 @@ Feature: update
|
|
405
405
|
Not managing Gemfile in puppet-test
|
406
406
|
"""
|
407
407
|
And the exit status should be 0
|
408
|
-
Given I run `cat modules/puppet-test/Gemfile`
|
408
|
+
Given I run `cat modules/maestrodev/puppet-test/Gemfile`
|
409
409
|
Then the output should contain:
|
410
410
|
"""
|
411
411
|
source 'https://rubygems.org'
|
@@ -488,8 +488,8 @@ Feature: update
|
|
488
488
|
"""
|
489
489
|
some spec_helper fud
|
490
490
|
"""
|
491
|
-
And a directory named "modules/puppetlabs-apache/spec"
|
492
|
-
And a file named "modules/puppetlabs-apache/spec/spec_helper.rb" with:
|
491
|
+
And a directory named "modules/puppetlabs/puppetlabs-apache/spec"
|
492
|
+
And a file named "modules/puppetlabs/puppetlabs-apache/spec/spec_helper.rb" with:
|
493
493
|
"""
|
494
494
|
This is a fake spec_helper!
|
495
495
|
"""
|
@@ -499,7 +499,7 @@ Feature: update
|
|
499
499
|
Not managing spec/spec_helper.rb in puppetlabs-apache
|
500
500
|
"""
|
501
501
|
And the exit status should be 0
|
502
|
-
Given I run `cat modules/puppetlabs-apache/spec/spec_helper.rb`
|
502
|
+
Given I run `cat modules/puppetlabs/puppetlabs-apache/spec/spec_helper.rb`
|
503
503
|
Then the output should contain:
|
504
504
|
"""
|
505
505
|
This is a fake spec_helper!
|
@@ -538,7 +538,7 @@ Feature: update
|
|
538
538
|
Files added:
|
539
539
|
spec/spec_helper.rb
|
540
540
|
"""
|
541
|
-
Given I run `cat modules/puppet-test/spec/spec_helper.rb`
|
541
|
+
Given I run `cat modules/maestrodev/puppet-test/spec/spec_helper.rb`
|
542
542
|
Then the output should contain:
|
543
543
|
"""
|
544
544
|
require 'puppetlabs_spec_helper/module_helper'
|
@@ -577,7 +577,7 @@ Feature: update
|
|
577
577
|
Given a file named "managed_modules.yml" with:
|
578
578
|
"""
|
579
579
|
---
|
580
|
-
- puppet-test
|
580
|
+
- maestrodev/puppet-test
|
581
581
|
"""
|
582
582
|
And a file named "modulesync.yml" with:
|
583
583
|
"""
|
@@ -597,8 +597,8 @@ Feature: update
|
|
597
597
|
require '<%= required %>'
|
598
598
|
<% end %>
|
599
599
|
"""
|
600
|
-
Given I run `git init modules/puppet-test`
|
601
|
-
Given a file named "modules/puppet-test/.git/config" with:
|
600
|
+
Given I run `git init modules/maestrodev/puppet-test`
|
601
|
+
Given a file named "modules/maestrodev/puppet-test/.git/config" with:
|
602
602
|
"""
|
603
603
|
[core]
|
604
604
|
repositoryformatversion = 0
|
@@ -667,7 +667,7 @@ Feature: update
|
|
667
667
|
Files added:
|
668
668
|
test
|
669
669
|
"""
|
670
|
-
Given I run `cat modules/puppet-test/test`
|
670
|
+
Given I run `cat modules/maestrodev/puppet-test/test`
|
671
671
|
Then the output should contain "aruba"
|
672
672
|
|
673
673
|
Scenario: When specifying configurations in managed_modules.yml and using a filter
|
@@ -702,9 +702,9 @@ Feature: update
|
|
702
702
|
Files added:
|
703
703
|
test
|
704
704
|
"""
|
705
|
-
Given I run `cat modules/puppet-test/test`
|
705
|
+
Given I run `cat modules/maestrodev/puppet-test/test`
|
706
706
|
Then the output should contain "aruba"
|
707
|
-
And a directory named "modules/puppet-blacksmith" should not exist
|
707
|
+
And a directory named "modules/maestrodev/puppet-blacksmith" should not exist
|
708
708
|
|
709
709
|
Scenario: When specifying configurations in managed_modules.yml and using a negative filter
|
710
710
|
Given a file named "managed_modules.yml" with:
|
@@ -738,15 +738,15 @@ Feature: update
|
|
738
738
|
Files added:
|
739
739
|
test
|
740
740
|
"""
|
741
|
-
Given I run `cat modules/puppet-test/test`
|
741
|
+
Given I run `cat modules/maestrodev/puppet-test/test`
|
742
742
|
Then the output should contain "aruba"
|
743
|
-
And a directory named "modules/puppet-blacksmith" should not exist
|
743
|
+
And a directory named "modules/maestrodev/puppet-blacksmith" should not exist
|
744
744
|
|
745
745
|
Scenario: Updating a module with a .sync.yml file
|
746
746
|
Given a file named "managed_modules.yml" with:
|
747
747
|
"""
|
748
748
|
---
|
749
|
-
- puppet-test
|
749
|
+
- maestrodev/puppet-test
|
750
750
|
"""
|
751
751
|
And a file named "modulesync.yml" with:
|
752
752
|
"""
|
@@ -756,6 +756,9 @@ Feature: update
|
|
756
756
|
And a file named "config_defaults.yml" with:
|
757
757
|
"""
|
758
758
|
---
|
759
|
+
:global:
|
760
|
+
global-default: some-default
|
761
|
+
global-to-overwrite: to-be-overwritten
|
759
762
|
spec/spec_helper.rb:
|
760
763
|
require:
|
761
764
|
- puppetlabs_spec_helper/module_helper
|
@@ -766,8 +769,14 @@ Feature: update
|
|
766
769
|
require '<%= required %>'
|
767
770
|
<% end %>
|
768
771
|
"""
|
769
|
-
|
770
|
-
|
772
|
+
And a file named "moduleroot/global-test.md.erb" with:
|
773
|
+
"""
|
774
|
+
<%= @configs['global-default'] %>
|
775
|
+
<%= @configs['global-to-overwrite'] %>
|
776
|
+
<%= @configs['module-default'] %>
|
777
|
+
"""
|
778
|
+
Given I run `git init modules/maestrodev/puppet-test`
|
779
|
+
Given a file named "modules/maestrodev/puppet-test/.git/config" with:
|
771
780
|
"""
|
772
781
|
[core]
|
773
782
|
repositoryformatversion = 0
|
@@ -780,9 +789,12 @@ Feature: update
|
|
780
789
|
url = https://github.com/maestrodev/puppet-test.git
|
781
790
|
fetch = +refs/heads/*:refs/remotes/origin/*
|
782
791
|
"""
|
783
|
-
Given a file named "modules/puppet-test/.sync.yml" with:
|
792
|
+
Given a file named "modules/maestrodev/puppet-test/.sync.yml" with:
|
784
793
|
"""
|
785
794
|
---
|
795
|
+
:global:
|
796
|
+
global-to-overwrite: it-is-overwritten
|
797
|
+
module-default: some-value
|
786
798
|
spec/spec_helper.rb:
|
787
799
|
unmanaged: true
|
788
800
|
"""
|
@@ -792,6 +804,13 @@ Feature: update
|
|
792
804
|
"""
|
793
805
|
Not managing spec/spec_helper.rb in puppet-test
|
794
806
|
"""
|
807
|
+
Given I run `cat modules/maestrodev/puppet-test/global-test.md`
|
808
|
+
Then the output should match:
|
809
|
+
"""
|
810
|
+
some-default
|
811
|
+
it-is-overwritten
|
812
|
+
some-value
|
813
|
+
"""
|
795
814
|
|
796
815
|
Scenario: Module with custom namespace
|
797
816
|
Given a file named "managed_modules.yml" with:
|
@@ -824,9 +843,9 @@ Feature: update
|
|
824
843
|
Files added:
|
825
844
|
test
|
826
845
|
"""
|
827
|
-
Given I run `cat modules/puppet-test/.git/config`
|
846
|
+
Given I run `cat modules/maestrodev/puppet-test/.git/config`
|
828
847
|
Then the output should contain "url = https://github.com/maestrodev/puppet-test.git"
|
829
|
-
Given I run `cat modules/puppet-lib-file_concat/.git/config`
|
848
|
+
Given I run `cat modules/electrical/puppet-lib-file_concat/.git/config`
|
830
849
|
Then the output should contain "url = https://github.com/electrical/puppet-lib-file_concat.git"
|
831
850
|
|
832
851
|
Scenario: Modifying an existing file with values exposed by the module
|
@@ -858,7 +877,7 @@ Feature: update
|
|
858
877
|
Files changed:
|
859
878
|
+diff --git a/README.md b/README.md
|
860
879
|
"""
|
861
|
-
Given I run `cat modules/puppet-test/README.md`
|
880
|
+
Given I run `cat modules/maestrodev/puppet-test/README.md`
|
862
881
|
Then the output should contain:
|
863
882
|
"""
|
864
883
|
echo 'https://github.com/maestrodev'
|
@@ -886,6 +905,28 @@ Feature: update
|
|
886
905
|
Then the output should not contain "error"
|
887
906
|
Then the output should not contain "rejected"
|
888
907
|
|
908
|
+
Scenario: Creating a GitHub PR with an update
|
909
|
+
Given a mocked git configuration
|
910
|
+
And a remote module repository
|
911
|
+
And a directory named "moduleroot"
|
912
|
+
And I set the environment variables to:
|
913
|
+
| variable | value |
|
914
|
+
| GITHUB_TOKEN | foobar |
|
915
|
+
When I run `msync update --noop --branch managed_update --pr`
|
916
|
+
Then the output should contain "Would submit PR "
|
917
|
+
And the exit status should be 0
|
918
|
+
|
919
|
+
Scenario: Creating a GitLab MR with an update
|
920
|
+
Given a mocked git configuration
|
921
|
+
And a remote module repository
|
922
|
+
And a directory named "moduleroot"
|
923
|
+
And I set the environment variables to:
|
924
|
+
| variable | value |
|
925
|
+
| GITLAB_TOKEN | foobar |
|
926
|
+
When I run `msync update --noop --branch managed_update --pr`
|
927
|
+
Then the output should contain "Would submit MR "
|
928
|
+
And the exit status should be 0
|
929
|
+
|
889
930
|
Scenario: Repository with a default branch other than master
|
890
931
|
Given a mocked git configuration
|
891
932
|
And a remote module repository with "develop" as the default branch
|
@@ -903,3 +944,36 @@ Feature: update
|
|
903
944
|
When I run `msync update -m "Update Gemfile"`
|
904
945
|
Then the exit status should be 0
|
905
946
|
Then the output should contain "Using repository's default branch: develop"
|
947
|
+
|
948
|
+
Scenario: Adding a new file from a template using meta data
|
949
|
+
And a file named "config_defaults.yml" with:
|
950
|
+
"""
|
951
|
+
---
|
952
|
+
"""
|
953
|
+
Given a file named "managed_modules.yml" with:
|
954
|
+
"""
|
955
|
+
---
|
956
|
+
- puppet-test
|
957
|
+
"""
|
958
|
+
And a file named "modulesync.yml" with:
|
959
|
+
"""
|
960
|
+
---
|
961
|
+
namespace: maestrodev
|
962
|
+
git_base: https://github.com/
|
963
|
+
"""
|
964
|
+
And a directory named "moduleroot"
|
965
|
+
And a file named "moduleroot/test.erb" with:
|
966
|
+
"""
|
967
|
+
module: <%= @metadata[:module_name] %>
|
968
|
+
target: <%= @metadata[:target_file] %>
|
969
|
+
workdir: <%= @metadata[:workdir] %>
|
970
|
+
"""
|
971
|
+
When I run `msync update --noop`
|
972
|
+
Then the exit status should be 0
|
973
|
+
Given I run `cat modules/maestrodev/puppet-test/test`
|
974
|
+
Then the output should contain:
|
975
|
+
"""
|
976
|
+
module: puppet-test
|
977
|
+
target: modules/maestrodev/puppet-test/test
|
978
|
+
workdir: modules/maestrodev/puppet-test
|
979
|
+
"""
|
data/lib/modulesync.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'fileutils'
|
2
|
-
require 'octokit'
|
3
2
|
require 'pathname'
|
4
3
|
require 'modulesync/cli'
|
5
4
|
require 'modulesync/constants'
|
@@ -10,13 +9,7 @@ require 'modulesync/settings'
|
|
10
9
|
require 'modulesync/util'
|
11
10
|
require 'monkey_patches'
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
Octokit.configure do |c|
|
16
|
-
c.api_endpoint = ENV.fetch('GITHUB_BASE_URL', 'https://api.github.com')
|
17
|
-
end
|
18
|
-
|
19
|
-
module ModuleSync
|
12
|
+
module ModuleSync # rubocop:disable Metrics/ModuleLength
|
20
13
|
include Constants
|
21
14
|
|
22
15
|
def self.config_defaults
|
@@ -29,31 +22,39 @@ module ModuleSync
|
|
29
22
|
end
|
30
23
|
|
31
24
|
def self.local_file(config_path, file)
|
32
|
-
|
25
|
+
File.join(config_path, MODULE_FILES_DIR, file)
|
33
26
|
end
|
34
27
|
|
35
|
-
def self.module_file(project_root, puppet_module,
|
36
|
-
|
28
|
+
def self.module_file(project_root, namespace, puppet_module, *parts)
|
29
|
+
File.join(project_root, namespace, puppet_module, *parts)
|
37
30
|
end
|
38
31
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
32
|
+
# List all template files.
|
33
|
+
#
|
34
|
+
# Only select *.erb files, and strip the extension. This way all the code will only have to handle bare paths,
|
35
|
+
# except when reading the actual ERB text
|
36
|
+
def self.find_template_files(local_template_dir)
|
37
|
+
if File.exist?(local_template_dir)
|
38
|
+
Find.find(local_template_dir).find_all { |p| p =~ /.erb$/ && !File.directory?(p) }
|
39
|
+
.collect { |p| p.chomp('.erb') }
|
40
|
+
.to_a
|
43
41
|
else
|
44
|
-
puts "#{
|
42
|
+
$stdout.puts "#{local_template_dir} does not exist." \
|
43
|
+
' Check that you are working in your module configs directory or' \
|
44
|
+
' that you have passed in the correct directory with -c.'
|
45
45
|
exit
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
def self.
|
50
|
-
|
49
|
+
def self.relative_names(file_list, path)
|
50
|
+
file_list.map { |file| file.sub(/#{path}/, '') }
|
51
51
|
end
|
52
52
|
|
53
53
|
def self.managed_modules(config_file, filter, negative_filter)
|
54
54
|
managed_modules = Util.parse_config(config_file)
|
55
55
|
if managed_modules.empty?
|
56
|
-
puts "No modules found in #{config_file}.
|
56
|
+
$stdout.puts "No modules found in #{config_file}." \
|
57
|
+
' Check that you specified the right :configs directory and :managed_modules_conf file.'
|
57
58
|
exit
|
58
59
|
end
|
59
60
|
managed_modules.select! { |m| m =~ Regexp.new(filter) } unless filter.nil?
|
@@ -78,100 +79,144 @@ module ModuleSync
|
|
78
79
|
end
|
79
80
|
|
80
81
|
def self.manage_file(filename, settings, options)
|
82
|
+
namespace = settings.additional_settings[:namespace]
|
81
83
|
module_name = settings.additional_settings[:puppet_module]
|
82
84
|
configs = settings.build_file_configs(filename)
|
85
|
+
target_file = module_file(options[:project_root], namespace, module_name, filename)
|
83
86
|
if configs['delete']
|
84
|
-
Renderer.remove(
|
87
|
+
Renderer.remove(target_file)
|
85
88
|
else
|
86
89
|
templatename = local_file(options[:configs], filename)
|
87
90
|
begin
|
88
91
|
erb = Renderer.build(templatename)
|
89
|
-
template
|
90
|
-
|
92
|
+
# Meta data passed to the template as @metadata[:name]
|
93
|
+
metadata = {
|
94
|
+
:module_name => module_name,
|
95
|
+
:workdir => module_file(options[:project_root], namespace, module_name),
|
96
|
+
:target_file => target_file,
|
97
|
+
}
|
98
|
+
template = Renderer.render(erb, configs, metadata)
|
99
|
+
Renderer.sync(template, target_file)
|
91
100
|
rescue # rubocop:disable Lint/RescueWithoutErrorClass
|
92
|
-
|
101
|
+
$stderr.puts "Error while rendering #{filename}"
|
93
102
|
raise
|
94
103
|
end
|
95
104
|
end
|
96
105
|
end
|
97
106
|
|
98
107
|
def self.manage_module(puppet_module, module_files, module_options, defaults, options)
|
99
|
-
|
100
|
-
|
101
|
-
|
108
|
+
default_namespace = options[:namespace]
|
109
|
+
if module_options.is_a?(Hash) && module_options.key?(:namespace)
|
110
|
+
default_namespace = module_options[:namespace]
|
102
111
|
end
|
103
|
-
|
104
|
-
|
105
|
-
namespace, module_name = module_name(puppet_module, options[:namespace])
|
112
|
+
namespace, module_name = module_name(puppet_module, default_namespace)
|
113
|
+
git_repo = File.join(namespace, module_name)
|
106
114
|
unless options[:offline]
|
107
|
-
git_base
|
108
|
-
git_uri = "#{git_base}#{namespace}"
|
109
|
-
Git.pull(git_uri, module_name, options[:branch], options[:project_root], module_options || {})
|
115
|
+
Git.pull(options[:git_base], git_repo, options[:branch], options[:project_root], module_options || {})
|
110
116
|
end
|
111
|
-
|
117
|
+
|
118
|
+
module_configs = Util.parse_config(module_file(options[:project_root], namespace, module_name, MODULE_CONF_FILE))
|
112
119
|
settings = Settings.new(defaults[GLOBAL_DEFAULTS_KEY] || {},
|
113
120
|
defaults,
|
114
121
|
module_configs[GLOBAL_DEFAULTS_KEY] || {},
|
115
122
|
module_configs,
|
116
123
|
:puppet_module => module_name,
|
117
|
-
:git_base => git_base,
|
124
|
+
:git_base => options[:git_base],
|
118
125
|
:namespace => namespace)
|
119
126
|
settings.unmanaged_files(module_files).each do |filename|
|
120
|
-
puts "Not managing #{filename} in #{module_name}"
|
127
|
+
$stdout.puts "Not managing #{filename} in #{module_name}"
|
121
128
|
end
|
122
129
|
|
123
130
|
files_to_manage = settings.managed_files(module_files)
|
124
131
|
files_to_manage.each { |filename| manage_file(filename, settings, options) }
|
125
132
|
|
126
133
|
if options[:noop]
|
127
|
-
Git.update_noop(
|
134
|
+
Git.update_noop(git_repo, options)
|
135
|
+
options[:pr] && pr(module_options).manage(namespace, module_name, options)
|
128
136
|
elsif !options[:offline]
|
129
|
-
|
130
|
-
pushed
|
131
|
-
return nil unless pushed && options[:pr]
|
132
|
-
|
133
|
-
# We only do GitHub PR work if the GITHUB_TOKEN variable is set in the environment.
|
134
|
-
repo_path = "#{namespace}/#{module_name}"
|
135
|
-
puts "Submitting PR '#{options[:pr_title]}' on GitHub to #{repo_path} - merges #{options[:branch]} into master"
|
136
|
-
github = Octokit::Client.new(:access_token => GITHUB_TOKEN)
|
137
|
-
pr = github.create_pull_request(repo_path, 'master', options[:branch], options[:pr_title], options[:message])
|
138
|
-
puts "PR created at #{pr['html_url']}"
|
139
|
-
|
140
|
-
# PR labels can either be a list in the YAML file or they can pass in a comma
|
141
|
-
# separated list via the command line argument.
|
142
|
-
pr_labels = Util.parse_list(options[:pr_labels])
|
143
|
-
|
144
|
-
# We only assign labels to the PR if we've discovered a list > 1. The labels MUST
|
145
|
-
# already exist. We DO NOT create missing labels.
|
146
|
-
unless pr_labels.empty?
|
147
|
-
puts "Attaching the following labels to PR #{pr['number']}: #{pr_labels.join(', ')}"
|
148
|
-
github.add_labels_to_an_issue(repo_path, pr['number'], pr_labels)
|
149
|
-
end
|
137
|
+
pushed = Git.update(git_repo, files_to_manage, options)
|
138
|
+
pushed && options[:pr] && pr(module_options).manage(namespace, module_name, options)
|
150
139
|
end
|
151
140
|
end
|
152
141
|
|
142
|
+
def self.config_path(file, options)
|
143
|
+
return file if Pathname.new(file).absolute?
|
144
|
+
File.join(options[:configs], file)
|
145
|
+
end
|
146
|
+
|
147
|
+
def config_path(file, options)
|
148
|
+
self.class.config_path(file, options)
|
149
|
+
end
|
150
|
+
|
153
151
|
def self.update(options)
|
154
152
|
options = config_defaults.merge(options)
|
155
|
-
defaults = Util.parse_config(
|
153
|
+
defaults = Util.parse_config(config_path(CONF_FILE, options))
|
154
|
+
if options[:pr]
|
155
|
+
unless options[:branch]
|
156
|
+
$stderr.puts 'A branch must be specified with --branch to use --pr!'
|
157
|
+
raise
|
158
|
+
end
|
156
159
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
+
@pr = create_pr_manager if options[:pr]
|
161
|
+
end
|
162
|
+
|
163
|
+
local_template_dir = config_path(MODULE_FILES_DIR, options)
|
164
|
+
local_files = find_template_files(local_template_dir)
|
165
|
+
module_files = relative_names(local_files, local_template_dir)
|
160
166
|
|
161
|
-
managed_modules = self.managed_modules(
|
167
|
+
managed_modules = self.managed_modules(config_path(options[:managed_modules_conf], options),
|
168
|
+
options[:filter],
|
169
|
+
options[:negative_filter])
|
162
170
|
|
163
171
|
errors = false
|
164
172
|
# managed_modules is either an array or a hash
|
165
173
|
managed_modules.each do |puppet_module, module_options|
|
166
174
|
begin
|
167
|
-
|
175
|
+
mod_options = module_options.nil? ? nil : Util.symbolize_keys(module_options)
|
176
|
+
manage_module(puppet_module, module_files, mod_options, defaults, options)
|
168
177
|
rescue # rubocop:disable Lint/RescueWithoutErrorClass
|
169
|
-
|
178
|
+
$stderr.puts "Error while updating #{puppet_module}"
|
170
179
|
raise unless options[:skip_broken]
|
171
180
|
errors = true
|
172
|
-
puts "Skipping #{puppet_module} as update process failed"
|
181
|
+
$stdout.puts "Skipping #{puppet_module} as update process failed"
|
173
182
|
end
|
174
183
|
end
|
175
184
|
exit 1 if errors && options[:fail_on_warnings]
|
176
185
|
end
|
186
|
+
|
187
|
+
def self.pr(module_options)
|
188
|
+
module_options ||= {}
|
189
|
+
github_conf = module_options[:github]
|
190
|
+
gitlab_conf = module_options[:gitlab]
|
191
|
+
|
192
|
+
if !github_conf.nil?
|
193
|
+
base_url = github_conf[:base_url] || ENV.fetch('GITHUB_BASE_URL', 'https://api.github.com')
|
194
|
+
require 'modulesync/pr/github'
|
195
|
+
ModuleSync::PR::GitHub.new(github_conf[:token], base_url)
|
196
|
+
elsif !gitlab_conf.nil?
|
197
|
+
base_url = gitlab_conf[:base_url] || ENV.fetch('GITLAB_BASE_URL', 'https://gitlab.com/api/v4')
|
198
|
+
require 'modulesync/pr/gitlab'
|
199
|
+
ModuleSync::PR::GitLab.new(gitlab_conf[:token], base_url)
|
200
|
+
elsif @pr.nil?
|
201
|
+
$stderr.puts 'No GitHub or GitLab token specified for --pr!'
|
202
|
+
raise
|
203
|
+
else
|
204
|
+
@pr
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def self.create_pr_manager
|
209
|
+
github_token = ENV.fetch('GITHUB_TOKEN', '')
|
210
|
+
gitlab_token = ENV.fetch('GITLAB_TOKEN', '')
|
211
|
+
|
212
|
+
if !github_token.empty?
|
213
|
+
require 'modulesync/pr/github'
|
214
|
+
ModuleSync::PR::GitHub.new(github_token, ENV.fetch('GITHUB_BASE_URL', 'https://api.github.com'))
|
215
|
+
elsif !gitlab_token.empty?
|
216
|
+
require 'modulesync/pr/gitlab'
|
217
|
+
ModuleSync::PR::GitLab.new(gitlab_token, ENV.fetch('GITLAB_BASE_URL', 'https://gitlab.com/api/v4'))
|
218
|
+
else
|
219
|
+
warn '--pr specified without environment variables GITHUB_TOKEN or GITLAB_TOKEN'
|
220
|
+
end
|
221
|
+
end
|
177
222
|
end
|