Class: HockeyGerrit

Inherits:
Object
  • Object
show all
Defined in:
lib/hockey_gerrit.rb,
lib/hockey_gerrit/version.rb

Constant Summary collapse

VERSION =
'0.0.4'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#changeObject

Returns the value of attribute change.



5
6
7
# File 'lib/hockey_gerrit.rb', line 5

def change
  @change
end

#logObject

Returns the value of attribute log.



5
6
7
# File 'lib/hockey_gerrit.rb', line 5

def log
  @log
end

#log_lineObject

Returns the value of attribute log_line.



5
6
7
# File 'lib/hockey_gerrit.rb', line 5

def log_line
  @log_line
end

#output_fileObject

Returns the value of attribute output_file.



5
6
7
# File 'lib/hockey_gerrit.rb', line 5

def output_file
  @output_file
end

#patchObject

Returns the value of attribute patch.



5
6
7
# File 'lib/hockey_gerrit.rb', line 5

def patch
  @patch
end

Instance Method Details

#assign_logObject



13
14
15
16
# File 'lib/hockey_gerrit.rb', line 13

def assign_log
  @log = `git log --reverse -1 --format="%an: %s"`
  raise 'log command failed' unless $CHILD_STATUS.success?
end

#change_lineObject



26
27
28
29
30
31
# File 'lib/hockey_gerrit.rb', line 26

def change_line
  raise 'Change empty' if change.empty?
  raise 'Patch empty' if patch.empty?
  raise 'Log empty' if log.empty?
  @log_line = "g#{change},#{patch}\n#{log}"
end

#changes(gerrit) ⇒ Object



6
7
8
9
10
11
# File 'lib/hockey_gerrit.rb', line 6

def changes(gerrit)
  raise 'No line from Gerrit provided' if gerrit.empty?
  gerrit_split = gerrit.split('/')
  raise 'ENV GERRIT_REFSPEC has invalid format' unless gerrit_split.size >= 2
  @change, @patch = gerrit_split[-2..-1]
end

#delete_fileObject



22
23
24
# File 'lib/hockey_gerrit.rb', line 22

def delete_file
  File.delete(output_file)
end

#writeObject



33
34
35
36
37
38
39
40
# File 'lib/hockey_gerrit.rb', line 33

def write
  @output_file = 'changelog.md'
  raise 'ENV GERRIT_REFSPEC not defined' unless ENV['GERRIT_REFSPEC']
  changes(ENV['GERRIT_REFSPEC'])
  assign_log
  change_line
  write_file
end

#write_fileObject



18
19
20
# File 'lib/hockey_gerrit.rb', line 18

def write_file
  File.write(output_file, log_line)
end