Class: Pullermann

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#comment_failureObject

Returns the value of attribute comment_failure.



3
4
5
# File 'lib/pullermann/pullermann.rb', line 3

def comment_failure
  @comment_failure
end

#comment_successObject

Returns the value of attribute comment_success.



3
4
5
# File 'lib/pullermann/pullermann.rb', line 3

def comment_success
  @comment_success
end

#exec_blockObject

Returns the value of attribute exec_block.



3
4
5
# File 'lib/pullermann/pullermann.rb', line 3

def exec_block
  @exec_block
end

#loggerObject

Returns the value of attribute logger.



3
4
5
# File 'lib/pullermann/pullermann.rb', line 3

def logger
  @logger
end

#passwordObject

Returns the value of attribute password.



3
4
5
# File 'lib/pullermann/pullermann.rb', line 3

def password
  @password
end

#password_failObject

Returns the value of attribute password_fail.



3
4
5
# File 'lib/pullermann/pullermann.rb', line 3

def password_fail
  @password_fail
end

#prepare_blockObject

Returns the value of attribute prepare_block.



3
4
5
# File 'lib/pullermann/pullermann.rb', line 3

def prepare_block
  @prepare_block
end

#rerun_on_source_changeObject

Returns the value of attribute rerun_on_source_change.



3
4
5
# File 'lib/pullermann/pullermann.rb', line 3

def rerun_on_source_change
  @rerun_on_source_change
end

#rerun_on_target_changeObject

Returns the value of attribute rerun_on_target_change.



3
4
5
# File 'lib/pullermann/pullermann.rb', line 3

def rerun_on_target_change
  @rerun_on_target_change
end

#reuse_commentsObject

Returns the value of attribute reuse_comments.



3
4
5
# File 'lib/pullermann/pullermann.rb', line 3

def reuse_comments
  @reuse_comments
end

#status_failureObject

Returns the value of attribute status_failure.



3
4
5
# File 'lib/pullermann/pullermann.rb', line 3

def status_failure
  @status_failure
end

#status_pendingObject

Returns the value of attribute status_pending.



3
4
5
# File 'lib/pullermann/pullermann.rb', line 3

def status_pending
  @status_pending
end

#status_successObject

Returns the value of attribute status_success.



3
4
5
# File 'lib/pullermann/pullermann.rb', line 3

def status_success
  @status_success
end

#successObject

Returns the value of attribute success.



3
4
5
# File 'lib/pullermann/pullermann.rb', line 3

def success
  @success
end

#usernameObject

Returns the value of attribute username.



3
4
5
# File 'lib/pullermann/pullermann.rb', line 3

def username
  @username
end

#username_failObject

Returns the value of attribute username_fail.



3
4
5
# File 'lib/pullermann/pullermann.rb', line 3

def username_fail
  @username_fail
end

Class Method Details

.runObject

The main Pullermann task. Call this to run your code.



35
36
37
# File 'lib/pullermann/pullermann.rb', line 35

def self.run
  main_instance.run
end

.setup {|main_instance| ... } ⇒ Object

Allow configuration blocks being passed to Pullermann. See the README.md for examples on how to call this method.

Yields:

  • (main_instance)


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

def self.setup
  yield main_instance
end

Instance Method Details

#execution(&block) ⇒ Object



30
31
32
# File 'lib/pullermann/pullermann.rb', line 30

def execution(&block)
  self.exec_block = block
end

#preparation(&block) ⇒ Object



26
27
28
# File 'lib/pullermann/pullermann.rb', line 26

def preparation(&block)
  self.prepare_block = block
end

#runObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/pullermann/pullermann.rb', line 39

def run
  # Populate variables and setup environment.
  configure
  begin
    self.prepare_block.call
  rescue Exception => e
    @log.error "Preparation block raised an exception: #{e}"
  end
  # Loop through all 'open' pull requests.
  selected_requests = pull_requests.select do |request|
    @request = request
    # Jump to next iteration if source and/or target didn't change since last run.
    next unless run_necessary?
    set_status_on_github
    remove_comment unless self.reuse_comments
    true
  end
  # Run code on all selected requests.
  selected_requests.each do |request|
    @request = request
    @log.info "Running for request ##{@request.id}."
    # GitHub always creates a merge commit for its 'Merge Button'.
    # Pullermann reuses that commit to run the code on it.
    switch_branch_to_merged_state
    # Run specified code (i.e. tests) for the project.
    begin
      self.exec_block.call
      # Unless self.success has already been set manually,
      # the success/failure is determined by the last command's return code.
      self.success ||= ($? == 0)
    rescue Exception => e
      @log.error "Execution block raised an exception: #{e}"
      self.success = false
    end
    switch_branch_back
    comment_on_github
    set_status_on_github
    self.success = nil
  end
end