modulesync 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2442835e7b5da17cc633790e9e4a2a3fe38c0a1b4d3fbd75ee8f60b6948ddc75
4
- data.tar.gz: 0f0c8f284f95824e469759582db8188b37c8c8d7247f463dc9877e973887fcac
3
+ metadata.gz: 7fb5357d0ecf1e4f620be302b55c9f1e88779c446021097172866c87a1e57d8f
4
+ data.tar.gz: be3975ae4dbe2a4e6a32cc5851bc0e9ce8ac8dd0b9560175380f492e43dabe27
5
5
  SHA512:
6
- metadata.gz: 521392847ed7f191f9ef9bb6a0c26d80fb7c557b882f092bec29834311af6c10a2e0bd5db2d1be162996fbfbcccfd5f9ac1063268b6480aa95c867802e9b48b3
7
- data.tar.gz: b3ddc00ba28e2d5043cb0e24d3448c35ca84f3d42a4263de4efa8513f7c38d02ca2324289a2b15d2a5c84435a3329de76acccfae8da2da6f1df31d60553cdc77
6
+ metadata.gz: 15051bcc97f904d9d886e67abf9e6ea99818410ec3f330f7d67ed9cc86451f322b79861801218f46b534a0f3241f3aa15dc16928360c471c0742e0b8f3c120f7
7
+ data.tar.gz: d527c5e7eeeccfabdbd5eb328759b826873aea33f12419179a89f84a1499af784788de9ca420eab8cbc5d2d83fdf1a9a8f6bbde1c536b25aca9c35b21c77c40b
@@ -19,7 +19,7 @@ Metrics/AbcSize:
19
19
  # Offense count: 1
20
20
  # Configuration parameters: CountComments.
21
21
  Metrics/ClassLength:
22
- Max: 105
22
+ Max: 107
23
23
 
24
24
  # Offense count: 4
25
25
  Metrics/CyclomaticComplexity:
@@ -1,8 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 2020-07-03 - 1.3.0
4
+
5
+ * Expose --managed_modules_conf [#184](https://github.com/voxpupuli/modulesync/pull/184)
6
+ * Allow absolute path for config files [#183](https://github.com/voxpupuli/modulesync/pull/183)
7
+ * Add pr_target_branch option [#182](https://github.com/voxpupuli/modulesync/pull/182)
8
+ * Allow to specify namespace in module_options [#181](https://github.com/voxpupuli/modulesync/pull/181)
9
+ * Allow to override PR parameters per module [#178](https://github.com/voxpupuli/modulesync/pull/178)
10
+ * Include the gitlab library (if we interact with gitlab), not github [#179](https://github.com/voxpupuli/modulesync/pull/179)
11
+
3
12
  ## 2020-07-03 - 1.2.0
4
13
 
5
- Add support for GitLab merge requests (MRs) [#175](https://github.com/voxpupuli/modulesync/pull/175)
14
+ * Add support for GitLab merge requests (MRs) [#175](https://github.com/voxpupuli/modulesync/pull/175)
6
15
 
7
16
  ## 2020-05-01 - 1.1.0
8
17
 
data/README.md CHANGED
@@ -185,17 +185,38 @@ GitLab automatically with the `--pr` CLI option.
185
185
  msync update --pr
186
186
  ```
187
187
 
188
- You must set the `GITHUB_TOKEN` or `GITLAB_TOKEN` environment variable
189
- for GitHub PRs or GitLab MRs to work. Additional options:
188
+ In order for GitHub PRs or GitLab MRs to work, you must either provide
189
+ the `GITHUB_TOKEN` or `GITLAB_TOKEN` environment variables,
190
+ or set them per repository in `managed_modules.yml`, using the `github` or
191
+ `gitlab` keys respectively.
192
+
193
+ For GitHub Enterprise and self-hosted GitLab instances you also need to set the
194
+ `GITHUB_BASE_URL` or `GITLAB_BASE_URL` environment variables, or use the
195
+ `base_url` parameter in `managed_modules.yml`:
196
+
197
+ ```yaml
198
+ ---
199
+ repo1:
200
+ :github:
201
+ :token: 'EXAMPLE_TOKEN'
202
+ :base_url: 'https://api.github.com/'
203
+
204
+ repo2:
205
+ :gitlab:
206
+ :token: 'EXAMPLE_TOKEN'
207
+ :base_url: 'https://git.example.com/api/v4'
208
+ ```
209
+
210
+ Then:
190
211
 
191
212
  * Set the PR/MR title with `--pr-title` or in `modulesync.yml` with the
192
213
  `pr_title` attribute.
193
214
  * Assign labels to the PR/MR with `--pr-labels` or in `modulesync.yml` with
194
215
  the `pr_labels` attribute. **NOTE:** `pr_labels` should be a list. When
195
216
  using the `--pr-labels` CLI option, you should use a comma separated list.
217
+ * Set the target branch with `--pr_target_branch` or in `modulesync.yml` with
218
+ the `pr_target_branch` attribute.
196
219
 
197
- For GitHub Enterprise and self-hosted GitLab instances you need to set the
198
- `GITHUB_BASE_URL` or `GITLAB_BASE_URL` environment variable in addition.
199
220
  More details for GitHub:
200
221
 
201
222
  * Octokit [`api_endpoint`](https://github.com/octokit/octokit.rb#interacting-with-the-githubcom-apis-in-github-enterprise)
@@ -255,7 +276,9 @@ msync update -m "Commit message"
255
276
  Available parameters for modulesync.yml
256
277
 
257
278
  * `git_base` : The default URL to git clone from (Default: 'git@github.com:')
258
- * `namespace` : Namespace of the projects to manage (Default: 'puppetlabs')
279
+ * `namespace` : Namespace of the projects to manage (Default: 'puppetlabs').
280
+ This value can be overridden in the module name (e.g. 'namespace/mod') or by
281
+ using the `namespace` key for the module in `managed_modules.yml`.
259
282
  * `branch` : Branch to push to (Default: 'master')
260
283
  * `remote_branch` : Remote branch to push to (Default: Same value as branch)
261
284
  * `message` : Commit message to apply to updated modules.
@@ -105,7 +105,11 @@ module ModuleSync # rubocop:disable Metrics/ModuleLength
105
105
  end
106
106
 
107
107
  def self.manage_module(puppet_module, module_files, module_options, defaults, options)
108
- namespace, module_name = module_name(puppet_module, options[:namespace])
108
+ default_namespace = options[:namespace]
109
+ if module_options.is_a?(Hash) && module_options.key?(:namespace)
110
+ default_namespace = module_options[:namespace]
111
+ end
112
+ namespace, module_name = module_name(puppet_module, default_namespace)
109
113
  git_repo = File.join(namespace, module_name)
110
114
  unless options[:offline]
111
115
  Git.pull(options[:git_base], git_repo, options[:branch], options[:project_root], module_options || {})
@@ -130,13 +134,22 @@ module ModuleSync # rubocop:disable Metrics/ModuleLength
130
134
  Git.update_noop(git_repo, options)
131
135
  elsif !options[:offline]
132
136
  pushed = Git.update(git_repo, files_to_manage, options)
133
- pushed && options[:pr] && @pr.manage(namespace, module_name, options)
137
+ pushed && options[:pr] && pr(module_options).manage(namespace, module_name, options)
134
138
  end
135
139
  end
136
140
 
141
+ def self.config_path(file, options)
142
+ return file if Pathname.new(file).absolute?
143
+ File.join(options[:configs], file)
144
+ end
145
+
146
+ def config_path(file, options)
147
+ self.class.config_path(file, options)
148
+ end
149
+
137
150
  def self.update(options)
138
151
  options = config_defaults.merge(options)
139
- defaults = Util.parse_config(File.join(options[:configs], CONF_FILE))
152
+ defaults = Util.parse_config(config_path(CONF_FILE, options))
140
153
  if options[:pr]
141
154
  unless options[:branch]
142
155
  $stderr.puts 'A branch must be specified with --branch to use --pr!'
@@ -146,11 +159,11 @@ module ModuleSync # rubocop:disable Metrics/ModuleLength
146
159
  @pr = create_pr_manager if options[:pr]
147
160
  end
148
161
 
149
- local_template_dir = File.join(options[:configs], MODULE_FILES_DIR)
162
+ local_template_dir = config_path(MODULE_FILES_DIR, options)
150
163
  local_files = find_template_files(local_template_dir)
151
164
  module_files = relative_names(local_files, local_template_dir)
152
165
 
153
- managed_modules = self.managed_modules(File.join(options[:configs], options[:managed_modules_conf]),
166
+ managed_modules = self.managed_modules(config_path(options[:managed_modules_conf], options),
154
167
  options[:filter],
155
168
  options[:negative_filter])
156
169
 
@@ -169,6 +182,26 @@ module ModuleSync # rubocop:disable Metrics/ModuleLength
169
182
  exit 1 if errors && options[:fail_on_warnings]
170
183
  end
171
184
 
185
+ def self.pr(module_options)
186
+ github_conf = module_options[:github]
187
+ gitlab_conf = module_options[:gitlab]
188
+
189
+ if !github_conf.nil?
190
+ base_url = github_conf[:base_url] || ENV.fetch('GITHUB_BASE_URL', 'https://api.github.com')
191
+ require 'modulesync/pr/github'
192
+ ModuleSync::PR::GitHub.new(github_conf[:token], base_url)
193
+ elsif !gitlab_conf.nil?
194
+ base_url = gitlab_conf[:base_url] || ENV.fetch('GITLAB_BASE_URL', 'https://gitlab.com/api/v4')
195
+ require 'modulesync/pr/gitlab'
196
+ ModuleSync::PR::GitLab.new(gitlab_conf[:token], base_url)
197
+ elsif @pr.nil?
198
+ $stderr.puts 'No GitHub or GitLab token specified for --pr!'
199
+ raise
200
+ else
201
+ @pr
202
+ end
203
+ end
204
+
172
205
  def self.create_pr_manager
173
206
  github_token = ENV.fetch('GITHUB_TOKEN', '')
174
207
  gitlab_token = ENV.fetch('GITLAB_TOKEN', '')
@@ -177,11 +210,10 @@ module ModuleSync # rubocop:disable Metrics/ModuleLength
177
210
  require 'modulesync/pr/github'
178
211
  ModuleSync::PR::GitHub.new(github_token, ENV.fetch('GITHUB_BASE_URL', 'https://api.github.com'))
179
212
  elsif !gitlab_token.empty?
180
- require 'modulesync/pr/github'
213
+ require 'modulesync/pr/gitlab'
181
214
  ModuleSync::PR::GitLab.new(gitlab_token, ENV.fetch('GITLAB_BASE_URL', 'https://gitlab.com/api/v4'))
182
215
  else
183
- $stderr.puts 'Environment variables GITHUB_TOKEN or GITLAB_TOKEN must be set to use --pr!'
184
- raise
216
+ warn '--pr specified without environment variables GITHUB_TOKEN or GITLAB_TOKEN'
185
217
  end
186
218
  end
187
219
  end
@@ -67,6 +67,8 @@ module ModuleSync
67
67
  :aliases => '-c',
68
68
  :desc => 'The local directory or remote repository to define the list of managed modules,' \
69
69
  ' the file templates, and the default values for template variables.'
70
+ option :managed_modules_conf,
71
+ :desc => 'The file name to define the list of managed modules'
70
72
  option :remote_branch,
71
73
  :aliases => '-r',
72
74
  :desc => 'Remote branch name to push the changes to. Defaults to the branch name.',
@@ -99,6 +101,9 @@ module ModuleSync
99
101
  :type => :array,
100
102
  :desc => 'Labels to add to the pull/merge request',
101
103
  :default => CLI.defaults[:pr_labels] || []
104
+ option :pr_target_branch,
105
+ :desc => 'Target branch for the pull/merge request',
106
+ :default => CLI.defaults[:pr_target_branch] || 'master'
102
107
  option :offline,
103
108
  :type => :boolean,
104
109
  :desc => 'Do not run any Git commands. Allows the user to manage Git outside of ModuleSync.',
@@ -16,11 +16,17 @@ module ModuleSync
16
16
  def manage(namespace, module_name, options)
17
17
  repo_path = File.join(namespace, module_name)
18
18
  head = "#{namespace}:#{options[:branch]}"
19
+ target_branch = options[:pr_target_branch] || 'master'
19
20
 
20
- pull_requests = @api.pull_requests(repo_path, :state => 'open', :base => 'master', :head => head)
21
+ pull_requests = @api.pull_requests(repo_path, :state => 'open', :base => target_branch, :head => head)
21
22
  if pull_requests.empty?
22
- pr = @api.create_pull_request(repo_path, 'master', options[:branch], options[:pr_title], options[:message])
23
- $stdout.puts "Submitted PR '#{options[:pr_title]}' to #{repo_path} - merges #{options[:branch]} into master"
23
+ pr = @api.create_pull_request(repo_path,
24
+ target_branch,
25
+ options[:branch],
26
+ options[:pr_title],
27
+ options[:message])
28
+ $stdout.puts \
29
+ "Submitted PR '#{options[:pr_title]}' to #{repo_path} - merges #{options[:branch]} into #{target_branch}"
24
30
  else
25
31
  # Skip creating the PR if it exists already.
26
32
  $stdout.puts "Skipped! #{pull_requests.length} PRs found for branch #{options[:branch]}"
@@ -17,17 +17,19 @@ module ModuleSync
17
17
  repo_path = File.join(namespace, module_name)
18
18
 
19
19
  head = "#{namespace}:#{options[:branch]}"
20
+ target_branch = options[:pr_target_branch] || 'master'
20
21
  merge_requests = @api.merge_requests(repo_path,
21
22
  :state => 'opened',
22
23
  :source_branch => head,
23
- :target_branch => 'master')
24
+ :target_branch => target_branch)
24
25
  if merge_requests.empty?
25
26
  mr_labels = ModuleSync::Util.parse_list(options[:pr_labels])
26
27
  mr = @api.create_merge_request(repo_path, options[:pr_title],
27
28
  :source_branch => options[:branch],
28
- :target_branch => 'master',
29
+ :target_branch => target_branch,
29
30
  :labels => mr_labels)
30
- $stdout.puts "Submitted MR '#{options[:pr_title]}' to #{repo_path} - merges #{options[:branch]} into master"
31
+ $stdout.puts \
32
+ "Submitted MR '#{options[:pr_title]}' to #{repo_path} - merges #{options[:branch]} into #{target_branch}"
31
33
  return if mr_labels.empty?
32
34
  $stdout.puts "Attached the following labels to MR #{mr.iid}: #{mr_labels.join(', ')}"
33
35
  else
@@ -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 = '1.2.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'
@@ -12,10 +12,10 @@ describe ModuleSync do
12
12
  end
13
13
  end
14
14
 
15
- context '::create_pr_manager' do
15
+ context '::pr' do
16
16
  describe "Raise Error" do
17
17
  it 'raises an error when neither GITHUB_TOKEN nor GITLAB_TOKEN are set for PRs' do
18
- expect { ModuleSync.create_pr_manager() }.to raise_error(RuntimeError).and output(/GITHUB_TOKEN/).to_stderr
18
+ expect { ModuleSync.pr({}) }.to raise_error(RuntimeError).and output(/No GitHub or GitLab token specified for --pr/).to_stderr
19
19
  end
20
20
  end
21
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modulesync
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.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: 2020-07-03 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