Class: Travis::CLI::Repos

Inherits:
ApiCommand show all
Defined in:
lib/travis/cli/repos.rb

Constant Summary

Constants inherited from Command

Command::DAY, Command::HOUR, Command::MINUTE, Command::WEEK

Constants included from Tools::Assets

Tools::Assets::BASE

Instance Attribute Summary

Attributes inherited from ApiCommand

#enterprise_name, #session

Attributes inherited from Command

#arguments, #config, #debug, #force_interactive, #formatter, #input, #output

Instance Method Summary collapse

Methods inherited from ApiCommand

#authenticate, #detected_endpoint?, #endpoint_config, #enterprise?, #initialize, #org?, #pro?, #setup, #sync

Methods included from Travis::Client::Methods

#access_token, #access_token=, #account, #accounts, #api_endpoint, #api_endpoint=, #artifact, #broadcasts, #build, #cancel, #explicit_api_endpoint?, #github_auth, #hooks, #job, #lint, #listen, #repo, #repos, #restart, #user

Methods inherited from Command

abstract, abstract?, #check_completion, #check_ruby, #check_version, command_name, #command_name, #debug?, description, #execute, #help, #info, #initialize, #last_check, #on_signal, #parse, #say, #setup, skip, subcommands, #terminal, #time, #usage, #usage_for, #write_to

Methods included from Tools::Assets

#asset, #asset_path

Methods included from Parser

#new, #on, #on_initialize

Constructor Details

This class inherits a constructor from Travis::CLI::ApiCommand

Instance Method Details

#attributes(repo) ⇒ Object



41
42
43
# File 'lib/travis/cli/repos.rb', line 41

def attributes(repo)
  { "active" => repo.active?, "admin" => repo.admin?, "push" => repo.push?, "pull" => repo.pull? }
end

#match?(string) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
# File 'lib/travis/cli/repos.rb', line 45

def match?(string)
  return true if match.nil?
  flags = File::FNM_PATHNAME | File::FNM_DOTMATCH
  flags |= File::FNM_EXTGLOB if defined? File::FNM_EXTGLOB
  File.fnmatch?(match, string, flags)
end

#repositoriesObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/travis/cli/repos.rb', line 27

def repositories
  @repositories ||= begin
    repos = session.hooks.concat(user.repositories).uniq
    session.preload(repos).sort_by(&:slug).select do |repo|
      next false unless match? repo.slug
      next false unless active.nil? or repo.active?    == active
      next false unless owner.nil?  or repo.owner_name == owner
      next false unless name.nil?   or repo.name       == name
      next false unless admin.nil?  or repo.admin?     == admin
      true
    end
  end
end

#runObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/travis/cli/repos.rb', line 15

def run
  repositories.each do |repo|
    next say(repo.slug) unless interactive?
    state_color = repo.active? ? :green : :yellow
    say color(repo.slug, [:bold, state_color]) + " "
    say color("(" << attributes(repo).map { |n,v| "#{n}: #{v ? "yes" : "no"}" }.join(", ") << ")", state_color)
    description = repo.description.lines.first.chomp unless repo.description.to_s.empty?
    say "Description: #{description || "???"}"
    empty_line unless repo == repositories.last
  end
end