class Travis::CLI::RepoCommand
Constants
- GIT_REGEX
- TRAVIS
Attributes
slug[RW]
Public Instance Methods
repository()
click to toggle source
# File lib/travis/cli/repo_command.rb, line 27 def repository repo(slug) rescue Travis::Client::NotFound error "repository not known to #{api_endpoint}: #{color(slug, :important)}" end
setup()
click to toggle source
Calls superclass method
Travis::CLI::ApiCommand#setup
# File lib/travis/cli/repo_command.rb, line 18 def setup setup_enterprise error "Can't figure out GitHub repo name. Ensure you're in the repo directory, or specify the repo name via the -r option (e.g. travis <command> -r <owner>/<repo>)" unless self.slug ||= find_slug error "GitHub repo name is invalid, it should be on the form 'owner/repo'" unless self.slug.include?("/") self.api_endpoint = detect_api_endpoint super repository.load # makes sure we actually have access to the repo end
Private Instance Methods
branch(name)
click to toggle source
# File lib/travis/cli/repo_command.rb, line 45 def branch(name) repository.branch(name) end
build(number_or_id)
click to toggle source
Calls superclass method
Travis::Client::Methods#build
# File lib/travis/cli/repo_command.rb, line 35 def build(number_or_id) return super if number_or_id.is_a? Integer repository.build(number_or_id) end
detect_api_endpoint()
click to toggle source
# File lib/travis/cli/repo_command.rb, line 110 def detect_api_endpoint if explicit_api_endpoint? or enterprise? repo_config['endpoint'] = api_endpoint elsif ENV['TRAVIS_ENDPOINT'] ENV['TRAVIS_ENDPOINT'] elsif config['default_endpoint'] and config['default_endpoint'] !~ TRAVIS repo_config['endpoint'] ||= config['default_endpoint'] else repo_config['endpoint'] ||= begin load_gh GH.head("/repos/#{slug}") Travis::Client::ORG_URI rescue GH::Error Travis::Client::PRO_URI end end end
detect_slug()
click to toggle source
# File lib/travis/cli/repo_command.rb, line 64 def detect_slug git_head = %x`git name-rev --name-only HEAD 2>#{IO::NULL}`.chomp git_remote = %x`git config --get branch.#{git_head}.remote 2>#{IO::NULL}`.chomp git_remote = 'origin' if git_remote.empty? git_info = %x`git ls-remote --get-url #{git_remote} 2>#{IO::NULL}`.chomp if parse_remote(git_info) =~ GIT_REGEX detectected_slug = $1 if interactive? if agree("Detected repository as #{color(detectected_slug, :info)}, is this correct? ") { |q| q.default = 'yes' } detectected_slug else ask("Repository slug (owner/name): ") { |q| q.default = detectected_slug } end else info "detected repository as #{color(detectected_slug, :bold)}" detectected_slug end end end
detected_endpoint?()
click to toggle source
# File lib/travis/cli/repo_command.rb, line 53 def detected_endpoint? !explicit_api_endpoint? end
find_slug()
click to toggle source
# File lib/travis/cli/repo_command.rb, line 57 def find_slug load_slug || begin slug = detect_slug interactive? ? store_slug(slug) : slug if slug end end
job(number_or_id)
click to toggle source
Calls superclass method
Travis::Client::Methods#job
# File lib/travis/cli/repo_command.rb, line 40 def job(number_or_id) return super if number_or_id.is_a? Integer repository.job(number_or_id) end
last_build()
click to toggle source
# File lib/travis/cli/repo_command.rb, line 49 def last_build repository.last_build or error("no build yet for #{slug}") end
load_slug()
click to toggle source
# File lib/travis/cli/repo_command.rb, line 95 def load_slug stored = %x`git config --get travis.slug`.chomp stored unless stored.empty? end
parse_remote(url)
click to toggle source
# File lib/travis/cli/repo_command.rb, line 85 def parse_remote(url) if url =~ /^git@[^:]+:/ path = url.split(':').last path = "/#{path}" unless path.start_with?('/') path else URI.parse(url).path end end
repo_config()
click to toggle source
# File lib/travis/cli/repo_command.rb, line 105 def repo_config config['repos'] ||= {} config['repos'][slug] ||= {} end
save_travis_config(file = travis_yaml)
click to toggle source
# File lib/travis/cli/repo_command.rb, line 146 def save_travis_config(file = travis_yaml) yaml = travis_config.to_yaml yaml.gsub! /^(\s+)('on'|true):/, "\\1on:" yaml.gsub! /\A---\s*\n/, '' File.write(file, yaml) end
store_slug(value)
click to toggle source
# File lib/travis/cli/repo_command.rb, line 100 def store_slug(value) %x`git config travis.slug #{value}` if value value end
travis_config()
click to toggle source
# File lib/travis/cli/repo_command.rb, line 128 def travis_config @travis_config ||= begin payload = YAML.load_file(travis_yaml) payload.respond_to?(:to_hash) ? payload.to_hash : {} end end
travis_yaml(dir = Dir.pwd)
click to toggle source
# File lib/travis/cli/repo_command.rb, line 135 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