pdksync 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/.travis.yml +15 -13
- data/CHANGELOG.md +16 -1
- data/Gemfile +2 -0
- data/README.md +1 -1
- data/Rakefile +42 -8
- data/lib/pdksync.rb +171 -131
- data/managed_modules.yml +54 -29
- data/pdksync.gemspec +1 -1
- data/spec/lib/pdksync_spec.rb +32 -46
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1ddb56d6bd4366f686243b4d773083709f966726caf0d2fd580aba1e9373c890
|
4
|
+
data.tar.gz: 34063f7b4a545f18f89c58b260061ffb93575b7f15ad932cb8ddeb9ed50ea209
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 027c7bf9b6d2482631119390863bccc0295a4c8737ef3e741a793cf163f57a726be46a99fb116d43055deeab3f69420ee88065878e8d58df637d0536e57055a1
|
7
|
+
data.tar.gz: 25b0cec819fb71ee5030e3a357deacb8ce219bd81323bf33e861b3cd5b456bd9dacf2f6993e32e52fadcdcd298ea530d439eb1093aa9d21667a2a18b03abc66b
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.travis.yml
CHANGED
@@ -1,25 +1,27 @@
|
|
1
|
-
---
|
2
1
|
sudo: false
|
3
2
|
dist: trusty
|
4
3
|
language: ruby
|
5
4
|
cache: bundler
|
6
5
|
before_install:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
- bundle -v
|
7
|
+
- rm -f Gemfile.lock
|
8
|
+
- gem update --system
|
9
|
+
- gem --version
|
10
|
+
- bundle -v
|
12
11
|
script:
|
13
|
-
|
12
|
+
- bundle exec $CHECK
|
14
13
|
rvm:
|
15
|
-
|
14
|
+
- 2.4.1
|
16
15
|
matrix:
|
17
16
|
fast_finish: true
|
18
17
|
include:
|
19
|
-
|
20
|
-
|
18
|
+
- env: CHECK='rubocop'
|
19
|
+
- env: CHECK='rspec spec'
|
21
20
|
branches:
|
22
21
|
only:
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
- master
|
23
|
+
- "/^v\\d/"
|
24
|
+
- release
|
25
|
+
env:
|
26
|
+
global:
|
27
|
+
secure: Hk8cxtIHM6kyRBSmcWWUSXUV50E/yo3MGJf3mPphb3ORUfzqjB8FGZLSn1VCIP81y++U6pZAg8/AkvcDNME0at1wWh/ONiOwYKxAyyVfr0/5/i7a+dIj/9MX2kUT6MBKZXipbln/u5brdwBAHJccFHz7doq30Nd108KE5ucqf0ZbptJyDbpsrIturK9Hx+mde9sYd6MyNlzGJkQOhSL22Zd+ppBSf/GDpk2+yWN171oGwHDPWPE47q4nkIrWjnWy0kLCqxoM0zHIPxPES6lhudso4ofbumnRiHcr7DldReC8Rq1CUe/fhG7udGEdPN26JAREyUeD8MOwo2uQohQluHvjOMx9leF7Sbu+tk5E2bqVz5ofm0bksZUIBahUtGP+REvwVruFOH8RsvO3pQBndDKG11691UY55L9qZNaQ82cNOWbfG1nNuglH0GIpJgdhjvWuGw1he4c18u1fgQGM01xO7JEDIpYHrrjBboD3mL/iXMmvxwg35eIrlkfdgl9DTBWqKOoLi79WpkDajI+2B/ABXW4L/WKWlM041UjAs5/r3jgkbcZz1nZVbU4Wa5r/6RvIfrM/FXnaGuZcwx7VdPBmfyhV4rgM4siyJDdhqudTRsq1+Al9q3MhZcyKQLmad8ShEx+dfG9WRBoayE+piD/9xkfriqdMk5YEjH02grE=
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,21 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org).
|
4
4
|
|
5
|
+
## [0.2.0](https://github.com/puppetlabs/pdksync/tree/0.1.0) (2018-11-02)
|
6
|
+
|
7
|
+
[Full Changelog](https://github.com/puppetlabs/pdksync/compare/0.1.0...0.1.0)
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
- \(feat\) add colourised output, fix pdk path [\#68](https://github.com/puppetlabs/pdksync/pull/68) ([tphoney](https://github.com/tphoney))
|
12
|
+
- \(CLOUD-2094\) adding container modules to the list [\#67](https://github.com/puppetlabs/pdksync/pull/67) ([sheenaajay](https://github.com/sheenaajay))
|
13
|
+
- \(feat\) adding git commit rake task [\#63](https://github.com/puppetlabs/pdksync/pull/63) ([tphoney](https://github.com/tphoney))
|
14
|
+
- \(FEAT\) add clone\_managed\_modules task [\#58](https://github.com/puppetlabs/pdksync/pull/58) ([tphoney](https://github.com/tphoney))
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
|
18
|
+
- Use https instead of ssh for the clone [\#72](https://github.com/puppetlabs/pdksync/pull/72) ([HelenCampbell](https://github.com/HelenCampbell))
|
19
|
+
|
5
20
|
## [0.1.0](https://github.com/puppetlabs/pdksync/tree/0.1.0) (2018-05-23)
|
6
21
|
|
7
22
|
[Full Changelog](https://github.com/puppetlabs/pdksync/compare/73bf282b297781bc26562bfb51b91b4f7b1632d1...0.1.0)
|
@@ -30,4 +45,4 @@ All notable changes to this project will be documented in this file. The format
|
|
30
45
|
|
31
46
|
|
32
47
|
|
33
|
-
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/
|
48
|
+
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
|
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -1,17 +1,51 @@
|
|
1
1
|
require_relative 'lib/pdksync'
|
2
2
|
require 'github_changelog_generator/task'
|
3
3
|
|
4
|
-
|
5
|
-
desc 'Run pdk update'
|
4
|
+
desc 'Run full pdksync process, clone repository, pdk update, create pr.'
|
6
5
|
task :pdksync do
|
7
|
-
|
8
|
-
|
6
|
+
args = {:branch_name => "pdksync_{ref}",
|
7
|
+
:commit_message => "pdksync_{ref}",
|
8
|
+
:pr_title => "pdksync_{ref}"}
|
9
|
+
PdkSync::main(steps: [:use_pdk_ref, :clone, :pdk_update, :create_commit, :push_and_create_pr], args: args)
|
10
|
+
end
|
11
|
+
|
12
|
+
namespace :pdk do
|
13
|
+
desc 'Runs PDK convert against modules'
|
14
|
+
task :pdk_convert do
|
15
|
+
PdkSync::main(steps: [:pdk_convert])
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'Runs PDK validate against modules'
|
19
|
+
task :pdk_validate do
|
20
|
+
PdkSync::main(steps: [:pdk_validate])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
namespace :git do
|
25
|
+
desc 'Clone managed modules'
|
26
|
+
task :clone_managed_modules do
|
27
|
+
PdkSync::main(steps: [:clone])
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Stage commits for modules, branchname and commit message eg rake 'git:create_commit[flippity, commit messagez]'"
|
31
|
+
task :create_commit, [:branch_name, :commit_message] do |task, args|
|
32
|
+
PdkSync::main(steps: [:create_commit], args: args)
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Push commit, and create PR for modules eg rake 'git:push_and_create_pr[pr title goes here]'"
|
36
|
+
task :push_and_create_pr, [:pr_title] do |task, args|
|
37
|
+
PdkSync::main(steps: [:push_and_create_pr], args: args)
|
38
|
+
end
|
39
|
+
|
40
|
+
desc "Clean up origin branches, (branches must include pdksync in their name) eg rake 'git:clean[pdksync_origin_branch]'"
|
41
|
+
task :clean_branches, [:branch_name] do |task, args|
|
42
|
+
PdkSync::main(steps: [:clean_branches], args: args)
|
43
|
+
end
|
9
44
|
end
|
10
45
|
|
11
|
-
desc
|
12
|
-
task :
|
13
|
-
PdkSync::
|
14
|
-
puts "The script has run."
|
46
|
+
desc "Run a command against modules eg rake 'run_a_command[complex command here -f -gx]'"
|
47
|
+
task :run_a_command, [:command] do |task, args|
|
48
|
+
PdkSync::main(steps: [:run_a_command], args: args[:command])
|
15
49
|
end
|
16
50
|
|
17
51
|
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
data/lib/pdksync.rb
CHANGED
@@ -8,6 +8,7 @@ require 'octokit'
|
|
8
8
|
require 'pdksync/constants'
|
9
9
|
require 'json'
|
10
10
|
require 'yaml'
|
11
|
+
require 'colorize'
|
11
12
|
|
12
13
|
# @summary
|
13
14
|
# This module set's out and controls the pdksync process
|
@@ -32,23 +33,107 @@ module PdkSync
|
|
32
33
|
@create_pr_against = Constants::CREATE_PR_AGAINST
|
33
34
|
@managed_modules = Constants::MANAGED_MODULES
|
34
35
|
|
35
|
-
|
36
|
-
# When a new instance of this module is called, this method will be run in order to start the pdksync process.
|
37
|
-
def self.run_pdksync
|
38
|
-
puts 'Beginning pdksync run'
|
36
|
+
def self.main(steps: [:clone], args: nil)
|
39
37
|
create_filespace
|
40
|
-
|
41
|
-
|
38
|
+
client = setup_client
|
39
|
+
module_names = return_modules
|
40
|
+
pr_list = []
|
42
41
|
# The current directory is saved for cleanup purposes
|
43
|
-
|
42
|
+
main_path = Dir.pwd
|
44
43
|
|
45
|
-
#
|
46
|
-
|
47
|
-
|
48
|
-
puts "
|
49
|
-
|
50
|
-
|
51
|
-
|
44
|
+
# validation run_a_command
|
45
|
+
if steps.include?(:run_a_command)
|
46
|
+
raise '"run_a_command" requires an argument to run.' if args.nil?
|
47
|
+
puts "Command '#{args}'"
|
48
|
+
end
|
49
|
+
# validation create_commit
|
50
|
+
if steps.include?(:create_commit)
|
51
|
+
raise 'Needs a branch_name and commit_message' if args.nil? || args[:commit_message].nil? || args[:branch_name].nil?
|
52
|
+
puts "Commit branch_name=#{args[:branch_name]} commit_message=#{args[:commit_message]}"
|
53
|
+
end
|
54
|
+
# validation push_and_create_pr
|
55
|
+
if steps.include?(:push_and_create_pr)
|
56
|
+
raise 'Needs a pr_title' if args.nil? || args[:pr_title].nil?
|
57
|
+
puts "PR title =#{args[:pr_title]}"
|
58
|
+
end
|
59
|
+
# validation clean_branches
|
60
|
+
if steps.include?(:clean_branches)
|
61
|
+
raise 'Needs a branch_name, and the branch name contains the string pdksync' if args.nil? || args[:branch_name].nil? || !args[:branch_name].include?('pdksync')
|
62
|
+
puts "Removing branch_name =#{args[:branch_name]}"
|
63
|
+
end
|
64
|
+
|
65
|
+
abort "No modules listed in #{@managed_modules}" if module_names.nil?
|
66
|
+
module_names.each do |module_name|
|
67
|
+
Dir.chdir(main_path) unless Dir.pwd == main_path
|
68
|
+
print "#{module_name}, "
|
69
|
+
repo_name = "#{@namespace}/#{module_name}"
|
70
|
+
output_path = "#{@pdksync_dir}/#{module_name}"
|
71
|
+
if steps.include?(:clone)
|
72
|
+
clean_env(output_path) if Dir.exist?(output_path)
|
73
|
+
print 'delete module directory, '
|
74
|
+
@git_repo = clone_directory(@namespace, module_name, output_path)
|
75
|
+
print 'cloned, '
|
76
|
+
puts "(WARNING) Unable to clone repo for #{module_name}".red if @git_repo.nil?
|
77
|
+
Dir.chdir(main_path) unless Dir.pwd == main_path
|
78
|
+
next if @git_repo.nil?
|
79
|
+
end
|
80
|
+
puts '(WARNING) @output_path does not exist, skipping module'.red unless File.directory?(output_path)
|
81
|
+
next unless File.directory?(output_path)
|
82
|
+
if steps.include?(:pdk_convert)
|
83
|
+
exit_status = run_command(output_path, "#{return_pdk_path} convert --force --template-url https://github.com/puppetlabs/pdk-templates")
|
84
|
+
print 'converted, '
|
85
|
+
next unless exit_status.zero?
|
86
|
+
end
|
87
|
+
if steps.include?(:pdk_validate)
|
88
|
+
Dir.chdir(main_path) unless Dir.pwd == main_path
|
89
|
+
exit_status = run_command(output_path, "#{return_pdk_path} validate -a")
|
90
|
+
print 'validated, '
|
91
|
+
next unless exit_status.zero?
|
92
|
+
end
|
93
|
+
if steps.include?(:run_a_command)
|
94
|
+
Dir.chdir(main_path) unless Dir.pwd == main_path
|
95
|
+
print 'run command, '
|
96
|
+
exit_status = run_command(output_path, args)
|
97
|
+
next unless exit_status.zero?
|
98
|
+
end
|
99
|
+
if steps.include?(:pdk_update)
|
100
|
+
Dir.chdir(main_path) unless Dir.pwd == main_path
|
101
|
+
next unless pdk_update(output_path).zero?
|
102
|
+
if steps.include?(:use_pdk_ref)
|
103
|
+
ref = return_template_ref
|
104
|
+
args = { branch_name: "pdksync_#{ref}",
|
105
|
+
commit_message: "pdksync_#{ref}",
|
106
|
+
pr_title: "pdksync_#{ref}" }
|
107
|
+
end
|
108
|
+
print 'pdk update, '
|
109
|
+
end
|
110
|
+
if steps.include?(:create_commit)
|
111
|
+
Dir.chdir(main_path) unless Dir.pwd == main_path
|
112
|
+
git_instance = Git.open(output_path)
|
113
|
+
create_commit(git_instance, args[:branch_name], args[:commit_message])
|
114
|
+
print 'commit created, '
|
115
|
+
end
|
116
|
+
if steps.include?(:push_and_create_pr)
|
117
|
+
Dir.chdir(main_path) unless Dir.pwd == main_path
|
118
|
+
git_instance = Git.open(output_path)
|
119
|
+
push_staged_files(git_instance, git_instance.current_branch, repo_name)
|
120
|
+
print 'push, '
|
121
|
+
pdk_version = return_pdk_version("#{output_path}/metadata.json")
|
122
|
+
pr = create_pr(client, repo_name, git_instance.current_branch, pdk_version, args[:pr_title])
|
123
|
+
pr_list.push(pr.html_url)
|
124
|
+
print 'created pr, '
|
125
|
+
end
|
126
|
+
if steps.include?(:clean_branches)
|
127
|
+
Dir.chdir(main_path) unless Dir.pwd == main_path
|
128
|
+
delete_branch(client, repo_name, args[:branch_name])
|
129
|
+
print 'branch deleted, '
|
130
|
+
end
|
131
|
+
puts 'done.'.green
|
132
|
+
end
|
133
|
+
return if pr_list.size.zero?
|
134
|
+
puts "\nPRs created:\n".blue
|
135
|
+
pr_list.each do |pr|
|
136
|
+
puts pr
|
52
137
|
end
|
53
138
|
end
|
54
139
|
|
@@ -65,9 +150,8 @@ module PdkSync
|
|
65
150
|
def self.setup_client
|
66
151
|
client = Octokit::Client.new(access_token: @access_token.to_s)
|
67
152
|
client.user.login
|
68
|
-
puts 'Client login has been successful.'
|
69
153
|
client
|
70
|
-
rescue ArgumentError
|
154
|
+
rescue ArgumentError, Octokit::Unauthorized
|
71
155
|
raise "Access Token not set up correctly - Use export 'GITHUB_TOKEN=<put your token here>' to set it."
|
72
156
|
end
|
73
157
|
|
@@ -80,29 +164,24 @@ module PdkSync
|
|
80
164
|
end
|
81
165
|
|
82
166
|
# @summary
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
return if @git_repo.nil?
|
97
|
-
return unless pdk_update(@output_path) == 0 # rubocop:disable Style/NumericPredicate
|
167
|
+
# Try to use a fully installed pdk, otherwise fall back to the bundled pdk gem.
|
168
|
+
# @return String
|
169
|
+
# Path to the pdk executable
|
170
|
+
def self.return_pdk_path
|
171
|
+
full_path = '/opt/puppetlabs/pdk/bin/pdk'
|
172
|
+
path = if File.executable?(full_path)
|
173
|
+
full_path
|
174
|
+
else
|
175
|
+
puts "(WARNING) Using pdk on PATH not '#{full_path}'".red
|
176
|
+
'pdk'
|
177
|
+
end
|
178
|
+
path
|
179
|
+
end
|
98
180
|
|
99
|
-
|
100
|
-
checkout_branch(
|
101
|
-
|
102
|
-
|
103
|
-
commit_staged_files(@git_repo, @template_ref)
|
104
|
-
push_staged_files(@git_repo, @template_ref, @repo_name)
|
105
|
-
create_pr(client, @repo_name, @template_ref, @pdk_version)
|
181
|
+
def self.create_commit(git_repo, branch_name, commit_message)
|
182
|
+
checkout_branch(git_repo, branch_name)
|
183
|
+
add_staged_files(git_repo)
|
184
|
+
commit_staged_files(git_repo, branch_name, commit_message)
|
106
185
|
end
|
107
186
|
|
108
187
|
# @summary
|
@@ -110,7 +189,6 @@ module PdkSync
|
|
110
189
|
# @param [String] output_path
|
111
190
|
# The repository that is to be deleted.
|
112
191
|
def self.clean_env(output_path)
|
113
|
-
puts 'Cleaning your environment.'
|
114
192
|
# If a local copy already exists it is removed
|
115
193
|
FileUtils.rm_rf(output_path)
|
116
194
|
end
|
@@ -126,27 +204,25 @@ module PdkSync
|
|
126
204
|
# @return [Git::Base]
|
127
205
|
# A git object representing the local repository.
|
128
206
|
def self.clone_directory(namespace, module_name, output_path)
|
129
|
-
puts "Cloning #{module_name} to #{output_path}."
|
130
207
|
Git.clone("https://github.com/#{namespace}/#{module_name}.git", output_path.to_s) # is returned
|
131
|
-
rescue Git::GitExecuteError
|
132
|
-
puts "(FAILURE) Cloning #{module_name} has failed
|
208
|
+
rescue Git::GitExecuteError => error
|
209
|
+
puts "(FAILURE) Cloning #{module_name} has failed. #{error}".red
|
133
210
|
end
|
134
211
|
|
135
212
|
# @summary
|
136
|
-
# This method when called will run
|
213
|
+
# This method when called will run a command command at the given location, with an error message being thrown if it is not successful.
|
137
214
|
# @param [String] output_path
|
138
215
|
# The location that the command is to be run from.
|
216
|
+
# @param [String] command
|
217
|
+
# The command to be run.
|
139
218
|
# @return [Integer]
|
140
|
-
# The status code of the
|
141
|
-
def self.
|
219
|
+
# The status code of the command run.
|
220
|
+
def self.run_command(output_path, command)
|
142
221
|
Dir.chdir(output_path) unless Dir.pwd == output_path
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
puts 'PDK convert has run.'
|
148
|
-
end
|
149
|
-
status
|
222
|
+
stdout, stderr, status = Open3.capture3(command)
|
223
|
+
puts "\n#{stdout}\n".yellow
|
224
|
+
puts "(FAILURE) Unable to run command '#{command}': #{stderr}".red unless status.exitstatus.zero?
|
225
|
+
status.exitstatus
|
150
226
|
end
|
151
227
|
|
152
228
|
# @summary
|
@@ -158,31 +234,9 @@ module PdkSync
|
|
158
234
|
def self.pdk_update(output_path)
|
159
235
|
# Runs the pdk update command
|
160
236
|
Dir.chdir(output_path) unless Dir.pwd == output_path
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
else
|
165
|
-
puts 'PDK update has run.'
|
166
|
-
end
|
167
|
-
return status unless status == 0 && stdout.include?('No changes required.') # rubocop:disable Style/NumericPredicate
|
168
|
-
puts 'No commits since last run.'
|
169
|
-
end
|
170
|
-
|
171
|
-
# @summary
|
172
|
-
# This method when called will run the 'pdk validate -a' command at the given location, with an error message being thrown if it is not successful.
|
173
|
-
# @param [String] output_path
|
174
|
-
# The location that the command is to be run from.
|
175
|
-
# @return [Integer]
|
176
|
-
# The status code of the pdk validate run.
|
177
|
-
def self.validate_autofix
|
178
|
-
# Runs the pdk validate command
|
179
|
-
_stdout, stderr, status = Open3.capture3('pdk validate -a')
|
180
|
-
if status != 0
|
181
|
-
puts "(FAILURE) Something went wrong with the validate: #{stderr}"
|
182
|
-
else
|
183
|
-
puts 'Validate has run successfully.'
|
184
|
-
end
|
185
|
-
status
|
237
|
+
_stdout, stderr, status = Open3.capture3("#{return_pdk_path} update --force")
|
238
|
+
puts "(FAILURE) Unable to run `pdk update`: #{stderr}".red unless status.exitstatus.zero?
|
239
|
+
status.exitstatus
|
186
240
|
end
|
187
241
|
|
188
242
|
# @summary
|
@@ -201,11 +255,10 @@ module PdkSync
|
|
201
255
|
# This method when called will checkout a new local branch of the given repository.
|
202
256
|
# @param [Git::Base] git_repo
|
203
257
|
# A git object representing the local repository to be branched.
|
204
|
-
# @param [String]
|
205
|
-
# The
|
206
|
-
def self.checkout_branch(git_repo,
|
207
|
-
|
208
|
-
git_repo.branch("pdksync_#{template_ref}".to_s).checkout
|
258
|
+
# @param [String] branch_suffix
|
259
|
+
# The string that is appended on the branch name. eg template_ref or a friendly name
|
260
|
+
def self.checkout_branch(git_repo, branch_suffix)
|
261
|
+
git_repo.branch("pdksync_#{branch_suffix}").checkout
|
209
262
|
end
|
210
263
|
|
211
264
|
# @summary
|
@@ -225,8 +278,12 @@ module PdkSync
|
|
225
278
|
# @param [Git::Base] git_repo
|
226
279
|
# A git object representing the local repository to be staged.
|
227
280
|
def self.add_staged_files(git_repo)
|
228
|
-
git_repo.
|
229
|
-
|
281
|
+
if git_repo.status.changed != {}
|
282
|
+
git_repo.add(all: true)
|
283
|
+
puts 'All files have been staged.'
|
284
|
+
else
|
285
|
+
puts 'Nothing to commit.'
|
286
|
+
end
|
230
287
|
end
|
231
288
|
|
232
289
|
# @summary
|
@@ -235,9 +292,15 @@ module PdkSync
|
|
235
292
|
# A git object representing the local repository against which the commit is to be made.
|
236
293
|
# @param [String] template_ref
|
237
294
|
# The unique template_ref that is used as part of the commit name.
|
238
|
-
|
239
|
-
|
240
|
-
|
295
|
+
# @param [String] commit_message
|
296
|
+
# If sepecified it will be the message for the commit.
|
297
|
+
def self.commit_staged_files(git_repo, template_ref, commit_message = nil)
|
298
|
+
message = if commit_message.nil?
|
299
|
+
"pdksync_#{template_ref}"
|
300
|
+
else
|
301
|
+
commit_message
|
302
|
+
end
|
303
|
+
git_repo.commit(message)
|
241
304
|
end
|
242
305
|
|
243
306
|
# @summary
|
@@ -248,11 +311,10 @@ module PdkSync
|
|
248
311
|
# The unique reference that that represents the template the update has ran against.
|
249
312
|
# @param [String] repo_name
|
250
313
|
# The name of the repository on which the commit is to be made.
|
251
|
-
def self.push_staged_files(git_repo,
|
252
|
-
git_repo.push(@push_file_destination,
|
253
|
-
|
254
|
-
|
255
|
-
puts "(FAILURE) Pushing to #{@push_file_destination} for #{repo_name} has failed."
|
314
|
+
def self.push_staged_files(git_repo, current_branch, repo_name)
|
315
|
+
git_repo.push(@push_file_destination, current_branch)
|
316
|
+
rescue StandardError => error
|
317
|
+
puts "(FAILURE) Pushing to #{@push_file_destination} for #{repo_name} has failed. #{error}".red
|
256
318
|
end
|
257
319
|
|
258
320
|
# @summary
|
@@ -265,46 +327,23 @@ module PdkSync
|
|
265
327
|
# The unique reference that that represents the template the update has ran against.
|
266
328
|
# @param [String] pdk_version
|
267
329
|
# The current version of the pdk on which the update is run.
|
268
|
-
def self.create_pr(client, repo_name, template_ref, pdk_version)
|
330
|
+
def self.create_pr(client, repo_name, template_ref, pdk_version, pr_title = nil)
|
331
|
+
if pr_title.nil?
|
332
|
+
title = "pdksync - Update using #{pdk_version}"
|
333
|
+
message = "pdk version: `#{pdk_version}` \n pdk template ref: `#{template_ref}`"
|
334
|
+
head = "pdksync_#{template_ref}"
|
335
|
+
else
|
336
|
+
title = "pdksync - #{pr_title}"
|
337
|
+
message = "#{pr_title}\npdk version: `#{pdk_version}` \n"
|
338
|
+
head = template_ref
|
339
|
+
end
|
269
340
|
pr = client.create_pull_request(repo_name, @create_pr_against,
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
puts 'The PR has been created.'
|
341
|
+
head,
|
342
|
+
title,
|
343
|
+
message)
|
274
344
|
pr
|
275
|
-
rescue StandardError
|
276
|
-
puts "(FAILURE) PR creation for #{repo_name} has failed."
|
277
|
-
end
|
278
|
-
|
279
|
-
# @summary
|
280
|
-
# This method when called will retrieve a list of module names and then proceed to iterate
|
281
|
-
# through them, removing any branch that contains the word 'pdksync'.
|
282
|
-
def self.clean_branches
|
283
|
-
puts 'Beginning pdksync cleanup run'
|
284
|
-
@client = setup_client
|
285
|
-
@module_names = return_modules
|
286
|
-
|
287
|
-
@module_names.each do |module_name|
|
288
|
-
puts '*************************************'
|
289
|
-
puts "Cleaning #{module_name}"
|
290
|
-
@repo_name = "#{@namespace}/#{module_name}"
|
291
|
-
retrieve_branches(@client, @repo_name).each do |branch|
|
292
|
-
delete_branch(@client, @repo_name, branch.name) if branch.name.include? 'pdksync'
|
293
|
-
end
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
# @summary
|
298
|
-
# This method when called will retrieve any and all branches from the given repository.
|
299
|
-
# @param [Octokit::Client] client
|
300
|
-
# The octokit client used to gain access to and manipulate the repository.
|
301
|
-
# @param [String] repo_name
|
302
|
-
# The name of the repository from which the branches are to be retrieved.
|
303
|
-
# @return [Array]
|
304
|
-
# An array containing all existing branches
|
305
|
-
def self.retrieve_branches(client, repo_name)
|
306
|
-
puts "Retrieving branches from #{repo_name}"
|
307
|
-
client.branches(repo_name)
|
345
|
+
rescue StandardError => error
|
346
|
+
puts "(FAILURE) PR creation for #{repo_name} has failed. #{error}".red
|
308
347
|
end
|
309
348
|
|
310
349
|
# @summary
|
@@ -316,7 +355,8 @@ module PdkSync
|
|
316
355
|
# @param [String] branch_name
|
317
356
|
# The name of the branch that is to be deleted.
|
318
357
|
def self.delete_branch(client, repo_name, branch_name)
|
319
|
-
puts "Removing '#{branch_name}' from '#{repo_name}'"
|
320
358
|
client.delete_branch(repo_name, branch_name)
|
359
|
+
rescue StandardError => error
|
360
|
+
puts "(FAILURE) Deleting #{branch_name} in #{repo_name} failed. #{error}".red
|
321
361
|
end
|
322
362
|
end
|
data/managed_modules.yml
CHANGED
@@ -1,30 +1,55 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
2
|
+
## windows team
|
3
|
+
#- puppetlabs-acl
|
4
|
+
#- puppetlabs-chocolatey
|
5
|
+
#- puppetlabs-dsc
|
6
|
+
#- puppetlabs-dsc_lite
|
7
|
+
#- puppetlabs-iis
|
8
|
+
#- puppetlabs-powershell
|
9
|
+
#- puppetlabs-registry
|
10
|
+
#- puppetlabs-reboot
|
11
|
+
#- puppetlabs-scheduled_task
|
12
|
+
#- puppetlabs-sqlserver
|
13
|
+
#- puppetlabs-windows
|
14
|
+
#- puppetlabs-wsus_client
|
15
|
+
## modules team
|
16
|
+
#- puppetlabs-accounts
|
17
|
+
#- puppetlabs-apache
|
18
|
+
#- puppetlabs-apt
|
19
|
+
#- puppetlabs-bootstrap
|
20
|
+
#- puppetlabs-concat
|
21
|
+
#- puppetlabs-exec
|
22
|
+
#- puppetlabs-facter_task
|
23
|
+
#- puppetlabs-firewall
|
24
|
+
#- puppetlabs-haproxy
|
25
|
+
#- puppetlabs-ibm_installation_manager
|
26
|
+
#- puppetlabs-inifile
|
27
|
+
#- puppetlabs-java
|
28
|
+
#- puppetlabs-java_ks
|
29
|
+
#- puppetlabs-motd
|
30
|
+
#- puppetlabs-mysql
|
31
|
+
#- puppetlabs-ntp
|
32
|
+
#- puppetlabs-package
|
33
|
+
#- puppetlabs-postgresql
|
34
|
+
#- puppetlabs-puppet_conf
|
35
|
+
#- puppetlabs-resource
|
36
|
+
#- puppetlabs-satellite_pe_tools
|
37
|
+
#- puppetlabs-service
|
38
|
+
#- puppetlabs-stdlib
|
39
|
+
#- puppetlabs-tagmail
|
40
|
+
#- puppetlabs-tomcat
|
41
|
+
#- puppetlabs-translate
|
42
|
+
#- puppetlabs-vcsrepo
|
43
|
+
#- puppetlabs-websphere_application_server
|
44
|
+
# networking team
|
45
|
+
#- cisco_ios
|
46
|
+
#- device_manager
|
47
|
+
#- puppetlabs-panos
|
48
|
+
#- puppetlabs-resource_api
|
49
|
+
## testing only
|
50
|
+
# - puppetlabs-testing
|
51
|
+
# - puppetlabs-testing1
|
52
|
+
# - puppetlabs-testing2
|
53
|
+
## cloud and containers team
|
54
|
+
# - puppetlabs-kubernetes
|
55
|
+
# - puppetlabs-rook
|
data/pdksync.gemspec
CHANGED
data/spec/lib/pdksync_spec.rb
CHANGED
@@ -5,64 +5,50 @@ require 'octokit'
|
|
5
5
|
|
6
6
|
describe PdkSync do
|
7
7
|
before(:all) do
|
8
|
-
@timestamp = Time.now.to_i
|
9
|
-
@namespace = 'puppetlabs'
|
10
8
|
@pdksync_dir = './modules_pdksync'
|
11
|
-
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
9
|
+
module_name = 'puppetlabs-testing'
|
10
|
+
@module_names = ['puppetlabs-testing']
|
11
|
+
@output_path = "#{@pdksync_dir}/#{module_name}"
|
12
|
+
@folder = Dir.pwd
|
15
13
|
end
|
16
14
|
|
17
|
-
|
18
|
-
|
15
|
+
before(:each) do
|
16
|
+
allow(PdkSync).to receive(:return_modules).and_return(@module_names)
|
17
|
+
Dir.chdir(@folder)
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'main method' do
|
21
|
+
it 'runs clone sucessfully' do
|
19
22
|
FileUtils.rm_rf(@pdksync_dir)
|
20
23
|
PdkSync.create_filespace
|
24
|
+
PdkSync.main(steps: [:clone])
|
21
25
|
expect(Dir.exist?(@pdksync_dir)).to be(true)
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'has cloned the repo' do
|
25
|
-
PdkSync.clone_directory(@namespace, @module_name, @output_path)
|
26
26
|
expect(Dir.exist?(@output_path)).to be(true)
|
27
27
|
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
before(:all) do
|
32
|
-
@git_repo = Git.open(@output_path)
|
28
|
+
it 'runs pdk convert, and files have changed' do
|
29
|
+
PdkSync.main(steps: [:pdk_convert])
|
30
|
+
File.exist?("#{@output_path}/convert_report.txt")
|
33
31
|
end
|
34
|
-
|
35
|
-
|
36
|
-
PdkSync.checkout_branch(@git_repo, @timestamp)
|
37
|
-
expect(@git_repo.current_branch).to include(@timestamp.to_s)
|
32
|
+
it 'raise when running a command with no argument' do
|
33
|
+
expect { PdkSync.main(steps: [:run_a_command]) }.to raise_error(RuntimeError, %r{"run_a_command" requires an argument to run.})
|
38
34
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
PdkSync.pdk_update(@output_path)
|
43
|
-
expect(File.exist?('update_report.txt')).to be(true)
|
35
|
+
it 'runs a command "touch cat.meow"' do
|
36
|
+
PdkSync.main(steps: [:run_a_command], args: 'touch cat.meow')
|
37
|
+
expect File.exist?("#{@output_path}/cat.meow")
|
44
38
|
end
|
45
|
-
|
46
|
-
|
47
|
-
PdkSync.add_staged_files(@git_repo)
|
48
|
-
result = Open3.capture3('git status')
|
49
|
-
expect(result).to include(%r{Changes to be committed})
|
39
|
+
it 'raise when create_commit with no arguments' do
|
40
|
+
expect { PdkSync.main(steps: [:create_commit]) }.to raise_error(RuntimeError, %r{Needs a branch_name and commit_message})
|
50
41
|
end
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
42
|
+
it 'create_commit runs, and contains the "kittens in mittens"' do
|
43
|
+
PdkSync.main(steps: [:create_commit], args: { branch_name: 'temp_branch', commit_message: 'kittens in mittens' })
|
44
|
+
git_repo = Git.open(@output_path)
|
45
|
+
expect(git_repo.show).to include('kittens in mittens')
|
46
|
+
end
|
47
|
+
it 'raise when push_and_create_pr with no arguments' do
|
48
|
+
expect { PdkSync.main(steps: [:push_and_create_pr]) }.to raise_error(RuntimeError, %r{Needs a pr_title})
|
49
|
+
end
|
50
|
+
it 'raise when clean_branches with no arguments' do
|
51
|
+
expect { PdkSync.main(steps: [:clean_branches]) }.to raise_error(RuntimeError, %r{Needs a branch_name, and the branch name contains the string pdksync})
|
57
52
|
end
|
58
53
|
end
|
59
|
-
# # Test fails if ran from travis due to lack of proper credentials
|
60
|
-
# it 'The committed files should be pushed and the PR created', unless: @access_token == '' do
|
61
|
-
# @client = PdkSync.setup_client
|
62
|
-
# PdkSync.push_staged_files(@git_repo, @timestamp, @repo_name)
|
63
|
-
# pr = PdkSync.create_pr(@client, @repo_name, @timestamp, @timstamp)
|
64
|
-
# expect(pr.title).to eq("pdksync - pdksync_#{@timestamp}")
|
65
|
-
# #Branch is now cleaned
|
66
|
-
# PdkSync.delete_branch(@client, @repo_name, "pdksync_#{@timestamp}".to_s)
|
67
|
-
# end
|
68
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdksync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -130,6 +130,7 @@ extensions: []
|
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
132
|
- ".gitignore"
|
133
|
+
- ".rspec"
|
133
134
|
- ".rubocop.yml"
|
134
135
|
- ".rubocop_todo.yml"
|
135
136
|
- ".travis.yml"
|
@@ -163,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
164
|
version: '0'
|
164
165
|
requirements: []
|
165
166
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.6
|
167
|
+
rubygems_version: 2.7.6
|
167
168
|
signing_key:
|
168
169
|
specification_version: 4
|
169
170
|
summary: Puppet Module PDK Synchronizer
|