Class: Gerrit::Command::List

Inherits:
Base
  • Object
show all
Defined in:
lib/gerrit/command/list.rb

Overview

Show a list of changes matching a specified query.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#execute_command, from_arguments, #initialize, #run

Methods included from Utils

camel_case, commit_hash?, human_time, map_in_parallel, snake_case

Constructor Details

This class inherits a constructor from Gerrit::Command::Base

Class Method Details

.find_changes(client, search_query) ⇒ Object

HACK: We cache the results of this since we may want to reuse the result of the query in other commands (see Command::Submit for an example). We also make this a public class method so other commands can call it.



32
33
34
35
36
# File 'lib/gerrit/command/list.rb', line 32

def self.find_changes(client, search_query)
  @matching_changes ||= {}
  @matching_changes[search_query] =
    client.query_changes(search_query).sort_by { |change| -change['lastUpdated'] }
end

Instance Method Details

#executeObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gerrit/command/list.rb', line 4

def execute
  changes = ui.spinner('Loading ') { self.class.find_changes(client, query) }

  # Display changes in reverse order so that the newest are at the bottom of
  # the table (i.e. the part that will be visible in a console when there is
  # a long list)
  ui.table(header: %w[# CR V Subject Owner Project Updated],
           alignments: [:left, :center, :center, :left, :left, :left, :right],
           padding: [0,1,0,1]) do |t|
    changes.each_with_index.map do |change, index|
      [
        index + 1,
        symbol_for_status('Code-Review', change),
        symbol_for_status('Verified', change),
        change['subject'],
        change['owner']['name'],
        change['project'],
        human_time(Time.at(change['lastUpdated'])),
      ]
    end.reverse.each do |row|
      t << row
    end
  end
end