modulesync 4.2.0 → 4.4.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/.github/labeler.yml +5 -0
- data/.github/workflows/ci.yml +5 -5
- data/.github/workflows/labeler.yml +17 -0
- data/.github/workflows/release.yml +9 -9
- data/CHANGELOG.md +30 -0
- data/README.md +2 -2
- data/features/update/pull_request.feature +1 -1
- data/lib/modulesync/git_service/github.rb +7 -0
- data/lib/modulesync/repository.rb +10 -0
- data/lib/modulesync/source_code.rb +20 -2
- data/lib/modulesync/version.rb +5 -0
- data/lib/modulesync.rb +10 -5
- data/modulesync.gemspec +4 -5
- data/spec/unit/module_sync/git_service/github_spec.rb +12 -0
- data/spec/unit/module_sync/repository_spec.rb +36 -0
- data/spec/unit/module_sync/source_code_spec.rb +10 -0
- data/spec/unit/module_sync_spec.rb +51 -0
- metadata +10 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b756f006e9c39eef2b7a94ec1f896866f22f88099978530b2e587565dc9826c8
|
|
4
|
+
data.tar.gz: 1d5fb83e96ee7974a09b12f91e6fea79997554fbe959d8ad6c29938d41f76ae8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b838e8aeaf52e6d0f2ff3dfbdc1a6c0ede1d1188862de5e6d7205632d94383782ef3aeaa2fb1150b18469a46c582ded2fad29621048657c4922453d69e4821ed
|
|
7
|
+
data.tar.gz: 19160e011a602778c435dfa18e5e7583fada6a7bfdca7ee125be0553b0b8acc795f10f986821bd3783a7dba9f5e8e1d6815565803f3411ab61b0a61c552e1d1b
|
data/.github/labeler.yml
ADDED
data/.github/workflows/ci.yml
CHANGED
|
@@ -16,16 +16,16 @@ jobs:
|
|
|
16
16
|
outputs:
|
|
17
17
|
ruby: ${{ steps.ruby.outputs.versions }}
|
|
18
18
|
steps:
|
|
19
|
-
- uses: actions/checkout@
|
|
19
|
+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
|
20
20
|
- name: Setup ruby
|
|
21
|
-
uses: ruby/setup-ruby@v1
|
|
21
|
+
uses: ruby/setup-ruby@d45b1a4e94b71acab930e56e79c6aa188764e7f9 # v1.316.0
|
|
22
22
|
with:
|
|
23
23
|
ruby-version: "3.4"
|
|
24
24
|
bundler-cache: true
|
|
25
25
|
- name: Run linter
|
|
26
26
|
run: bundle exec rake rubocop
|
|
27
27
|
- id: ruby
|
|
28
|
-
uses: voxpupuli/ruby-version@
|
|
28
|
+
uses: voxpupuli/ruby-version@656370e339050da63b86b1c631f5f88a3f4c0803 # 1.0.1
|
|
29
29
|
|
|
30
30
|
test:
|
|
31
31
|
name: "Ruby ${{ matrix.ruby }}"
|
|
@@ -36,9 +36,9 @@ jobs:
|
|
|
36
36
|
matrix:
|
|
37
37
|
ruby: ${{ fromJSON(needs.rubocop_and_matrix.outputs.ruby) }}
|
|
38
38
|
steps:
|
|
39
|
-
- uses: actions/checkout@
|
|
39
|
+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
|
40
40
|
- name: Install Ruby ${{ matrix.ruby }}
|
|
41
|
-
uses: ruby/setup-ruby@v1
|
|
41
|
+
uses: ruby/setup-ruby@d45b1a4e94b71acab930e56e79c6aa188764e7f9 # v1.316.0
|
|
42
42
|
with:
|
|
43
43
|
ruby-version: ${{ matrix.ruby }}
|
|
44
44
|
bundler-cache: true
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: 🏷️ Pull Request Labeler
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
- pull_request_target
|
|
6
|
+
|
|
7
|
+
permissions: {}
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
labeler:
|
|
11
|
+
name: Labeler
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
if: github.repository_owner == 'voxpupuli' || github.repository_owner == 'OpenVoxProject'
|
|
14
|
+
permissions:
|
|
15
|
+
pull-requests: write
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/labeler@b8dd2d9be0f68b860e7dae5dae7d772984eacd6d # v6.2.0
|
|
@@ -15,16 +15,16 @@ jobs:
|
|
|
15
15
|
name: Build the gem
|
|
16
16
|
runs-on: ubuntu-24.04
|
|
17
17
|
steps:
|
|
18
|
-
- uses: actions/checkout@
|
|
18
|
+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
|
19
19
|
- name: Install Ruby
|
|
20
|
-
uses: ruby/setup-ruby@v1
|
|
20
|
+
uses: ruby/setup-ruby@d45b1a4e94b71acab930e56e79c6aa188764e7f9 # v1.316.0
|
|
21
21
|
with:
|
|
22
22
|
ruby-version: 'ruby'
|
|
23
23
|
- name: Build gem
|
|
24
24
|
shell: bash
|
|
25
25
|
run: gem build --verbose *.gemspec
|
|
26
26
|
- name: Upload gem to GitHub cache
|
|
27
|
-
uses: actions/upload-artifact@
|
|
27
|
+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
28
28
|
with:
|
|
29
29
|
name: gem-artifact
|
|
30
30
|
path: '*.gem'
|
|
@@ -39,7 +39,7 @@ jobs:
|
|
|
39
39
|
contents: write # clone repo and create release
|
|
40
40
|
steps:
|
|
41
41
|
- name: Download gem from GitHub cache
|
|
42
|
-
uses: actions/download-artifact@
|
|
42
|
+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
|
43
43
|
with:
|
|
44
44
|
name: gem-artifact
|
|
45
45
|
- name: Create Release
|
|
@@ -56,7 +56,7 @@ jobs:
|
|
|
56
56
|
packages: write # publish to rubygems.pkg.github.com
|
|
57
57
|
steps:
|
|
58
58
|
- name: Download gem from GitHub cache
|
|
59
|
-
uses: actions/download-artifact@
|
|
59
|
+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
|
60
60
|
with:
|
|
61
61
|
name: gem-artifact
|
|
62
62
|
- name: Publish gem to GitHub packages
|
|
@@ -73,10 +73,10 @@ jobs:
|
|
|
73
73
|
id-token: write # rubygems.org authentication
|
|
74
74
|
steps:
|
|
75
75
|
- name: Download gem from GitHub cache
|
|
76
|
-
uses: actions/download-artifact@
|
|
76
|
+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
|
77
77
|
with:
|
|
78
78
|
name: gem-artifact
|
|
79
|
-
- uses: rubygems/configure-rubygems-credentials@
|
|
79
|
+
- uses: rubygems/configure-rubygems-credentials@dc5a8d8553e6ee01fc26761a49e99e733d17954a # v2.1.0
|
|
80
80
|
- name: Publish gem to rubygems.org
|
|
81
81
|
shell: bash
|
|
82
82
|
run: gem push *.gem
|
|
@@ -92,11 +92,11 @@ jobs:
|
|
|
92
92
|
- release-to-rubygems
|
|
93
93
|
steps:
|
|
94
94
|
- name: Download gem from GitHub cache
|
|
95
|
-
uses: actions/download-artifact@
|
|
95
|
+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
|
96
96
|
with:
|
|
97
97
|
name: gem-artifact
|
|
98
98
|
- name: Install Ruby
|
|
99
|
-
uses: ruby/setup-ruby@v1
|
|
99
|
+
uses: ruby/setup-ruby@d45b1a4e94b71acab930e56e79c6aa188764e7f9 # v1.316.0
|
|
100
100
|
with:
|
|
101
101
|
ruby-version: 'ruby'
|
|
102
102
|
- name: Wait for release to propagate
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [4.4.0](https://github.com/voxpupuli/modulesync/tree/4.4.0) (2026-07-09)
|
|
6
|
+
|
|
7
|
+
[Full Changelog](https://github.com/voxpupuli/modulesync/compare/v4.3.0...4.4.0)
|
|
8
|
+
|
|
9
|
+
**Implemented enhancements:**
|
|
10
|
+
|
|
11
|
+
- feat: add best practices on how to version a gem [\#351](https://github.com/voxpupuli/modulesync/pull/351) ([rwaffen](https://github.com/rwaffen))
|
|
12
|
+
|
|
13
|
+
**Fixed bugs:**
|
|
14
|
+
|
|
15
|
+
- fix: add guess\_endpoint\_from for github, similar to gitlab [\#350](https://github.com/voxpupuli/modulesync/pull/350) ([rwaffen](https://github.com/rwaffen))
|
|
16
|
+
|
|
17
|
+
## [v4.3.0](https://github.com/voxpupuli/modulesync/tree/v4.3.0) (2026-07-09)
|
|
18
|
+
|
|
19
|
+
[Full Changelog](https://github.com/voxpupuli/modulesync/compare/4.2.0...v4.3.0)
|
|
20
|
+
|
|
21
|
+
**Implemented enhancements:**
|
|
22
|
+
|
|
23
|
+
- Add Ruby 4.0 support [\#338](https://github.com/voxpupuli/modulesync/pull/338) ([dependabot[bot]](https://github.com/apps/dependabot))
|
|
24
|
+
|
|
25
|
+
**Fixed bugs:**
|
|
26
|
+
|
|
27
|
+
- fix: validate PR credentials and retry PR creation [\#347](https://github.com/voxpupuli/modulesync/pull/347) ([rwaffen](https://github.com/rwaffen))
|
|
28
|
+
|
|
29
|
+
**Merged pull requests:**
|
|
30
|
+
|
|
31
|
+
- Update cucumber requirement from ~\> 10.1 to ~\> 11.0 [\#344](https://github.com/voxpupuli/modulesync/pull/344) ([dependabot[bot]](https://github.com/apps/dependabot))
|
|
32
|
+
- Update voxpupuli-rubocop requirement from ~\> 5.1.0 to ~\> 5.2.0 [\#341](https://github.com/voxpupuli/modulesync/pull/341) ([dependabot[bot]](https://github.com/apps/dependabot))
|
|
33
|
+
- Update voxpupuli-rubocop requirement from ~\> 5.0.0 to ~\> 5.1.0 [\#334](https://github.com/voxpupuli/modulesync/pull/334) ([dependabot[bot]](https://github.com/apps/dependabot))
|
|
34
|
+
|
|
5
35
|
## [4.2.0](https://github.com/voxpupuli/modulesync/tree/4.2.0) (2025-10-16)
|
|
6
36
|
|
|
7
37
|
[Full Changelog](https://github.com/voxpupuli/modulesync/compare/4.1.0...4.2.0)
|
data/README.md
CHANGED
|
@@ -200,7 +200,7 @@ or set them per repository in `managed_modules.yml`, using the `github` or
|
|
|
200
200
|
|
|
201
201
|
For GitHub Enterprise and self-hosted GitLab instances you also need to set the
|
|
202
202
|
`GITHUB_BASE_URL` or `GITLAB_BASE_URL` environment variables, or specify the
|
|
203
|
-
`base_url` parameter in `
|
|
203
|
+
`base_url` parameter per repository in `managed_modules.yml`:
|
|
204
204
|
|
|
205
205
|
```yaml
|
|
206
206
|
---
|
|
@@ -467,7 +467,7 @@ This gem is licensed under the Apache-2 license.
|
|
|
467
467
|
## Release information
|
|
468
468
|
|
|
469
469
|
To make a new release, please do:
|
|
470
|
-
* update the version in
|
|
470
|
+
* update the version in `lib/modulesync/version.rb`
|
|
471
471
|
* Install gems with `bundle install --with release --path .vendor`
|
|
472
472
|
* generate the changelog with `bundle exec rake changelog`
|
|
473
473
|
* Check if the new version matches the closed issues/PRs in the changelog
|
|
@@ -88,7 +88,7 @@ Feature: Create a pull-request/merge-request after update
|
|
|
88
88
|
"""
|
|
89
89
|
<%= @configs['name'] %>
|
|
90
90
|
"""
|
|
91
|
-
When I run `msync update --
|
|
91
|
+
When I run `msync update --message "Update test" --pr`
|
|
92
92
|
Then the stderr should contain "A token is required to use services from gitlab"
|
|
93
93
|
And the exit status should be 1
|
|
94
94
|
And the puppet module "puppet-test" from "fakenamespace" should have no commits made by "Aruba"
|
|
@@ -18,6 +18,13 @@ module ModuleSync
|
|
|
18
18
|
@api = Octokit::Client.new(access_token: token)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
def self.guess_endpoint_from(remote:)
|
|
22
|
+
endpoint = super
|
|
23
|
+
return 'https://api.github.com' if endpoint == 'https://github.com'
|
|
24
|
+
|
|
25
|
+
endpoint
|
|
26
|
+
end
|
|
27
|
+
|
|
21
28
|
private
|
|
22
29
|
|
|
23
30
|
def _open_pull_request(repo_path:, namespace:, title:, message:, source_branch:, target_branch:, labels:, noop:)
|
|
@@ -32,6 +32,16 @@ module ModuleSync
|
|
|
32
32
|
repo.diff("#{local_branch}..origin/#{remote_branch}").any?
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
+
# This method checks if the source branch is ahead of the target branch in the remote repository.
|
|
36
|
+
# It does this by checking if there are any commits in the source branch that are not in the target branch.
|
|
37
|
+
def remote_branch_ahead?(source_branch, target_branch)
|
|
38
|
+
return false unless remote_branch_exists?(source_branch) && remote_branch_exists?(target_branch)
|
|
39
|
+
|
|
40
|
+
log = repo.log(1).between("origin/#{target_branch}", "origin/#{source_branch}")
|
|
41
|
+
commits = log.respond_to?(:execute) ? log.execute : log
|
|
42
|
+
commits.any?
|
|
43
|
+
end
|
|
44
|
+
|
|
35
45
|
def default_branch
|
|
36
46
|
# `Git.default_branch` requires ruby-git >= 1.17.0
|
|
37
47
|
return Git.default_branch(repo.dir) if Git.respond_to? :default_branch
|
|
@@ -68,13 +68,31 @@ module ModuleSync
|
|
|
68
68
|
namespace: repository_namespace,
|
|
69
69
|
title: ModuleSync.options[:pr_title],
|
|
70
70
|
message: ModuleSync.options[:message],
|
|
71
|
-
source_branch:
|
|
72
|
-
target_branch:
|
|
71
|
+
source_branch: pull_request_source_branch,
|
|
72
|
+
target_branch: pull_request_target_branch,
|
|
73
73
|
labels: ModuleSync::Util.parse_list(ModuleSync.options[:pr_labels]),
|
|
74
74
|
noop: ModuleSync.options[:noop],
|
|
75
75
|
)
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
+
# This method checks if the pull request branch is ready to be opened.
|
|
79
|
+
# It does this by checking if the source branch is ahead of the target branch in the remote repository.
|
|
80
|
+
def pull_request_branch_ready?
|
|
81
|
+
repository.remote_branch_ahead?(pull_request_source_branch, pull_request_target_branch)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# This method returns the source branch for the pull request.
|
|
85
|
+
# It first checks if the `remote_branch` option is set, then checks if the `branch` option is set, and finally defaults to the repository's default branch.
|
|
86
|
+
def pull_request_source_branch
|
|
87
|
+
ModuleSync.options[:remote_branch] || ModuleSync.options[:branch] || repository.default_branch
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# This method returns the target branch for the pull request.
|
|
91
|
+
# It first checks if the `pr_target_branch` option is set, and if not, it defaults to the repository's default branch.
|
|
92
|
+
def pull_request_target_branch
|
|
93
|
+
ModuleSync.options[:pr_target_branch] || repository.default_branch
|
|
94
|
+
end
|
|
95
|
+
|
|
78
96
|
private
|
|
79
97
|
|
|
80
98
|
def _repository_remote
|
data/lib/modulesync.rb
CHANGED
|
@@ -11,6 +11,7 @@ require 'modulesync/puppet_module'
|
|
|
11
11
|
require 'modulesync/renderer'
|
|
12
12
|
require 'modulesync/settings'
|
|
13
13
|
require 'modulesync/util'
|
|
14
|
+
require 'modulesync/version'
|
|
14
15
|
|
|
15
16
|
require 'monkey_patches'
|
|
16
17
|
|
|
@@ -49,8 +50,8 @@ module ModuleSync
|
|
|
49
50
|
def self.find_template_files(local_template_dir)
|
|
50
51
|
if File.exist?(local_template_dir)
|
|
51
52
|
Find.find(local_template_dir).find_all { |p| p =~ /.erb$/ && !File.directory?(p) }
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
.collect { |p| p.chomp('.erb') }
|
|
54
|
+
.to_a
|
|
54
55
|
else
|
|
55
56
|
warn "#{local_template_dir} does not exist. " \
|
|
56
57
|
'Check that you are working in your module configs directory or ' \
|
|
@@ -152,7 +153,7 @@ module ModuleSync
|
|
|
152
153
|
new = puppet_module.bump(options[:message], options[:changelog])
|
|
153
154
|
puppet_module.repository.tag(new, options[:tag_pattern]) if options[:tag]
|
|
154
155
|
end
|
|
155
|
-
|
|
156
|
+
options[:pr] && (pushed || puppet_module.pull_request_branch_ready?) && puppet_module.open_pull_request
|
|
156
157
|
end
|
|
157
158
|
end
|
|
158
159
|
|
|
@@ -174,9 +175,13 @@ module ModuleSync
|
|
|
174
175
|
local_files = find_template_files(local_template_dir)
|
|
175
176
|
module_files = relative_names(local_files, local_template_dir)
|
|
176
177
|
|
|
178
|
+
# Initialize every Git service before updating any repository.
|
|
179
|
+
# This validates PR credentials before an update can commit or push changes.
|
|
180
|
+
initialized_modules = managed_modules
|
|
181
|
+
initialized_modules.each(&:git_service) if options[:pr]
|
|
182
|
+
|
|
177
183
|
errors = false
|
|
178
|
-
|
|
179
|
-
managed_modules.each do |puppet_module|
|
|
184
|
+
initialized_modules.each do |puppet_module|
|
|
180
185
|
manage_module(puppet_module, module_files, defaults)
|
|
181
186
|
rescue ModuleSync::Error, Git::Error => e
|
|
182
187
|
message = e.message || 'Error during `update`'
|
data/modulesync.gemspec
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
require_relative 'lib/modulesync/version'
|
|
5
4
|
|
|
6
5
|
Gem::Specification.new do |spec|
|
|
7
6
|
spec.name = 'modulesync'
|
|
8
|
-
spec.version =
|
|
7
|
+
spec.version = ModuleSync::VERSION
|
|
9
8
|
spec.authors = ['Vox Pupuli']
|
|
10
9
|
spec.email = ['voxpupuli@groups.io']
|
|
11
10
|
spec.summary = 'Puppet Module Synchronizer'
|
|
@@ -19,10 +18,10 @@ Gem::Specification.new do |spec|
|
|
|
19
18
|
spec.require_paths = ['lib']
|
|
20
19
|
|
|
21
20
|
spec.add_development_dependency 'aruba', '~>2.0'
|
|
22
|
-
spec.add_development_dependency 'cucumber', '~>
|
|
21
|
+
spec.add_development_dependency 'cucumber', '~> 11.0'
|
|
23
22
|
spec.add_development_dependency 'rake', '~> 13.2', '>= 13.2.1'
|
|
24
23
|
spec.add_development_dependency 'rspec', '~> 3.13'
|
|
25
|
-
spec.add_development_dependency 'voxpupuli-rubocop', '~> 5.
|
|
24
|
+
spec.add_development_dependency 'voxpupuli-rubocop', '~> 5.2.0'
|
|
26
25
|
|
|
27
26
|
spec.add_dependency 'git', '>= 3.0', '< 5'
|
|
28
27
|
spec.add_dependency 'gitlab', '>=4', '<7'
|
|
@@ -5,6 +5,18 @@ require 'spec_helper'
|
|
|
5
5
|
require 'modulesync/git_service/github'
|
|
6
6
|
|
|
7
7
|
describe ModuleSync::GitService::GitHub do
|
|
8
|
+
describe '.guess_endpoint_from' do
|
|
9
|
+
it 'uses the public GitHub API endpoint for a github.com remote' do
|
|
10
|
+
expect(described_class.guess_endpoint_from(remote: 'git@github.com:test/modulesync.git'))
|
|
11
|
+
.to eq('https://api.github.com')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'uses the remote hostname for a GitHub Enterprise remote' do
|
|
15
|
+
expect(described_class.guess_endpoint_from(remote: 'git@github.example.com:test/modulesync.git'))
|
|
16
|
+
.to eq('https://github.example.com')
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
8
20
|
context '::open_pull_request' do
|
|
9
21
|
before do
|
|
10
22
|
@client = double
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe ModuleSync::Repository do
|
|
6
|
+
subject(:repository) do
|
|
7
|
+
described_class.new(directory: '/tmp/example', remote: 'https://github.com/example/repository.git')
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
let(:remote_branches) do
|
|
11
|
+
[
|
|
12
|
+
instance_double(Git::Branch, name: 'main'),
|
|
13
|
+
instance_double(Git::Branch, name: 'modulesync'),
|
|
14
|
+
]
|
|
15
|
+
end
|
|
16
|
+
let(:branches) { instance_double(Git::Branches, remote: remote_branches) }
|
|
17
|
+
let(:log) { instance_double(Git::Log) }
|
|
18
|
+
let(:git) { instance_double(Git::Base, branches: branches, log: log) }
|
|
19
|
+
|
|
20
|
+
before do
|
|
21
|
+
repository.instance_variable_set(:@git, git)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'detects commits on a remote source branch that are missing from the target branch' do
|
|
25
|
+
allow(log).to receive(:between).with('origin/main', 'origin/modulesync').and_return(log)
|
|
26
|
+
allow(log).to receive(:execute).and_return([instance_double(Git::Object::Commit)])
|
|
27
|
+
|
|
28
|
+
expect(repository.remote_branch_ahead?('modulesync', 'main')).to be true
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'rejects a source branch that does not exist remotely' do
|
|
32
|
+
remote_branches.pop
|
|
33
|
+
|
|
34
|
+
expect(repository.remote_branch_ahead?('modulesync', 'main')).to be false
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -7,9 +7,12 @@ describe ModuleSync::SourceCode do
|
|
|
7
7
|
described_class.new('namespace/name', nil)
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
let(:repository) { instance_double(ModuleSync::Repository, default_branch: 'main') }
|
|
11
|
+
|
|
10
12
|
before do
|
|
11
13
|
options = ModuleSync.config_defaults.merge({ git_base: 'file:///tmp/dummy' })
|
|
12
14
|
ModuleSync.instance_variable_set :@options, options
|
|
15
|
+
allow(ModuleSync::Repository).to receive(:new).and_return(repository)
|
|
13
16
|
end
|
|
14
17
|
|
|
15
18
|
it 'has a repository namespace sets to "namespace"' do
|
|
@@ -19,4 +22,11 @@ describe ModuleSync::SourceCode do
|
|
|
19
22
|
it 'has a repository name sets to "name"' do
|
|
20
23
|
expect(subject.repository_name).to eq 'name'
|
|
21
24
|
end
|
|
25
|
+
|
|
26
|
+
it 'reports a remote source branch ahead of the PR target as ready' do
|
|
27
|
+
ModuleSync.options[:branch] = 'modulesync'
|
|
28
|
+
allow(repository).to receive(:remote_branch_ahead?).with('modulesync', 'main').and_return(true)
|
|
29
|
+
|
|
30
|
+
expect(subject.pull_request_branch_ready?).to be true
|
|
31
|
+
end
|
|
22
32
|
end
|
|
@@ -12,5 +12,56 @@ describe ModuleSync do
|
|
|
12
12
|
options = { managed_modules_conf: 'test_file.yml' }
|
|
13
13
|
described_class.update(options)
|
|
14
14
|
end
|
|
15
|
+
|
|
16
|
+
it 'validates PR credentials for every module before managing any module' do
|
|
17
|
+
allow(ModuleSync::Util).to receive(:parse_config).with('./config_defaults.yml').and_return({})
|
|
18
|
+
puppet_module = double
|
|
19
|
+
allow(described_class).to receive_messages(find_template_files: [], managed_modules: [puppet_module])
|
|
20
|
+
|
|
21
|
+
expect(puppet_module).to receive(:git_service).ordered
|
|
22
|
+
expect(described_class).to receive(:manage_module).with(puppet_module, [], {}).ordered
|
|
23
|
+
|
|
24
|
+
described_class.update(pr: true)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'does not manage modules when PR credentials are missing' do
|
|
28
|
+
allow(ModuleSync::Util).to receive(:parse_config).with('./config_defaults.yml').and_return({})
|
|
29
|
+
puppet_module = double
|
|
30
|
+
allow(described_class).to receive_messages(find_template_files: [], managed_modules: [puppet_module])
|
|
31
|
+
allow(puppet_module).to receive(:git_service)
|
|
32
|
+
.and_raise(ModuleSync::GitService::MissingCredentialsError, 'missing token')
|
|
33
|
+
expect(described_class).not_to receive(:manage_module)
|
|
34
|
+
|
|
35
|
+
expect { described_class.update(pr: true) }
|
|
36
|
+
.to raise_error(ModuleSync::GitService::MissingCredentialsError, 'missing token')
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context '::manage_module' do
|
|
41
|
+
let(:repository) { instance_double(ModuleSync::Repository) }
|
|
42
|
+
let(:settings) { instance_double(ModuleSync::Settings) }
|
|
43
|
+
let(:puppet_module) do
|
|
44
|
+
instance_double(ModuleSync::PuppetModule,
|
|
45
|
+
given_name: 'puppet-test',
|
|
46
|
+
repository: repository,
|
|
47
|
+
repository_name: 'puppet-test',
|
|
48
|
+
repository_namespace: 'example')
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
before do
|
|
52
|
+
described_class.instance_variable_set(:@options, described_class.config_defaults.merge(pr: true))
|
|
53
|
+
allow(repository).to receive_messages(prepare_workspace: nil, submit_changes: false)
|
|
54
|
+
allow(puppet_module).to receive(:path).with(ModuleSync::MODULE_CONF_FILE).and_return('module-config.yml')
|
|
55
|
+
allow(ModuleSync::Util).to receive(:parse_config).with('module-config.yml').and_return({})
|
|
56
|
+
allow(ModuleSync::Settings).to receive(:new).and_return(settings)
|
|
57
|
+
allow(settings).to receive_messages(unmanaged_files: [], managed_files: [])
|
|
58
|
+
allow(puppet_module).to receive(:pull_request_branch_ready?).and_return(true)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'opens a requested PR for an unchanged branch that is ahead of its target' do
|
|
62
|
+
expect(puppet_module).to receive(:open_pull_request)
|
|
63
|
+
|
|
64
|
+
described_class.manage_module(puppet_module, [], {})
|
|
65
|
+
end
|
|
15
66
|
end
|
|
16
67
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: modulesync
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Vox Pupuli
|
|
@@ -29,14 +29,14 @@ dependencies:
|
|
|
29
29
|
requirements:
|
|
30
30
|
- - "~>"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '
|
|
32
|
+
version: '11.0'
|
|
33
33
|
type: :development
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - "~>"
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '
|
|
39
|
+
version: '11.0'
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: rake
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -77,14 +77,14 @@ dependencies:
|
|
|
77
77
|
requirements:
|
|
78
78
|
- - "~>"
|
|
79
79
|
- !ruby/object:Gem::Version
|
|
80
|
-
version: 5.
|
|
80
|
+
version: 5.2.0
|
|
81
81
|
type: :development
|
|
82
82
|
prerelease: false
|
|
83
83
|
version_requirements: !ruby/object:Gem::Requirement
|
|
84
84
|
requirements:
|
|
85
85
|
- - "~>"
|
|
86
86
|
- !ruby/object:Gem::Version
|
|
87
|
-
version: 5.
|
|
87
|
+
version: 5.2.0
|
|
88
88
|
- !ruby/object:Gem::Dependency
|
|
89
89
|
name: git
|
|
90
90
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -189,8 +189,10 @@ extra_rdoc_files: []
|
|
|
189
189
|
files:
|
|
190
190
|
- ".config/cucumber.yml"
|
|
191
191
|
- ".github/dependabot.yml"
|
|
192
|
+
- ".github/labeler.yml"
|
|
192
193
|
- ".github/release.yml"
|
|
193
194
|
- ".github/workflows/ci.yml"
|
|
195
|
+
- ".github/workflows/labeler.yml"
|
|
194
196
|
- ".github/workflows/release.yml"
|
|
195
197
|
- ".gitignore"
|
|
196
198
|
- ".rspec"
|
|
@@ -232,6 +234,7 @@ files:
|
|
|
232
234
|
- lib/modulesync/settings.rb
|
|
233
235
|
- lib/modulesync/source_code.rb
|
|
234
236
|
- lib/modulesync/util.rb
|
|
237
|
+
- lib/modulesync/version.rb
|
|
235
238
|
- lib/monkey_patches.rb
|
|
236
239
|
- modulesync.gemspec
|
|
237
240
|
- spec/helpers/faker.rb
|
|
@@ -241,6 +244,7 @@ files:
|
|
|
241
244
|
- spec/unit/module_sync/git_service/github_spec.rb
|
|
242
245
|
- spec/unit/module_sync/git_service/gitlab_spec.rb
|
|
243
246
|
- spec/unit/module_sync/git_service_spec.rb
|
|
247
|
+
- spec/unit/module_sync/repository_spec.rb
|
|
244
248
|
- spec/unit/module_sync/settings_spec.rb
|
|
245
249
|
- spec/unit/module_sync/source_code_spec.rb
|
|
246
250
|
- spec/unit/module_sync_spec.rb
|
|
@@ -262,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
262
266
|
- !ruby/object:Gem::Version
|
|
263
267
|
version: '0'
|
|
264
268
|
requirements: []
|
|
265
|
-
rubygems_version:
|
|
269
|
+
rubygems_version: 4.0.10
|
|
266
270
|
specification_version: 4
|
|
267
271
|
summary: Puppet Module Synchronizer
|
|
268
272
|
test_files: []
|