boxen 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "boxen"
5
- gem.version = "1.1.2"
5
+ gem.version = "1.2.0"
6
6
  gem.authors = ["John Barnette", "Will Farrington"]
7
7
  gem.email = ["jbarnette@github.com", "wfarr@github.com"]
8
8
  gem.description = "Manage Mac development boxes with love (and Puppet)."
@@ -29,6 +29,14 @@ module Boxen
29
29
  config.password = keychain.password
30
30
  config.token = keychain.token
31
31
 
32
+ if config.enterprise?
33
+ # configure to talk to GitHub Enterprise
34
+ Octokit.configure do |c|
35
+ c.api_endpoint = "#{config.ghurl}/api/v3"
36
+ c.web_endpoint = config.ghurl
37
+ end
38
+ end
39
+
32
40
  yield config if block_given?
33
41
  end
34
42
  end
@@ -39,16 +47,18 @@ module Boxen
39
47
 
40
48
  def self.save(config)
41
49
  attrs = {
42
- :email => config.email,
43
- :fde => config.fde?,
44
- :homedir => config.homedir,
45
- :login => config.login,
46
- :name => config.name,
47
- :puppetdir => config.puppetdir,
48
- :repodir => config.repodir,
49
- :reponame => config.reponame,
50
- :srcdir => config.srcdir,
51
- :user => config.user
50
+ :email => config.email,
51
+ :fde => config.fde?,
52
+ :homedir => config.homedir,
53
+ :login => config.login,
54
+ :name => config.name,
55
+ :puppetdir => config.puppetdir,
56
+ :repodir => config.repodir,
57
+ :reponame => config.reponame,
58
+ :ghurl => config.ghurl,
59
+ :srcdir => config.srcdir,
60
+ :user => config.user,
61
+ :repotemplate => config.repotemplate
52
62
  }
53
63
 
54
64
  file = "#{config.homedir}/config/boxen/defaults.json"
@@ -220,9 +230,12 @@ module Boxen
220
230
  return override unless override.nil?
221
231
 
222
232
  if File.directory? repodir
233
+ ghuri = URI(ghurl)
223
234
  url = Dir.chdir(repodir) { `git config remote.origin.url`.strip }
224
235
 
225
- if $?.success? && %r|github\.com[/:]([^/]+/[^/]+)| =~ url
236
+ # find the path and strip off the .git suffix
237
+ repo_exp = Regexp.new Regexp.escape(ghuri.host) + "[/:]([^/]+/[^/]+)"
238
+ if $?.success? && repo_exp.match(url)
226
239
  @reponame = $1.sub /\.git$/, ""
227
240
  end
228
241
  end
@@ -230,6 +243,29 @@ module Boxen
230
243
 
231
244
  attr_writer :reponame
232
245
 
246
+ # GitHub location (public or GitHub Enterprise)
247
+
248
+ def ghurl
249
+ @ghurl || ENV["BOXEN_GITHUB_ENTERPRISE_URL"] || "https://github.com"
250
+ end
251
+
252
+ attr_writer :ghurl
253
+
254
+ # Repository URL template (required for GitHub Enterprise)
255
+
256
+ def repotemplate
257
+ default = 'https://github.com/%s'
258
+ @repotemplate || ENV["BOXEN_REPO_URL_TEMPLATE"] || default
259
+ end
260
+
261
+ attr_writer :repotemplate
262
+
263
+ # Does this Boxen use a GitHub Enterprise instance?
264
+
265
+ def enterprise?
266
+ ghurl != "https://github.com"
267
+ end
268
+
233
269
  # The directory where repos live. Default is
234
270
  # `"/Users/#{user}/src"`.
235
271
 
@@ -18,7 +18,7 @@ module Boxen
18
18
 
19
19
  def compare_url
20
20
  return unless config.reponame
21
- "https://github.com/#{config.reponame}/compare/#{checkout.sha}...master"
21
+ "#{config.ghurl}/#{config.reponame}/compare/#{checkout.sha}...master"
22
22
  end
23
23
 
24
24
  def hostname
@@ -27,6 +27,14 @@ module Boxen
27
27
  [puppet, "apply", flags, manifest].flatten
28
28
  end
29
29
 
30
+ def hiera_config
31
+ if File.exist? "#{config.repodir}/config/hiera.yaml"
32
+ "#{config.repodir}/config/hiera.yaml"
33
+ else
34
+ "/dev/null"
35
+ end
36
+ end
37
+
30
38
  def flags
31
39
  flags = []
32
40
  root = File.expand_path "../../..", __FILE__
@@ -40,8 +48,7 @@ module Boxen
40
48
  flags << ["--modulepath", "#{config.repodir}/modules:#{config.repodir}/shared"]
41
49
 
42
50
  # Don't ever complain about Hiera to me
43
-
44
- flags << ["--hiera_config", "/dev/null"]
51
+ flags << ["--hiera_config", hiera_config]
45
52
 
46
53
  # Log to both the console and a file.
47
54
 
@@ -82,10 +89,11 @@ module Boxen
82
89
  if File.file? "Puppetfile"
83
90
  librarian = "#{config.repodir}/bin/librarian-puppet"
84
91
 
85
- # Set an environment variable for librarian-puppet's
86
- # github_tarball source strategy.
87
-
88
- ENV["GITHUB_API_TOKEN"] = config.token
92
+ unless config.enterprise?
93
+ # Set an environment variable for librarian-puppet's
94
+ # github_tarball source strategy.
95
+ ENV["GITHUB_API_TOKEN"] = config.token
96
+ end
89
97
 
90
98
  librarian_command = [librarian, "install", "--path=#{config.repodir}/shared"]
91
99
  librarian_command << "--verbose" if config.debug?
@@ -135,6 +135,51 @@ class BoxenConfigTest < Boxen::Test
135
135
  ENV["BOXEN_PUPPET_DIR"] = val
136
136
  end
137
137
 
138
+ def test_ghurl
139
+ @config.ghurl = "https://git.foo.com"
140
+ assert_equal "https://git.foo.com", @config.ghurl
141
+ end
142
+
143
+ def test_ghurl_blank
144
+ assert_equal "https://github.com", @config.ghurl
145
+ end
146
+
147
+ def test_gheurl_env_var
148
+ val = ENV['BOXEN_GITHUB_ENTERPRISE_URL']
149
+
150
+ ENV['BOXEN_GITHUB_ENTERPRISE_URL'] = 'https://git.foo.com'
151
+ assert_equal "https://git.foo.com", @config.ghurl
152
+
153
+ ENV['BOXEN_GITHUB_ENTERPRISE_URL'] = val
154
+ end
155
+
156
+ def test_enterprise_true
157
+ @config.ghurl = "https://git.foo.com"
158
+ assert @config.enterprise?
159
+ end
160
+
161
+ def test_enterprise_false
162
+ assert @config.enterprise? == false
163
+ end
164
+
165
+ def test_repotemplate
166
+ @config.repotemplate = 'https://git.foo.com/%s'
167
+ assert_equal 'https://git.foo.com/%s', @config.repotemplate
168
+ end
169
+
170
+ def test_repotemplate_blank
171
+ assert_equal 'https://github.com/%s', @config.repotemplate
172
+ end
173
+
174
+ def test_repotemplate_env_var
175
+ val = ENV['BOXEN_REPO_URL_TEMPLATE']
176
+
177
+ ENV['BOXEN_REPO_URL_TEMPLATE'] = 'https://git.foo.com/%s'
178
+ assert_equal 'https://git.foo.com/%s', @config.repotemplate
179
+
180
+ ENV['BOXEN_REPO_URL_TEMPLATE'] = val
181
+ end
182
+
138
183
  def test_repodir
139
184
  @config.repodir = nil
140
185
  assert_equal Dir.pwd, @config.repodir
@@ -175,6 +220,29 @@ class BoxenConfigTest < Boxen::Test
175
220
  assert_equal "some-org/our-boxen", @config.reponame
176
221
  end
177
222
 
223
+ def test_reponame_git_config_ghurl
224
+ @config.ghurl = 'https://git.foo.com'
225
+ @config.expects(:"`").with("git config remote.origin.url").
226
+ returns "https://git.foo.com/some-org/our-boxen\n"
227
+
228
+ assert_equal "some-org/our-boxen", @config.reponame
229
+ end
230
+
231
+ def test_reponame_git_config_git_protocol
232
+ @config.expects(:"`").with("git config remote.origin.url").
233
+ returns "git@github.com:some-org/our-boxen.git\n"
234
+
235
+ assert_equal "some-org/our-boxen", @config.reponame
236
+ end
237
+
238
+ def test_reponame_git_config_git_protocol_ghurl
239
+ @config.ghurl = 'https://git.foo.com'
240
+ @config.expects(:"`").with("git config remote.origin.url").
241
+ returns "git@git.foo.com:some-org/our-boxen.git\n"
242
+
243
+ assert_equal "some-org/our-boxen", @config.reponame
244
+ end
245
+
178
246
  def test_reponame_git_config_bad_exit
179
247
  @config.expects(:"`").with("git config remote.origin.url").returns ""
180
248
  $?.expects(:success?).returns false
@@ -190,6 +258,14 @@ class BoxenConfigTest < Boxen::Test
190
258
  assert_nil @config.reponame
191
259
  end
192
260
 
261
+ def test_reponame_git_config_bad_url_git_protocol
262
+ @config.expects(:"`").with("git config remote.origin.url").
263
+ returns "git@spumco.com:some-org/our-boxen.git\n"
264
+ $?.expects(:success?).returns true
265
+
266
+ assert_nil @config.reponame
267
+ end
268
+
193
269
  def test_reponame_git_config_git_extension
194
270
  @config.expects(:"`").with("git config remote.origin.url").
195
271
  returns "https://github.com/some-org/our-boxen.git\n"
@@ -198,6 +274,15 @@ class BoxenConfigTest < Boxen::Test
198
274
  assert_equal "some-org/our-boxen", @config.reponame
199
275
  end
200
276
 
277
+ def test_reponame_git_config_git_extension_ghurl
278
+ @config.ghurl = 'https://git.foo.com'
279
+ @config.expects(:"`").with("git config remote.origin.url").
280
+ returns "https://git.foo.com/some-org/our-boxen.git\n"
281
+ $?.expects(:success?).returns true
282
+
283
+ assert_equal "some-org/our-boxen", @config.reponame
284
+ end
285
+
201
286
  def test_srcdir
202
287
  val = ENV["BOXEN_SRC_DIR"]
203
288
  ENV["BOXEN_SRC_DIR"] = nil
@@ -56,6 +56,16 @@ class BoxenHookGitHubIssueTest < Boxen::Test
56
56
  assert_equal expected, @hook.compare_url
57
57
  end
58
58
 
59
+ def test_compare_url_ghurl
60
+ @config.reponame = repo = 'org/repo'
61
+ @config.ghurl = 'https://git.foo.com'
62
+ sha = 'deadbeef'
63
+ @checkout.expects(:sha).returns(sha)
64
+
65
+ expected = "https://git.foo.com/#{repo}/compare/#{sha}...master"
66
+ assert_equal expected, @hook.compare_url
67
+ end
68
+
59
69
  def test_hostname
60
70
  @hook.expects(:"`").with("hostname").returns "whatevs.local\n"
61
71
  assert_equal "whatevs.local", @hook.hostname
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 1
8
7
  - 2
9
- version: 1.1.2
8
+ - 0
9
+ version: 1.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Barnette
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-04-25 00:00:00 -07:00
18
+ date: 2013-05-11 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency