puppet-armature 0.3.0 → 0.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.
@@ -0,0 +1,41 @@
1
+ require 'minitest/autorun'
2
+ require 'helpers'
3
+
4
+ class PuppetfileTest < Minitest::Test
5
+ include ArmatureTestHelpers
6
+
7
+ def test_empty
8
+ with_temp_dir("puppetfile") do
9
+ parse_puppetfile("")
10
+ end
11
+ end
12
+
13
+ def test_one_module
14
+ with_temp_dir("puppetfile") do
15
+ results = parse_puppetfile(<<-PUPPETFILE)
16
+ mod "interesting", :git=>"#{repo_path("foo")}"
17
+ PUPPETFILE
18
+
19
+ assert_equal(["interesting"], results.keys(),
20
+ "Modules incorrect")
21
+ end
22
+ end
23
+
24
+ def test_bad_module_name
25
+ with_temp_dir("puppetfile") do
26
+ assert_raises(Armature::Environments::InvalidNameError) do
27
+ parse_puppetfile(<<-PUPPETFILE)
28
+ mod "./foo", :git=>"#{repo_path("foo")}"
29
+ PUPPETFILE
30
+ end
31
+ end
32
+ end
33
+
34
+ private
35
+ def parse_puppetfile(contents)
36
+ @cache = Armature::Cache.new("cache")
37
+ repo_init("foo")
38
+ File.write("Puppetfile", contents)
39
+ Armature::Puppetfile.new(@cache).include("Puppetfile")
40
+ end
41
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-armature
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Parks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-26 00:00:00.000000000 Z
11
+ date: 2018-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -72,14 +72,22 @@ files:
72
72
  - lib/armature.rb
73
73
  - lib/armature/cache.rb
74
74
  - lib/armature/environments.rb
75
- - lib/armature/gitrepo.rb
75
+ - lib/armature/errors.rb
76
76
  - lib/armature/puppetfile.rb
77
+ - lib/armature/ref/base.rb
78
+ - lib/armature/ref/identity.rb
79
+ - lib/armature/ref/immutable.rb
80
+ - lib/armature/ref/mutable.rb
81
+ - lib/armature/repo.rb
82
+ - lib/armature/repo/forge.rb
83
+ - lib/armature/repo/git.rb
77
84
  - lib/armature/run.rb
78
85
  - lib/armature/util.rb
79
86
  - lib/armature/version.rb
80
87
  - puppet-armature.gemspec
81
88
  - test/deploy_test.rb
82
89
  - test/helpers.rb
90
+ - test/puppetfile_test.rb
83
91
  homepage: https://github.com/danielparks/armature
84
92
  licenses:
85
93
  - BSD-2-Clause
@@ -101,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
109
  version: '0'
102
110
  requirements: []
103
111
  rubyforge_project:
104
- rubygems_version: 2.4.5
112
+ rubygems_version: 2.5.2.1
105
113
  signing_key:
106
114
  specification_version: 4
107
115
  summary: Deploy Puppet environments and manage modules
@@ -1,139 +0,0 @@
1
- module Armature
2
- class RefError < StandardError
3
- end
4
-
5
- class GitRepo
6
- attr_reader :name
7
-
8
- def initialize(git_dir, name)
9
- @git_dir = git_dir
10
- @name = name
11
- @fetched = false
12
- @logger = Logging.logger[self]
13
- @ref_cache = {}
14
- end
15
-
16
- def url
17
- @url ||= git("config", "--get", "remote.origin.url").chomp()
18
- end
19
-
20
- def freshen
21
- if ! @fetched
22
- freshen!
23
- true
24
- else
25
- false
26
- end
27
- end
28
-
29
- def freshen!
30
- @logger.info("Fetching from #{url}")
31
- Armature::Util::lock @git_dir, File::LOCK_EX, "fetch" do
32
- git "remote", "update", "--prune"
33
- end
34
- @ref_cache = {}
35
- @fetched = true
36
- end
37
-
38
- def git(*arguments)
39
- # This accepts a hash of options as the last argument
40
- options = if arguments.last.is_a? Hash then arguments.pop else {} end
41
- options = Armature::Util.process_options(options, { :work_dir => nil }, {})
42
-
43
- if options[:work_dir]
44
- work_dir_arguments = [ "--work-tree=" + options[:work_dir] ]
45
- else
46
- work_dir_arguments = []
47
- end
48
-
49
- command = [ "git", "--git-dir=" + @git_dir ] \
50
- + work_dir_arguments \
51
- + arguments
52
-
53
- Armature::Run.command(*command)
54
- end
55
-
56
- def get_branches()
57
- freshen()
58
- data = git("for-each-ref",
59
- "--format", "%(objectname) %(refname)",
60
- "refs/heads")
61
- lines = data.split(/[\r\n]/).reject { |line| line == "" }
62
-
63
- lines.map do |line|
64
- sha, ref = line.split(' ', 2)
65
- name = ref.sub("refs/heads/", "")
66
- @ref_cache[ref] = [:mutable, sha, ref, "branch", name]
67
- name
68
- end
69
- end
70
-
71
- def ref_type(ref)
72
- ref_info(ref)[0]
73
- end
74
-
75
- def ref_identity(ref)
76
- ref_info(ref)[1]
77
- end
78
-
79
- def canonical_ref(ref)
80
- ref_info(ref)[2]
81
- end
82
-
83
- def ref_human_name(ref)
84
- info = ref_info(ref)
85
-
86
- "#{info[3]} '#{info[4]}'"
87
- end
88
-
89
- private
90
-
91
- # Get information about ref, checking the cache first
92
- def ref_info(ref)
93
- if ! @ref_cache[ref]
94
- freshen_ref_cache(ref)
95
- end
96
-
97
- @ref_cache[ref]
98
- end
99
-
100
- # Get information about a ref and put it in the cache
101
- def freshen_ref_cache(ref)
102
- if ref.start_with? "refs/heads/"
103
- @ref_cache[ref] = [:mutable, rev_parse!(ref), ref, "branch", ref.sub("refs/heads/", "")]
104
- elsif ref.start_with? "refs/tags/"
105
- @ref_cache[ref] = [:immutable, rev_parse!(ref), ref, "tag", ref.sub("refs/tags/", "")]
106
- elsif ref.start_with? "refs/"
107
- @ref_cache[ref] = [:mutable, rev_parse!(ref), ref, "ref", ref]
108
- elsif sha = rev_parse("refs/heads/#{ref}")
109
- @ref_cache["refs/heads/#{ref}"] = [:mutable, sha, "refs/heads/#{ref}", "branch", ref]
110
- @ref_cache[ref] = @ref_cache["refs/heads/#{ref}"]
111
- elsif sha = rev_parse("refs/tags/#{ref}")
112
- @ref_cache["refs/tags/#{ref}"] = [:immutable, sha, "refs/tags/#{ref}", "tag", ref]
113
- @ref_cache[ref] = @ref_cache["refs/tags/#{ref}"]
114
- elsif sha = rev_parse(ref)
115
- if sha == ref
116
- @ref_cache[ref] = [:identity, sha, ref, "revision", ref]
117
- else
118
- @ref_cache[ref] = [:mutable, sha, ref, "ref", ref]
119
- end
120
- else
121
- raise RefError.new("no such ref '#{ref}' in repo '#{url}'")
122
- end
123
- end
124
-
125
- # Get the sha for a ref, or nil if it doesn't exist
126
- def rev_parse(ref)
127
- rev_parse!(ref)
128
- rescue RefError
129
- nil
130
- end
131
-
132
- # Get the sha for a ref, or raise if it doesn't exist
133
- def rev_parse!(ref)
134
- git("rev-parse", "--verify", "#{ref}^{commit}").chomp
135
- rescue Armature::Run::CommandFailureError
136
- raise RefError.new("no such ref '#{ref}' in repo '#{url}'")
137
- end
138
- end
139
- end