Class: Prophet

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_token_failObject

Returns the value of attribute access_token_fail.



6
7
8
# File 'lib/prophet/prophet.rb', line 6

def access_token_fail
  @access_token_fail
end

#access_token_passObject

Returns the value of attribute access_token_pass.



6
7
8
# File 'lib/prophet/prophet.rb', line 6

def access_token_pass
  @access_token_pass
end

#comment_failureObject

Returns the value of attribute comment_failure.



6
7
8
# File 'lib/prophet/prophet.rb', line 6

def comment_failure
  @comment_failure
end

#comment_successObject

Returns the value of attribute comment_success.



6
7
8
# File 'lib/prophet/prophet.rb', line 6

def comment_success
  @comment_success
end

#disable_commentsObject

Returns the value of attribute disable_comments.



6
7
8
# File 'lib/prophet/prophet.rb', line 6

def disable_comments
  @disable_comments
end

#exec_blockObject

Returns the value of attribute exec_block.



6
7
8
# File 'lib/prophet/prophet.rb', line 6

def exec_block
  @exec_block
end

#loggerObject

Returns the value of attribute logger.



6
7
8
# File 'lib/prophet/prophet.rb', line 6

def logger
  @logger
end

#prepare_blockObject

Returns the value of attribute prepare_block.



6
7
8
# File 'lib/prophet/prophet.rb', line 6

def prepare_block
  @prepare_block
end

#rerun_on_source_changeObject

Returns the value of attribute rerun_on_source_change.



6
7
8
# File 'lib/prophet/prophet.rb', line 6

def rerun_on_source_change
  @rerun_on_source_change
end

#rerun_on_target_changeObject

Returns the value of attribute rerun_on_target_change.



6
7
8
# File 'lib/prophet/prophet.rb', line 6

def rerun_on_target_change
  @rerun_on_target_change
end

#reuse_commentsObject

Returns the value of attribute reuse_comments.



6
7
8
# File 'lib/prophet/prophet.rb', line 6

def reuse_comments
  @reuse_comments
end

#status_contextObject

Returns the value of attribute status_context.



6
7
8
# File 'lib/prophet/prophet.rb', line 6

def status_context
  @status_context
end

#status_failureObject

Returns the value of attribute status_failure.



6
7
8
# File 'lib/prophet/prophet.rb', line 6

def status_failure
  @status_failure
end

#status_pendingObject

Returns the value of attribute status_pending.



6
7
8
# File 'lib/prophet/prophet.rb', line 6

def status_pending
  @status_pending
end

#status_successObject

Returns the value of attribute status_success.



6
7
8
# File 'lib/prophet/prophet.rb', line 6

def status_success
  @status_success
end

#status_target_urlObject

Returns the value of attribute status_target_url.



6
7
8
# File 'lib/prophet/prophet.rb', line 6

def status_target_url
  @status_target_url
end

#successObject

Returns the value of attribute success.



6
7
8
# File 'lib/prophet/prophet.rb', line 6

def success
  @success
end

#username_failObject

Returns the value of attribute username_fail.



6
7
8
# File 'lib/prophet/prophet.rb', line 6

def username_fail
  @username_fail
end

#username_passObject

Returns the value of attribute username_pass.



6
7
8
# File 'lib/prophet/prophet.rb', line 6

def username_pass
  @username_pass
end

Class Method Details

.runObject

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



41
42
43
# File 'lib/prophet/prophet.rb', line 41

def self.run
  main_instance.run
end

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

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

Yields:

  • (main_instance)


28
29
30
# File 'lib/prophet/prophet.rb', line 28

def self.setup
  yield main_instance
end

Instance Method Details

#execution(&block) ⇒ Object



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

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

#preparation(&block) ⇒ Object



32
33
34
# File 'lib/prophet/prophet.rb', line 32

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

#runObject



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
79
80
81
82
83
84
85
86
# File 'lib/prophet/prophet.rb', line 45

def run
  # Populate variables and setup environment.
  configure
  begin
    self.prepare_block.call
  rescue Exception => e
    logger.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
    logger.info "Running for request ##{@request.id}."
    # GitHub always creates a merge commit for its 'Merge Button'.
    # Prophet reuses that commit to run the code on it.
    if 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 (to true/false) manually,
        # the success/failure is determined by the last command's return code.
        self.success = ($CHILD_STATUS && $CHILD_STATUS.exitstatus == 0) if self.success.nil?
      rescue Exception => e
        logger.error "Execution block raised an exception: #{e}"
        self.success = false
      end
      switch_branch_back
      comment_on_github
      set_status_on_github
    end
    self.success = nil
  end
end