Add heroku config
This commit is contained in:
parent
ad15be2e16
commit
d4058130e4
|
@ -0,0 +1,86 @@
|
||||||
|
module VagrantPlugins
|
||||||
|
module HerokuPush
|
||||||
|
class Config < Vagrant.plugin("2", :config)
|
||||||
|
# The name of the Heroku application to push to.
|
||||||
|
# @return [String]
|
||||||
|
attr_accessor :app
|
||||||
|
|
||||||
|
# The base directory with file contents to upload. By default this
|
||||||
|
# is the same directory as the Vagrantfile, but you can specify this
|
||||||
|
# if you have a `src` folder or `bin` folder or some other folder
|
||||||
|
# you want to upload. This directory must be a git repository.
|
||||||
|
# @return [String]
|
||||||
|
attr_accessor :dir
|
||||||
|
|
||||||
|
# The path to the git binary to shell out to. This usually is only set for
|
||||||
|
# debugging/development. If not set, the git bin will be searched for
|
||||||
|
# in the PATH.
|
||||||
|
# @return [String]
|
||||||
|
attr_accessor :git_bin
|
||||||
|
|
||||||
|
# The Git remote to push to (default: "heroku").
|
||||||
|
# @return [String]
|
||||||
|
attr_accessor :remote
|
||||||
|
|
||||||
|
# The Git branch to push to (default: "master").
|
||||||
|
# @return [String]
|
||||||
|
attr_accessor :branch
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
@app = UNSET_VALUE
|
||||||
|
@dir = UNSET_VALUE
|
||||||
|
|
||||||
|
@git_bin = UNSET_VALUE
|
||||||
|
@remote = UNSET_VALUE
|
||||||
|
@branch = UNSET_VALUE
|
||||||
|
end
|
||||||
|
|
||||||
|
def finalize!
|
||||||
|
@app = nil if @app == UNSET_VALUE
|
||||||
|
@dir = "." if @dir == UNSET_VALUE
|
||||||
|
|
||||||
|
@git_bin = "git" if @git_bin == UNSET_VALUE
|
||||||
|
@remote = "heroku" if @remote == UNSET_VALUE
|
||||||
|
@branch = "master" if @branch == UNSET_VALUE
|
||||||
|
end
|
||||||
|
|
||||||
|
def validate(machine)
|
||||||
|
errors = _detected_errors
|
||||||
|
|
||||||
|
if missing?(@dir)
|
||||||
|
errors << I18n.t("heroku_push.errors.missing_attribute",
|
||||||
|
attribute: "dir",
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
if missing?(@git_bin)
|
||||||
|
errors << I18n.t("heroku_push.errors.missing_attribute",
|
||||||
|
attribute: "git_bin",
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
if missing?(@remote)
|
||||||
|
errors << I18n.t("heroku_push.errors.missing_attribute",
|
||||||
|
attribute: "remote",
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
if missing?(@branch)
|
||||||
|
errors << I18n.t("heroku_push.errors.missing_attribute",
|
||||||
|
attribute: "branch",
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
{ "Heroku push" => errors }
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# Determine if the given string is "missing" (blank)
|
||||||
|
# @return [true, false]
|
||||||
|
def missing?(obj)
|
||||||
|
obj.to_s.strip.empty?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,30 @@
|
||||||
|
en:
|
||||||
|
heroku_push:
|
||||||
|
errors:
|
||||||
|
command_failed: |-
|
||||||
|
The following command exited with a non-zero exit status:
|
||||||
|
|
||||||
|
%{cmd}
|
||||||
|
|
||||||
|
stdout: %{stdout}
|
||||||
|
stderr: %{stderr}
|
||||||
|
git_not_found: |-
|
||||||
|
The Git binary '%{bin}' could not be found. Please ensure you
|
||||||
|
have downloaded and installed the latest version of Git:
|
||||||
|
|
||||||
|
http://git-scm.com/downloads
|
||||||
|
missing_attribute: |-
|
||||||
|
Missing required attribute '%{attribute}'. The Vagrant Heroku Push
|
||||||
|
plugin requires you set this attribute. Please set this attribute in
|
||||||
|
your Vagrantfile, for example:
|
||||||
|
|
||||||
|
config.push.define "heroku" do |push|
|
||||||
|
push.%{attribute} = "..."
|
||||||
|
end
|
||||||
|
not_a_git_repo: |-
|
||||||
|
The following path is not a valid Git repository:
|
||||||
|
|
||||||
|
%{path}
|
||||||
|
|
||||||
|
Please ensure you are working in the correct directory. In order to use
|
||||||
|
the Vagrant Heroku Push plugin, you must have a git repository.
|
|
@ -0,0 +1,117 @@
|
||||||
|
require_relative "../../../base"
|
||||||
|
|
||||||
|
require Vagrant.source_root.join("plugins/pushes/heroku/config")
|
||||||
|
|
||||||
|
describe VagrantPlugins::HerokuPush::Config do
|
||||||
|
include_context "unit"
|
||||||
|
|
||||||
|
before(:all) do
|
||||||
|
I18n.load_path << Vagrant.source_root.join("plugins/pushes/heroku/locales/en.yml")
|
||||||
|
I18n.reload!
|
||||||
|
end
|
||||||
|
|
||||||
|
subject { described_class.new }
|
||||||
|
|
||||||
|
let(:machine) { double("machine") }
|
||||||
|
|
||||||
|
describe "#app" do
|
||||||
|
it "defaults to nil" do
|
||||||
|
subject.finalize!
|
||||||
|
expect(subject.app).to be(nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#dir" do
|
||||||
|
it "defaults to ." do
|
||||||
|
subject.finalize!
|
||||||
|
expect(subject.dir).to eq(".")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#git_bin" do
|
||||||
|
it "defaults to git" do
|
||||||
|
subject.finalize!
|
||||||
|
expect(subject.git_bin).to eq("git")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#remote" do
|
||||||
|
it "defaults to git" do
|
||||||
|
subject.finalize!
|
||||||
|
expect(subject.remote).to eq("heroku")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#branch" do
|
||||||
|
it "defaults to git" do
|
||||||
|
subject.finalize!
|
||||||
|
expect(subject.branch).to eq("master")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#validate" do
|
||||||
|
before do
|
||||||
|
allow(machine).to receive(:env)
|
||||||
|
.and_return(double("env",
|
||||||
|
root_path: "",
|
||||||
|
))
|
||||||
|
|
||||||
|
subject.app = "bacon"
|
||||||
|
subject.dir = "."
|
||||||
|
subject.git_bin = "git"
|
||||||
|
subject.remote = "heroku"
|
||||||
|
subject.branch = "master"
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:result) { subject.validate(machine) }
|
||||||
|
let(:errors) { result["Heroku push"] }
|
||||||
|
|
||||||
|
context "when the app is missing" do
|
||||||
|
it "does not return an error" do
|
||||||
|
subject.app = ""
|
||||||
|
subject.finalize!
|
||||||
|
expect(errors).to be_empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when the git_bin is missing" do
|
||||||
|
it "returns an error" do
|
||||||
|
subject.git_bin = ""
|
||||||
|
subject.finalize!
|
||||||
|
expect(errors).to include(I18n.t("heroku_push.errors.missing_attribute",
|
||||||
|
attribute: "git_bin",
|
||||||
|
))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when the remote is missing" do
|
||||||
|
it "returns an error" do
|
||||||
|
subject.remote = ""
|
||||||
|
subject.finalize!
|
||||||
|
expect(errors).to include(I18n.t("heroku_push.errors.missing_attribute",
|
||||||
|
attribute: "remote",
|
||||||
|
))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when the branch is missing" do
|
||||||
|
it "returns an error" do
|
||||||
|
subject.branch = ""
|
||||||
|
subject.finalize!
|
||||||
|
expect(errors).to include(I18n.t("heroku_push.errors.missing_attribute",
|
||||||
|
attribute: "branch",
|
||||||
|
))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when the dir is missing" do
|
||||||
|
it "returns an error" do
|
||||||
|
subject.dir = ""
|
||||||
|
subject.finalize!
|
||||||
|
expect(errors).to include(I18n.t("heroku_push.errors.missing_attribute",
|
||||||
|
attribute: "dir",
|
||||||
|
))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue