mirror of
https://github.com/zhigang1992/boxen.git
synced 2026-01-12 22:46:11 +08:00
Add Config#reponame
This commit is contained in:
@@ -54,6 +54,7 @@ module Boxen
|
||||
:name => config.name,
|
||||
:puppetdir => config.puppetdir,
|
||||
:repodir => config.repodir,
|
||||
:reponame => config.reponame,
|
||||
:srcdir => config.srcdir,
|
||||
:token => config.token,
|
||||
:user => config.user
|
||||
@@ -223,6 +224,26 @@ module Boxen
|
||||
|
||||
attr_writer :repodir
|
||||
|
||||
# The repo on GitHub to use for error reports and automatic
|
||||
# updates, in `owner/repo` format. Default is the `origin` of a
|
||||
# Git repo in `repodir`, if it exists and points at GitHub.
|
||||
# Respects the `BOXEN_REPO_NAME` environment variable.
|
||||
|
||||
def reponame
|
||||
override = @reponame || ENV["BOXEN_REPO_NAME"]
|
||||
return override unless override.nil?
|
||||
|
||||
if File.directory? repodir
|
||||
url = Dir.chdir(repodir) { `git config remote.origin.url`.strip }
|
||||
|
||||
if $?.success? && %r|github\.com[/:]([^/]+/[^/]+)| =~ url
|
||||
@reponame = $1.sub /\.git$/, ""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
attr_writer :reponame
|
||||
|
||||
# The directory where repos live. Default is
|
||||
# `"/Users/#{user}/src"`.
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ require "boxen/config"
|
||||
class BoxenConfigTest < Boxen::Test
|
||||
def setup
|
||||
@config = Boxen::Config.new
|
||||
@config.repodir = "test/fixtures/repo"
|
||||
end
|
||||
|
||||
def test_debug?
|
||||
@@ -100,8 +101,6 @@ def test_initialize
|
||||
end
|
||||
|
||||
def test_projects
|
||||
@config.repodir = "test/fixtures/repo"
|
||||
|
||||
files = Dir["#{@config.repodir}/modules/projects/manifests/*.pp"]
|
||||
assert_equal files.size, @config.projects.size
|
||||
end
|
||||
@@ -116,6 +115,7 @@ def test_initialize
|
||||
end
|
||||
|
||||
def test_repodir
|
||||
@config.repodir = nil
|
||||
assert_equal Dir.pwd, @config.repodir
|
||||
|
||||
@config.repodir = "foo"
|
||||
@@ -123,10 +123,50 @@ def test_initialize
|
||||
end
|
||||
|
||||
def test_repodir_env_var
|
||||
@config.repodir = nil
|
||||
|
||||
ENV.expects(:[]).with("BOXEN_REPO_DIR").returns "foo"
|
||||
assert_equal "foo", @config.repodir
|
||||
end
|
||||
|
||||
def test_reponame
|
||||
@config.reponame = "something/explicit"
|
||||
assert_equal "something/explicit", @config.reponame
|
||||
end
|
||||
|
||||
def test_reponame_env_var
|
||||
ENV.expects(:[]).with("BOXEN_REPO_NAME").returns "env/var"
|
||||
assert_equal "env/var", @config.reponame
|
||||
end
|
||||
|
||||
def test_reponame_git_config
|
||||
@config.expects(:"`").with("git config remote.origin.url").
|
||||
returns "https://github.com/some-org/our-boxen\n"
|
||||
|
||||
assert_equal "some-org/our-boxen", @config.reponame
|
||||
end
|
||||
|
||||
def test_reponame_git_config_bad_exit
|
||||
@config.expects(:"`").with("git config remote.origin.url").returns ""
|
||||
$?.expects(:success?).returns false
|
||||
|
||||
assert_nil @config.reponame
|
||||
end
|
||||
|
||||
def test_reponame_git_config_bad_url
|
||||
@config.expects(:"`").with("git config remote.origin.url").
|
||||
returns "https://spumco.com/some-org/our-boxen\n"
|
||||
|
||||
assert_nil @config.reponame
|
||||
end
|
||||
|
||||
def test_reponame_git_config_git_extension
|
||||
@config.expects(:"`").with("git config remote.origin.url").
|
||||
returns "https://github.com/some-org/our-boxen.git\n"
|
||||
|
||||
assert_equal "some-org/our-boxen", @config.reponame
|
||||
end
|
||||
|
||||
def test_srcdir
|
||||
@config.expects(:user).returns "foo"
|
||||
assert_equal "/Users/foo/src", @config.srcdir
|
||||
|
||||
Reference in New Issue
Block a user