Class: Backend
- Inherits:
-
Object
- Object
- Backend
- Includes:
- GitHubPrOperations
- Defined in:
- lib/gitarro/backend.rb
Overview
this the main public class is the backend of gitarro, were we execute the tests and so on
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#gbexec ⇒ Object
readonly
Returns the value of attribute gbexec.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(option = nil) ⇒ Backend
constructor
public method of backend.
-
#open_newer_prs ⇒ Object
public method for get prs opened and matching the changed_since condition.
-
#retrigger_check(pr) ⇒ Object
public for retrigger the test.
-
#retriggered_by_comment?(pr_number, context) ⇒ Boolean
this function will check if the PR contains in comment the magic word # for retrigger all the tests.
- #reviewed_pr?(comm_st, pr) ⇒ Boolean
-
#triggered_by_pr_number?(pr) ⇒ Boolean
public always rerun tests against the pr number if this exists.
- #unreviewed_new_pr?(pr, comm_st) ⇒ Boolean
Methods included from GitHubPrOperations
#commit_is_unreviewed?, #context_present?, #create_status, #failed_status?, #pending_pr?, #pr_last_update_less_than, #success_status?
Constructor Details
#initialize(option = nil) ⇒ Backend
public method of backend
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/gitarro/backend.rb', line 129 def initialize(option = nil) = option.nil? ? OptParser.new. : option # each options will generate a object variable dinamically .each do |key, value| instance_variable_set("@#{key}", value) self.class.send(:attr_accessor, key) end Octokit.auto_paginate = true @client = Octokit::Client.new(netrc: true) @gbexec = TestExecutor.new() end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
125 126 127 |
# File 'lib/gitarro/backend.rb', line 125 def client @client end |
#gbexec ⇒ Object (readonly)
Returns the value of attribute gbexec.
125 126 127 |
# File 'lib/gitarro/backend.rb', line 125 def gbexec @gbexec end |
#options ⇒ Object
Returns the value of attribute options.
124 125 126 |
# File 'lib/gitarro/backend.rb', line 124 def end |
Instance Method Details
#open_newer_prs ⇒ Object
public method for get prs opened and matching the changed_since condition
143 144 145 146 147 148 149 |
# File 'lib/gitarro/backend.rb', line 143 def open_newer_prs prs = @client.pull_requests(@repo, state: 'open').select do |pr| pr_last_update_less_than(pr, [:changed_since]) end print_pr_resume(prs) prs end |
#retrigger_check(pr) ⇒ Object
public for retrigger the test
152 153 154 155 156 157 158 |
# File 'lib/gitarro/backend.rb', line 152 def retrigger_check(pr) return unless retrigger_needed?(pr) create_status(pr, 'pending') print_test_required exit 0 if @check launch_test_and_setup_status(pr) == 'success' ? exit(0) : exit(1) end |
#retriggered_by_comment?(pr_number, context) ⇒ Boolean
this function will check if the PR contains in comment the magic word # for retrigger all the tests.
192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/gitarro/backend.rb', line 192 def retriggered_by_comment?(pr_number, context) magic_word_trigger = "gitarro rerun #{context} !!!" # a pr contain always a comments, cannot be nil @client.issue_comments(@repo, pr_number).each do |com| # delete comment otherwise it will be retrigger infinetely if com.body.include? magic_word_trigger @client.delete_comment(@repo, com.id) return true end end false end |
#reviewed_pr?(comm_st, pr) ⇒ Boolean
179 180 181 182 183 184 185 186 187 188 |
# File 'lib/gitarro/backend.rb', line 179 def reviewed_pr?(comm_st, pr) # if PR status is not on pending and the context is not set, # we dont run the tests return false unless context_present?(comm_st) == false || pending_pr?(comm_st) return false unless pr_all_files_type(pr.number, @file_type).any? print_test_required exit(0) if @check launch_test_and_setup_status(pr) end |
#triggered_by_pr_number?(pr) ⇒ Boolean
public always rerun tests against the pr number if this exists
161 162 163 164 165 166 |
# File 'lib/gitarro/backend.rb', line 161 def triggered_by_pr_number?(pr) return false if @pr_number.nil? || @pr_number != pr.number puts "Got triggered by PR_NUMBER OPTION, rerunning on #{@pr_number}" print_test_required launch_test_and_setup_status(pr) end |
#unreviewed_new_pr?(pr, comm_st) ⇒ Boolean
168 169 170 171 172 173 174 175 176 177 |
# File 'lib/gitarro/backend.rb', line 168 def unreviewed_new_pr?(pr, comm_st) return unless commit_is_unreviewed?(comm_st) pr_all_files_type(pr.number, @file_type) return if empty_files_changed_by_pr?(pr) # gb.check is true when there is a job running as scheduler # which doesn't execute the test but trigger another job print_test_required return false if @check launch_test_and_setup_status(pr) end |