class Twigg::Command::Gerrit

The “gerrit” subcommand can be used to conveniently initialize a set of repos and keep them up-to-date.

Private Instance Methods

address(project = nil, port: true, protocol: true) click to toggle source

Returns a Gerrit address.

Examples:

address('foo')
=> ssh://jimmy@gerrit.example.com:29418/foo.git
address(port: false, protocol: false)
=> jimmy@gerrit.example.com
# File lib/twigg-gerrit/command/gerrit.rb, line 38
def address(project = nil, port: true, protocol: true)
  [].tap do |address|
    address << 'ssh://' if protocol
    address << "#{Config.gerrit.user}@#{Config.gerrit.host}"
    address << ":#{Config.gerrit.port}" if port
    address << "/#{project}.git" if project
  end.join
end
projects() click to toggle source

Returns the list of all projects hosted within a Gerrit instance.

# File lib/twigg-gerrit/command/gerrit.rb, line 48
def projects
  @projects ||= begin
    port         = Config.gerrit.port.to_s
    user_at_host = address(port: false, protocol: false)
    command      = ['ssh', '-p', port, user_at_host, 'gerrit', 'ls-projects']

    # Don't bother redirecting stderr; let it slip through to the user,
    # where it may provide useful feedback (such as "Permission denied
    # (publickey)." or similar).
    IO.popen(command, 'r') { |io| io.read }.split.tap do
      die 'failed to retrieve project list' unless $?.success?
    end
  end
end
stats() click to toggle source

Shows a list of open changes, ordered by last update date (descending).

# File lib/twigg-gerrit/command/gerrit.rb, line 15
def stats
  changes = ::Twigg::Gerrit::Change.changes

  puts "Open changes (#{changes.count})"
  changes.map do |change|
    puts "  #%-6d %s [%s] %s" % [
      change.change_id,
      change.subject,
      change.full_name,
      age(change.last_updated_on),
    ]
  end
end
sub_subcommands() click to toggle source
Calls superclass method
# File lib/twigg-gerrit/command/gerrit.rb, line 10
def sub_subcommands
  super + ['stats']
end