Class: Backend
- Inherits:
-
Object
- Object
- Backend
- Includes:
- CachingOctokit, ChangelogTests, 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
Returns the value of attribute client.
-
#gbexec ⇒ Object
Returns the value of attribute gbexec.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#changelog_active?(pr, comm_st) ⇒ Boolean
FIXME: remove this pub.
-
#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?
Methods included from ChangelogTests
#changelog_changed?, #do_changelog_test, #magic_comment?
Methods included from CachingOctokit
#create_dir_store, #dont_generate_cache?, #generate_cache
Constructor Details
#initialize(option = nil) ⇒ Backend
public method of backend
195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/gitarro/backend.rb', line 195 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 # if changed_since option on, dont generate cache. generate_cache(@cachehttp) Octokit.auto_paginate = true @client = Octokit::Client.new(netrc: true) @gbexec = TestExecutor.new() end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
187 188 189 |
# File 'lib/gitarro/backend.rb', line 187 def client @client end |
#gbexec ⇒ Object
Returns the value of attribute gbexec.
187 188 189 |
# File 'lib/gitarro/backend.rb', line 187 def gbexec @gbexec end |
#options ⇒ Object
Returns the value of attribute options.
187 188 189 |
# File 'lib/gitarro/backend.rb', line 187 def end |
Instance Method Details
#changelog_active?(pr, comm_st) ⇒ Boolean
FIXME: remove this pub. method once changelog test are separated public method, trigger changelogtest if option active
238 239 240 241 242 |
# File 'lib/gitarro/backend.rb', line 238 def changelog_active?(pr, comm_st) return false unless @changelog_test return false unless changelog_changed?(pr, comm_st) true end |
#open_newer_prs ⇒ Object
public method for get prs opened and matching the changed_since condition
211 212 213 214 215 216 217 |
# File 'lib/gitarro/backend.rb', line 211 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
220 221 222 223 224 225 226 |
# File 'lib/gitarro/backend.rb', line 220 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.
269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/gitarro/backend.rb', line 269 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
255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/gitarro/backend.rb', line 255 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 true if changelog_active?(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
229 230 231 232 233 234 |
# File 'lib/gitarro/backend.rb', line 229 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
244 245 246 247 248 249 250 251 252 253 |
# File 'lib/gitarro/backend.rb', line 244 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 |