ra10ke 1.0.0 → 1.1.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: 6b40e69bd38407cb3c0e54c36a83cdc1699ac85ea8512118275bce2f9e8dc6ef
4
- data.tar.gz: 4cedb006d2cf6591280e75df20fcf33ba4abdd5f8647caf68497f13c53c05f36
3
+ metadata.gz: 64e7e73cfb508697efd25e4aec36655c126a168a81fca44345f6564929be6bcd
4
+ data.tar.gz: 2139cb8c668b255a04d975121014006bd94cc4a4b45d71008e37e9e1341c74d6
5
5
  SHA512:
6
- metadata.gz: 0d87d64c5635eb697987a69e3ce56dcb230175f43182ee67e54817da51624c07426ad5f7c82b6f31c896ef88e2ed2132584c5dfc4d085c591e9336fc1d5fc6b3
7
- data.tar.gz: 84247260dbf741c18cd0aef1888b40f07328c015b228f1c021ae15c1d8846497819bbe6a6226e51cfe43697e84707c4d0a827f57796a6e73cce76015b354272a
6
+ metadata.gz: d05765b4c95390301ec8c6e0917f251ee60333b09810174c643d1d6a5608824ee96c46d334f60232beb026ea28caa4c4c5ea0e1e6b72b0f12ff7c7fdda6783b4
7
+ data.tar.gz: dc0317d3c47ce2e18e9c8818d7dd468f0acdd8e5a8047dad637938f40745196c66369ac4741293e092f8ab28e6a115aec70e936ea8845cb133c6f1f9108a0cd0
@@ -0,0 +1,11 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: "bundler" # See documentation for possible values
9
+ directory: "/" # Location of package manifests
10
+ schedule:
11
+ interval: "daily"
@@ -0,0 +1,32 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - '*'
7
+
8
+ jobs:
9
+ release:
10
+ runs-on: ubuntu-latest
11
+ if: github.repository_owner == 'voxpupuli'
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Install Ruby 3.0
15
+ uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: '3.0'
18
+ env:
19
+ BUNDLE_WITHOUT: release
20
+ - name: Build gem
21
+ run: gem build *.gemspec
22
+ - name: Publish gem to rubygems.org
23
+ run: gem push *.gem
24
+ env:
25
+ GEM_HOST_API_KEY: '${{ secrets.RUBYGEMS_AUTH_TOKEN }}'
26
+ - name: Setup GitHub packages access
27
+ run: |
28
+ mkdir -p ~/.gem
29
+ echo ":github: Bearer ${{ secrets.GITHUB_TOKEN }}" >> ~/.gem/credentials
30
+ chmod 0600 ~/.gem/credentials
31
+ - name: Publish gem to GitHub packages
32
+ run: gem push --key github --host https://rubygems.pkg.github.com/voxpupuli *.gem
@@ -0,0 +1,35 @@
1
+ name: Test
2
+
3
+ on:
4
+ - pull_request
5
+ - push
6
+
7
+ env:
8
+ BUNDLE_WITHOUT: release
9
+
10
+ jobs:
11
+ test:
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ include:
17
+ - ruby: "2.4"
18
+ - ruby: "2.5"
19
+ - ruby: "2.6"
20
+ - ruby: "2.7"
21
+ - ruby: "3.0"
22
+ coverage: "yes"
23
+ env:
24
+ COVERAGE: ${{ matrix.coverage }}
25
+ steps:
26
+ - uses: actions/checkout@v2
27
+ - name: Install Ruby ${{ matrix.ruby }}
28
+ uses: ruby/setup-ruby@v1
29
+ with:
30
+ ruby-version: ${{ matrix.ruby }}
31
+ bundler-cache: true
32
+ - name: Run tests
33
+ run: bundle exec rake
34
+ - name: Build gem
35
+ run: gem build *.gemspec
data/.gitignore CHANGED
@@ -1,3 +1,6 @@
1
1
  Gemfile.lock
2
+ coverage
2
3
  pkg
3
4
  .bundle
5
+ vendor
6
+ .vendor
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.3
1
+ 2.5.7
data/.travis.yml CHANGED
@@ -6,6 +6,7 @@ rvm:
6
6
  - '2.3'
7
7
  - '2.4'
8
8
  - '2.5'
9
+ - '2.6'
9
10
  deploy:
10
11
  provider: rubygems
11
12
  api_key:
data/CHANGELOG.md CHANGED
@@ -1,8 +1,36 @@
1
- CHANGELOG
2
- =========
1
+ # Changelog
3
2
 
4
- 1.0.0
5
- -----
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [v1.1.0](https://github.com/voxpupuli/ra10ke/tree/v1.1.0) (2021-10-26)
6
+
7
+ [Full Changelog](https://github.com/voxpupuli/ra10ke/compare/v1.0.0...v1.1.0)
8
+
9
+ **Implemented enhancements:**
10
+
11
+ - Support r10k:validate with control\_branch [\#58](https://github.com/voxpupuli/ra10ke/issues/58)
12
+ - Implement GitHub Actions and fix tests [\#62](https://github.com/voxpupuli/ra10ke/pull/62) ([bastelfreak](https://github.com/bastelfreak))
13
+ - Add handling for additional r10k args in validate for control\_branch [\#61](https://github.com/voxpupuli/ra10ke/pull/61) ([ananace](https://github.com/ananace))
14
+ - Add r10k:deprecation task [\#60](https://github.com/voxpupuli/ra10ke/pull/60) ([ananace](https://github.com/ananace))
15
+ - Support r10k:validate with control\_branch modules [\#59](https://github.com/voxpupuli/ra10ke/pull/59) ([ananace](https://github.com/ananace))
16
+ - allow to add other version formats in dependencies [\#56](https://github.com/voxpupuli/ra10ke/pull/56) ([jduepmeier](https://github.com/jduepmeier))
17
+ - Fixes \#52 - validate task fails when repo does not exist [\#53](https://github.com/voxpupuli/ra10ke/pull/53) ([logicminds](https://github.com/logicminds))
18
+
19
+ **Fixed bugs:**
20
+
21
+ - Fix source of control\_branch data [\#63](https://github.com/voxpupuli/ra10ke/pull/63) ([ananace](https://github.com/ananace))
22
+
23
+ **Closed issues:**
24
+
25
+ - validate task fails when repo does not exist [\#52](https://github.com/voxpupuli/ra10ke/issues/52)
26
+
27
+ **Merged pull requests:**
28
+
29
+ - Add Dependabot config [\#65](https://github.com/voxpupuli/ra10ke/pull/65) ([bastelfreak](https://github.com/bastelfreak))
30
+ - Set minimal Ruby version to 2.4.0 [\#64](https://github.com/voxpupuli/ra10ke/pull/64) ([bastelfreak](https://github.com/bastelfreak))
31
+ - Add coverage reports [\#54](https://github.com/voxpupuli/ra10ke/pull/54) ([logicminds](https://github.com/logicminds))
32
+
33
+ ## [v1.0.0](https://github.com/voxpupuli/ra10ke/tree/v1.0.0) (2020-02-08)
6
34
 
7
35
  2020-02-08
8
36
 
@@ -120,3 +148,6 @@ Many thanks to [Alexander "Ace" Olofsson](https://github.com/ace13) and [James P
120
148
  2015-12-07
121
149
 
122
150
  * Initial release
151
+
152
+
153
+ \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
data/Gemfile CHANGED
@@ -2,3 +2,12 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in ra10ke.gemspec
4
4
  gemspec
5
+
6
+ group :release do
7
+ gem 'github_changelog_generator', :require => false
8
+ end
9
+
10
+ group :coverage, optional: ENV['COVERAGE']!='yes' do
11
+ gem 'simplecov-console', :require => false
12
+ gem 'codecov', :require => false
13
+ end
data/HISTORY.md ADDED
@@ -0,0 +1,118 @@
1
+ ## [v1.0.0](https://github.com/voxpupuli/ra10ke/tree/v1.0.0) (2020-02-08)
2
+
3
+ 2020-02-08
4
+
5
+ Closed Pull Requests:
6
+
7
+ * [#44](https://github.com/voxpupuli/ra10ke/pull/44) - Fix the faulty docs for Ra10ke::Validate#all_refs after [#42](https://github.com/voxpupuli/ra10ke/pull/42)
8
+ * [#45](https://github.com/voxpupuli/ra10ke/pull/45) - Add a duplicates check
9
+ * [#48](https://github.com/voxpupuli/ra10ke/pull/48) - Allow semverse 3.x
10
+
11
+ 0.6.2
12
+ -----
13
+
14
+ 2019-08-26
15
+
16
+ Closed Pull Requests:
17
+
18
+ * [#42](https://github.com/voxpupuli/ra10ke/pull/42) - Fix lost refs in validation
19
+
20
+ Again many thanks to the following contributors for submitting PRs:
21
+
22
+ * [Alexander Olofsson](https://github.com/ananace)
23
+
24
+ 0.6.1
25
+ -----
26
+
27
+ 2019-08-17
28
+
29
+ Closed Pull Requests:
30
+
31
+ * [#40](https://github.com/voxpupuli/ra10ke/pull/40) - Fix a fault in the mod handling behaviour
32
+
33
+ Closed Issues:
34
+
35
+ * [#25](https://github.com/voxpupuli/ra10ke/issues/25) - Consider making r10k:install have a default path of '.'
36
+
37
+ Many thanks to the following contributors for submitting PRs:
38
+
39
+ * [Alexander Olofsson](https://github.com/ananace)
40
+
41
+ 0.6.0
42
+ -----
43
+
44
+ 2019-07-30
45
+
46
+ Closed Pull Requests:
47
+
48
+ * [#35](https://github.com/voxpupuli/ra10ke/pull/35) Adds new validate task for verifying the integrity of all modules specified in the Puppetfile
49
+ * [#33](https://github.com/voxpupuli/ra10ke/pull/33) Refactor tasks, Version tag handling fix, purge option
50
+ * [#32](https://github.com/voxpupuli/ra10ke/pull/32) Make it possible to configure the tasks in the rakefile
51
+
52
+ Many thanks to the following contributors for submitting PRs:
53
+
54
+ * [Corey Osman](https://github.com/logicminds)
55
+ * [Andreas Zuber](https://github.com/ZeroPointEnergy)
56
+
57
+ 0.5.0
58
+ -----
59
+
60
+ 2018-12-26
61
+
62
+ Closed Pull Requests:
63
+
64
+ * [#22](https://github.com/voxpupuli/ra10ke/pull/22) Add rudimentary r10k:install task
65
+ * [#26](https://github.com/voxpupuli/ra10ke/pull/26) make use of the forge command in puppetfile
66
+ * [#29](https://github.com/voxpupuli/ra10ke/pull/29) Abort (exit 1) if Puppetfile syntax check fails
67
+ * [#30](https://github.com/voxpupuli/ra10ke/pull/30) enable travis deployment
68
+
69
+ 0.4.0
70
+ -----
71
+
72
+ 2018-06-17
73
+
74
+ * [#13](https://github.com/voxpupuli/ra10ke/pull/13) Avoid using `desired_ref` directly for Git
75
+ * [#14](https://github.com/voxpupuli/ra10ke/pull/14) Set required Ruby version as `>= 2.1.0`
76
+ * [#15](https://github.com/voxpupuli/ra10ke/pull/15) ignore invalid ref
77
+ * [#16](https://github.com/voxpupuli/ra10ke/pull/16) Use Semantic Versioning for Git tags
78
+ * [#17](https://github.com/voxpupuli/ra10ke/pull/17) Be careful around trimming Git tags
79
+ * [#19](https://github.com/voxpupuli/ra10ke/pull/19) Ensure Puppetfile gets parsed with absolute path
80
+
81
+ Many thanks to the following contributors for submitting the PRs:
82
+ * [Valter Jansons](https://github.com/sigv)
83
+ * [Martin Alfke](https://github.com/tuxmea)
84
+ * [Matthias Baur](https://github.com/baurmatt)
85
+
86
+ 0.3.0
87
+ -----
88
+
89
+ 2017-10-08
90
+
91
+ * [#6](https://github.com/voxpupuli/ra10ke/pull/6) Add a dependency solver based on the Ruby Solve library (thanks to [Jarkko Oranen](https://github.com/oranenj))
92
+ * [#8](https://github.com/voxpupuli/ra10ke/pull/8) Add numeric tag convention support (thanks to [Hervé MARTIN](https://github.com/HerveMARTIN))
93
+
94
+ 0.2.0
95
+ -----
96
+
97
+ 2017-01-03
98
+
99
+ * Moved to [Vox Pupuli](https://voxpupuli.org/)
100
+ * [#3](https://github.com/voxpupuli/ra10ke/pull/3) Update ra10ke with r10k 2.4.0 support
101
+ * [#4](https://github.com/voxpupuli/ra10ke/pull/4) Added git support
102
+
103
+ Many thanks to [Alexander "Ace" Olofsson](https://github.com/ace13) and [James Powis](https://github.com/james-powis) for their contributions!
104
+
105
+ 0.1.1
106
+ -----
107
+
108
+ 2016-08-22
109
+
110
+ * [#1](https://github.com/tampakrap/ra10ke/issues/1) update docs to mention Gemfile and Rakefile
111
+ * properly advertise the user agent
112
+
113
+ 0.1.0
114
+ -----
115
+
116
+ 2015-12-07
117
+
118
+ * Initial release
data/README.md CHANGED
@@ -1,7 +1,12 @@
1
1
  ra10ke
2
2
  ======
3
3
 
4
- [![Gem Version](https://badge.fury.io/rb/ra10ke.svg)](https://badge.fury.io/rb/ra10ke)
4
+ [![License](https://img.shields.io/github/license/voxpupuli/ra10ke.svg)](https://github.com/voxpupuli/ra10ke/blob/master/LICENSE.txt)
5
+ [![Test](https://github.com/voxpupuli/ra10ke/actions/workflows/test.yml/badge.svg)](https://github.com/voxpupuli/ra10ke/actions/workflows/test.yml)
6
+ [![codecov](https://codecov.io/gh/voxpupuli/ra10ke/branch/master/graph/badge.svg?token=Mypkl78hvK)](https://codecov.io/gh/voxpupuli/ra10ke)
7
+ [![Release](https://github.com/voxpupuli/ra10ke/actions/workflows/release.yml/badge.svg)](https://github.com/voxpupuli/ra10ke/actions/workflows/release.yml)
8
+ [![RubyGem Version](https://img.shields.io/gem/v/ra10ke.svg)](https://rubygems.org/gems/ra10ke)
9
+ [![RubyGem Downloads](https://img.shields.io/gem/dt/ra10ke.svg)](https://rubygems.org/gems/ra10ke)
5
10
 
6
11
  Rake tasks related to [R10K](https://github.com/puppetlabs/r10k) and
7
12
  [Puppetfile](https://github.com/puppetlabs/r10k/blob/master/doc/puppetfile.mkd).
@@ -145,3 +150,22 @@ gitlab:
145
150
 
146
151
  Error: Duplicates exist in the Puppetfile
147
152
  ```
153
+
154
+ ### r10k:deprecation
155
+
156
+ This rake task checks all the Forge modules listed in the Puppetfile, looking
157
+ for modules that are marked as deprecated on the Forge.
158
+
159
+ Example
160
+
161
+ ```
162
+ NAME | DEPRECATED_AT
163
+ ------------------------|--------------------------
164
+ kemra102-auditd | 2021-07-22 12:11:46
165
+ puppet-staging | 2018-12-18 11:11:29
166
+ puppetlabs-resource_api | 2021-03-31 12:53:24
167
+ puppetlabs-ruby | 2021-04-22 10:29:42
168
+ puppetlabs-translate | 2021-03-19 10:11:51
169
+
170
+ Error: Puppetfile contains deprecated modules.
171
+ ```
data/Rakefile CHANGED
@@ -14,3 +14,16 @@ task :default => [:spec]
14
14
  RSpec::Core::RakeTask.new(:spec) do |spec|
15
15
  spec.pattern = FileList['spec/**/*_spec.rb']
16
16
  end
17
+
18
+ begin
19
+ require 'github_changelog_generator/task'
20
+ GitHubChangelogGenerator::RakeTask.new :changelog do |config|
21
+ version = Ra10ke::VERSION
22
+ config.future_release = "v#{version}" if version =~ /^\d+\.\d+.\d+$/
23
+ config.header = "# Changelog\n\nAll notable changes to this project will be documented in this file."
24
+ config.exclude_labels = %w{duplicate question invalid wontfix wont-fix skip-changelog}
25
+ config.user = 'voxpupuli'
26
+ config.project = 'ra10ke'
27
+ end
28
+ rescue LoadError
29
+ end
@@ -1,4 +1,34 @@
1
1
  module Ra10ke::Dependencies
2
+ @@version_formats = {}
3
+
4
+ # Registers a block that finds the latest version.
5
+ # The block will be called with a list of tags.
6
+ # If the block returns nil the next format will be tried.
7
+ def self.register_version_format(name, &block)
8
+ @@version_formats[name] = block
9
+ end
10
+
11
+ # semver is the default version format.
12
+ register_version_format(:semver) do |tags|
13
+ latest_tag = tags.map do |tag|
14
+ begin
15
+ Semverse::Version.new tag[/\Av?(.*)\Z/, 1]
16
+ rescue Semverse::InvalidVersionFormat
17
+ # ignore tags that do not comply to semver
18
+ nil
19
+ end
20
+ end.select { |tag| !tag.nil? }.sort.last.to_s.downcase
21
+ latest_ref = tags.detect { |tag| tag[/\Av?(.*)\Z/, 1] == latest_tag }
22
+ end
23
+
24
+ def get_latest_ref(remote_refs)
25
+ tags = remote_refs['tags'].keys
26
+ latest_ref = nil
27
+ @@version_formats.detect { |_, block| latest_ref = block.call(tags) }
28
+ latest_ref = 'undef (tags do not follow any known pattern)' if latest_ref.nil?
29
+ latest_ref
30
+ end
31
+
2
32
  def define_task_dependencies(*_args)
3
33
  desc "Print outdated forge modules"
4
34
  task :dependencies do
@@ -44,17 +74,10 @@ module Ra10ke::Dependencies
44
74
  # we have to be be opinionated here
45
75
  # so semantic versioning (vX.Y.Z) it is for us
46
76
  # as well as support for skipping the leading v letter
47
- tags = remote_refs['tags'].keys
48
- latest_tag = tags.map do |tag|
49
- begin
50
- Semverse::Version.new tag[/\Av?(.*)\Z/, 1]
51
- rescue Semverse::InvalidVersionFormat
52
- # ignore tags that do not comply to semver
53
- nil
54
- end
55
- end.select { |tag| !tag.nil? }.sort.last.to_s.downcase
56
- latest_ref = tags.detect { |tag| tag[/\Av?(.*)\Z/, 1] == latest_tag }
57
- latest_ref = 'undef (tags do not match semantic versioning)' if latest_ref.nil?
77
+ #
78
+ # register own version formats with
79
+ # Ra10ke::Dependencies.register_version_format(:name, &block)
80
+ latest_ref = get_latest_ref(remote_refs)
58
81
  elsif ref.match(/^[a-z0-9]{40}$/)
59
82
  # for sha just assume head should be tracked
60
83
  latest_ref = remote_refs['head'][:sha]
@@ -66,6 +89,5 @@ module Ra10ke::Dependencies
66
89
  end
67
90
  end
68
91
  end
69
-
70
92
  end
71
93
  end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ra10ke/puppetfile_parser'
4
+ require 'English'
5
+ require 'puppet_forge'
6
+ require 'table_print'
7
+ require 'time'
8
+
9
+ module Ra10ke::Deprecation
10
+ # Validate the git urls and refs
11
+ def define_task_deprecation(*)
12
+ desc 'Validate that no forge modules are deprecated'
13
+ task :deprecation do
14
+ valid = Ra10ke::Deprecation::Validation.new(get_puppetfile.puppetfile_path)
15
+ exit_code = 0
16
+ if valid.bad_mods?
17
+ exit_code = 1
18
+ message = "\nError: Puppetfile contains deprecated modules."
19
+ tp valid.sorted_mods, :name, :deprecated_at
20
+ else
21
+ message = 'Puppetfile contains no deprecated Forge modules.'
22
+ end
23
+ abort(message) if exit_code.positive?
24
+
25
+ puts message
26
+ end
27
+ end
28
+
29
+ class Validation
30
+ include Ra10ke::PuppetfileParser
31
+
32
+ attr_reader :puppetfile
33
+
34
+ def initialize(file)
35
+ file ||= './Puppetfile'
36
+ @puppetfile = File.expand_path(file)
37
+ abort("Puppetfile does not exist at #{puppetfile}") unless File.readable?(puppetfile)
38
+ end
39
+
40
+ # @return [Array[Hash]] array of module information and git status
41
+ def deprecated_modules
42
+ @deprecated_modules ||= begin
43
+ deprecated = forge_modules(puppetfile).map do |mod|
44
+ # For Ruby 2.4 support
45
+ begin # rubocop:disable Style/RedundantBegin
46
+ module_name = "#{mod[:namespace] || mod[:name]}-#{mod[:name]}"
47
+ forge_data = PuppetForge::Module.find(module_name)
48
+
49
+ next forge_data if forge_data.deprecated_at
50
+
51
+ nil
52
+ rescue Faraday::ResourceNotFound
53
+ nil
54
+ end
55
+ end
56
+ deprecated.compact.map do |mod|
57
+ { name: mod.slug, deprecated_at: Time.parse(mod.deprecated_at) }
58
+ end
59
+ end
60
+ end
61
+
62
+ # @return [Boolean] - true if there are any bad mods
63
+ def bad_mods?
64
+ deprecated_modules.any?
65
+ end
66
+
67
+ # @return [Hash] - sorts the mods based on good/bad
68
+ def sorted_mods
69
+ deprecated_modules.sort_by { |a| a[:name] }
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tempfile'
4
+
5
+ module Ra10ke
6
+ class GitRepo
7
+ attr_reader :url
8
+
9
+ REMOTE_REFS_CMD = 'git ls-remote --symref'
10
+ CLONE_CMD = 'git clone --no-tags'
11
+ CURRENT_BRANCH_CMD = 'git symbolic-ref --short HEAD'
12
+ SHOW_CMD = 'git show'
13
+
14
+ def initialize(url)
15
+ @url = url
16
+ end
17
+
18
+ # Get the current branch for a Git repo
19
+ # @param path [String] - The path to the repository to check
20
+ # @return [String] - The current active branch of the Git repo
21
+ def self.current_branch(path)
22
+ Dir.chdir(path) do
23
+ data, success = run_command(CURRENT_BRANCH_CMD)
24
+ return success ? data.strip : nil
25
+ end
26
+ end
27
+
28
+ # @return [Array] - the raw data from the git ls-remote command as lines array
29
+ # return empty array if url or command failed
30
+ def remote_refs
31
+ @remote_refs ||= begin
32
+ data, success = run_command("#{REMOTE_REFS_CMD} #{url}")
33
+ success ? data.lines : []
34
+ end
35
+ end
36
+
37
+ # @return [Boolean] true if the git url is valid
38
+ def valid_url?
39
+ !remote_refs.empty?
40
+ end
41
+
42
+ # @return [Boolean] - return true if the commit sha is valid
43
+ # @param url [String] - the git string either https or ssh url
44
+ # @param ref [String] - the sha id
45
+ def valid_commit?(sha)
46
+ return false if sha.nil? || sha.empty?
47
+ return true if valid_ref?(sha)
48
+
49
+ # cloning is a last resort if for some reason we cannot
50
+ # remotely get via ls-remote
51
+ Dir.mktmpdir do |dir|
52
+ run_command("#{CLONE_CMD} #{url} #{dir}", silent: true)
53
+ Dir.chdir(dir) do
54
+ _, status = run_command("#{SHOW_CMD} #{sha}", silent: true)
55
+ status
56
+ end
57
+ end
58
+ end
59
+
60
+ # @return [Boolean] - return true if the ref is valid
61
+ # @param url [String] - the git string either https or ssh url
62
+ # @param ref [String] - the ref object, branch name, tag name, or commit sha, defaults to HEAD
63
+ def valid_ref?(ref = 'HEAD')
64
+ return false if ref.nil?
65
+
66
+ found = all_refs.find do |data|
67
+ # we don't need to bother with these types
68
+ next if data[:type] == :pull || data[:type] == :merge_request
69
+
70
+ # is the name equal to the tag or branch? Is the commit sha equal?
71
+ data[:name].eql?(ref) || data[:sha].slice(0, 8).eql?(ref.slice(0, 8))
72
+ end
73
+ !found.nil?
74
+ end
75
+
76
+ # @return [Array] - an array of all the refs associated with the remote repository
77
+ # @param url [String] - the git string either https or ssh url
78
+ # @example
79
+ # [{:sha=>"0ec707e431367bbe2752966be8ab915b6f0da754", :ref=>"refs/heads/74110ac", :type=>:branch, :subtype=>nil, :name=>"74110ac"},
80
+ # :sha=>"07bb5d2d94db222dca5860eb29c184e8970f36f4", :ref=>"refs/pull/74/head", :type=>:pull, :subtype=>:head, :name=>"74"},
81
+ # :sha=>"156ca9a8ea69e056e86355b27d944e59d1b3a1e1", :ref=>"refs/heads/master", :type=>:branch, :subtype=>nil, :name=>"master"},
82
+ # :sha=>"fcc0532bbc5a5b65f3941738339e9cc7e3d767ce", :ref=>"refs/pull/249/head", :type=>:pull, :subtype=>:head, :name=>"249"},
83
+ # :sha=>"8d54891fa5df75890ee15d53080c2a81b4960f92", :ref=>"refs/pull/267/head", :type=>:pull, :subtype=>:head, :name=>"267"}]
84
+ def all_refs
85
+ @all_refs ||= begin
86
+ remote_refs.each_with_object([]) do |line, refs|
87
+ sha, ref = line.split("\t")
88
+ next refs if sha.eql?('ref: refs/heads/master')
89
+
90
+ _, type, name, subtype = ref.chomp.split('/')
91
+ next refs unless name
92
+
93
+ type = :tag if type.eql?('tags')
94
+ type = type.to_sym
95
+ subtype = subtype.to_sym if subtype
96
+ type = :branch if type.eql?(:heads)
97
+ refs << { sha: sha, ref: ref.chomp, type: type, subtype: subtype, name: name }
98
+ end
99
+ end
100
+ end
101
+
102
+ # useful for mocking easily
103
+ # @param cmd [String]
104
+ # @param silent [Boolean] set to true if you wish to send output to /dev/null, false by default
105
+ # @return [Array]
106
+ def self.run_command(cmd, silent: false)
107
+ out_args = silent ? '2>&1 > /dev/null' : '2>&1'
108
+ out = `#{cmd} #{out_args}`
109
+ [out, $CHILD_STATUS.success?]
110
+ end
111
+
112
+ def run_command(cmd, silent: false)
113
+ self.class.run_command(cmd, silent: silent)
114
+ end
115
+ end
116
+ end
@@ -12,6 +12,13 @@ module Ra10ke
12
12
  end
13
13
  end
14
14
 
15
+ # @return [Array] - returns a array of hashes that contain modules from the Forge
16
+ def forge_modules(file = puppetfile)
17
+ modules(file).reject do |mod|
18
+ mod[:args].key?(:git)
19
+ end
20
+ end
21
+
15
22
  # @param puppetfile [String] - the absolute path to the puppetfile
16
23
  # @return [Array] - returns an array of module hashes that represent the puppetfile
17
24
  # @example