modulesync 1.2.0 → 1.3.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/.rubocop_todo.yml +1 -1
- data/CHANGELOG.md +10 -1
- data/README.md +28 -5
- data/lib/modulesync.rb +40 -8
- data/lib/modulesync/cli.rb +5 -0
- data/lib/modulesync/pr/github.rb +9 -3
- data/lib/modulesync/pr/gitlab.rb +5 -3
- data/modulesync.gemspec +1 -1
- data/spec/unit/modulesync_spec.rb +2 -2
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 7fb5357d0ecf1e4f620be302b55c9f1e88779c446021097172866c87a1e57d8f
         | 
| 4 | 
            +
              data.tar.gz: be3975ae4dbe2a4e6a32cc5851bc0e9ce8ac8dd0b9560175380f492e43dabe27
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 15051bcc97f904d9d886e67abf9e6ea99818410ec3f330f7d67ed9cc86451f322b79861801218f46b534a0f3241f3aa15dc16928360c471c0742e0b8f3c120f7
         | 
| 7 | 
            +
              data.tar.gz: d527c5e7eeeccfabdbd5eb328759b826873aea33f12419179a89f84a1499af784788de9ca420eab8cbc5d2d83fdf1a9a8f6bbde1c536b25aca9c35b21c77c40b
         | 
    
        data/.rubocop_todo.yml
    CHANGED
    
    
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -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 | 
            -
             | 
| 189 | 
            -
             | 
| 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.
         | 
    
        data/lib/modulesync.rb
    CHANGED
    
    | @@ -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 | 
            -
                 | 
| 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] &&  | 
| 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( | 
| 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 =  | 
| 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( | 
| 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/ | 
| 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 | 
            -
                   | 
| 184 | 
            -
                  raise
         | 
| 216 | 
            +
                  warn '--pr specified without environment variables GITHUB_TOKEN or GITLAB_TOKEN'
         | 
| 185 217 | 
             
                end
         | 
| 186 218 | 
             
              end
         | 
| 187 219 | 
             
            end
         | 
    
        data/lib/modulesync/cli.rb
    CHANGED
    
    | @@ -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.',
         | 
    
        data/lib/modulesync/pr/github.rb
    CHANGED
    
    | @@ -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 =>  | 
| 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, | 
| 23 | 
            -
             | 
| 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]}"
         | 
    
        data/lib/modulesync/pr/gitlab.rb
    CHANGED
    
    | @@ -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 =>  | 
| 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 =>  | 
| 29 | 
            +
                                                     :target_branch => target_branch,
         | 
| 29 30 | 
             
                                                     :labels => mr_labels)
         | 
| 30 | 
            -
                      $stdout.puts  | 
| 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
         | 
    
        data/modulesync.gemspec
    CHANGED
    
    | @@ -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. | 
| 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 ':: | 
| 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. | 
| 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. | 
| 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- | 
| 11 | 
            +
            date: 2020-07-21 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: aruba
         |