Class: Bellows::Gerrit

Inherits:
Object
  • Object
show all
Defined in:
lib/bellows/gerrit.rb

Class Method Summary collapse

Class Method Details

.comment(revision, message, verify_vote = 0) ⇒ Object



36
37
38
# File 'lib/bellows/gerrit.rb', line 36

def self.comment(revision, message, verify_vote=0)
  Gerrit.run_cmd(%{review --verified #{verify_vote} -m \"'#{message}'\" #{revision}})
end

.reviews(project, status = "open", branch = "master") ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bellows/gerrit.rb', line 16

def self.reviews(project, status="open", branch="master")
  # Assume projects without a slash are 'openstack' org projects
  #if not x =~ /.*\/.*/ then
  #  project = "openstack/#{project}"
  #end
  reviews = []
  out=Gerrit.run_cmd(%{query status:#{status} project:#{project} branch:#{branch} limit:500 --current-patch-set --format JSON})
  out.each_line do |line|
    data = JSON.parse(line)
    if data['project'] and data['project'] == "#{project}" and data['branch'] and data['branch'] == branch
      if block_given?
        yield data
      else
        reviews << data 
      end
    end
  end
  reviews
end

.run_cmd(command) ⇒ Object



7
8
9
# File 'lib/bellows/gerrit.rb', line 7

def self.run_cmd(command)
  return %x{ssh review gerrit #{command}}
end

.stream_events(type = nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/bellows/gerrit.rb', line 40

def self.stream_events(type=nil)

  PTY.spawn stream_events_cmd do |read, write, pid|
    loop do
      begin
        data = JSON.parse(read.gets)
        if type.nil? or data['type'] == type then
          yield data
        end
      rescue
        break
      end
    end
  end

end

.stream_events_cmdObject

defined here so we can easily stub out for testing



12
13
14
# File 'lib/bellows/gerrit.rb', line 12

def self.stream_events_cmd
  return "ssh review gerrit stream-events"
end