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.
-
#pr_equal_spefic_branch?(pr) ⇒ Boolean
public method for check if pr belong to user specified branch if the pr belong to the branch continue tests otherwise just skip tests without setting any status.
-
#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? ⇒ 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
164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/gitarro/backend.rb', line 164 def initialize(option = nil) @options = option.nil? ? OptParser.new. : option # each options will generate a object variable dinamically @options.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(@options) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
160 161 162 |
# File 'lib/gitarro/backend.rb', line 160 def client @client end |
#gbexec ⇒ Object (readonly)
Returns the value of attribute gbexec.
160 161 162 |
# File 'lib/gitarro/backend.rb', line 160 def gbexec @gbexec end |
#options ⇒ Object
Returns the value of attribute options.
159 160 161 |
# File 'lib/gitarro/backend.rb', line 159 def @options end |
Instance Method Details
#open_newer_prs ⇒ Object
public method for get prs opened and matching the changed_since condition
190 191 192 193 194 195 196 |
# File 'lib/gitarro/backend.rb', line 190 def open_newer_prs prs = @client.pull_requests(@repo, state: 'open').select do |pr| pr_last_update_less_than(pr, @options[:changed_since]) end print_pr_resume(prs) prs end |
#pr_equal_spefic_branch?(pr) ⇒ Boolean
public method for check if pr belong to user specified branch if the pr belong to the branch continue tests otherwise just skip tests without setting any status
179 180 181 182 183 184 185 186 |
# File 'lib/gitarro/backend.rb', line 179 def pr_equal_spefic_branch?(pr) return true if @branch.nil? return true if @branch == pr.base.ref puts "branch \"#{pr.base.ref}\" should match github-branch \"#{@branch}\" (given) !!!" puts "skipping tests !!!" false end |
#retrigger_check(pr) ⇒ Object
public for retrigger the test
199 200 201 202 203 204 205 206 207 |
# File 'lib/gitarro/backend.rb', line 199 def retrigger_check(pr) return unless retrigger_needed?(pr) create_status(pr, 'pending') print_test_required gbexec.export_pr_data(pr) 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.
250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/gitarro/backend.rb', line 250 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
235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/gitarro/backend.rb', line 235 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 gbexec.export_pr_data(pr) exit(0) if @check launch_test_and_setup_status(pr) == 'success' ? exit(0) : exit(1) end |
#triggered_by_pr_number? ⇒ Boolean
public always rerun tests against the pr number if this exists
210 211 212 213 214 215 216 217 218 |
# File 'lib/gitarro/backend.rb', line 210 def triggered_by_pr_number? return false if @pr_number.nil? pr_on_number = @client.pull_request(@repo, @pr_number) puts "Got triggered by PR_NUMBER OPTION, rerunning on #{@pr_number}" print_test_required gbexec.export_pr_data(pr) launch_test_and_setup_status(pr_on_number) == 'success' ? exit(0) : exit(1) end |
#unreviewed_new_pr?(pr, comm_st) ⇒ Boolean
220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/gitarro/backend.rb', line 220 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 gbexec.export_pr_data(pr) return false if @check launch_test_and_setup_status(pr) == 'success' ? exit(0) : exit(1) end |