lib/travis/cli/repo_command.rb in travis-1.2.8 vs lib/travis/cli/repo_command.rb in travis-1.3.0
- old
+ new
@@ -1,12 +1,13 @@
require 'travis/cli'
+require 'yaml'
module Travis
module CLI
class RepoCommand < ApiCommand
GIT_REGEX = %r{^(?:https://|git://|git@)github\.com[:/](.*/.+?)(\.git)?$}
- on('-r', '--repo SLUG') { |c, slug| c.slug = slug }
+ on('-r', '--repo SLUG', 'repository to use (will try to detect from current git clone)') { |c, slug| c.slug = slug }
attr_accessor :slug
abstract
def setup
@@ -65,9 +66,34 @@
Travis::Client::ORG_URI
rescue GH::Error
Travis::Client::PRO_URI
end
end
+ end
+
+ def travis_config
+ @travis_config ||= begin
+ payload = YAML.load_file(travis_yaml)
+ payload.respond_to?(:to_hash) ? payload.to_hash : {}
+ end
+ end
+
+ def travis_yaml(dir = Dir.pwd)
+ path = File.expand_path('.travis.yml', dir)
+ if File.exist? path
+ path
+ else
+ parent = File.expand_path('..', dir)
+ error "no .travis.yml found" if parent == dir
+ travis_yaml(parent)
+ end
+ end
+
+ def save_travis_config
+ yaml = travis_config.to_yaml
+ yaml.gsub! /^(\s+)('on'|true):/, "\\1on:"
+ yaml.gsub! /\A---\n/, ''
+ File.write(travis_yaml, yaml)
end
end
end
end