class Travis::CLI::RepoCommand

def branch(name)

def branch(name)
  repository.branch(name)
end

def build(number_or_id)

def build(number_or_id)
  return super if number_or_id.is_a? Integer
  repository.build(number_or_id)
end

def detect_api_endpoint

def detect_api_endpoint
  if explicit_api_endpoint?
    repo_config['endpoint'] = api_endpoint
  elsif ENV['TRAVIS_ENDPOINT']
    ENV['TRAVIS_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

def detected_endpoint?

def detected_endpoint?
  !explicit_api_endpoint?
end

def find_slug

def find_slug
  git_head   = `git name-rev --name-only HEAD 2>#{IO::NULL}`.chomp
  git_remote = `git config --get branch.#{git_head}.remote 2>#{IO::NULL}`.chomp
  git_remote = 'origin' if git_remote.empty?
  git_info   = `git config --get remote.#{git_remote}.url 2>#{IO::NULL}`.chomp
  $1 if Addressable::URI.parse(git_info).path =~ GIT_REGEX
end

def job(number_or_id)

def job(number_or_id)
  return super if number_or_id.is_a? Integer
  repository.job(number_or_id)
end

def last_build

def last_build
  repository.last_build or error("no build yet for #{slug}")
end

def repo_config

def repo_config
  config['repos'] ||= {}
  config['repos'][slug] ||= {}
end

def repository

def repository
  repo(slug)
rescue Travis::Client::NotFound
  error "repository not known to #{api_endpoint}: #{color(slug, :important)}"
end

def save_travis_config(file = travis_yaml)

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

def setup

def setup
  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 <repo-name>)" 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

def travis_config

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)

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