Class: Backend

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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



128
129
130
131
132
133
134
135
136
137
138
# File 'lib/gitarro/backend.rb', line 128

def initialize(option = nil)
  @options = option.nil? ? OptParser.new.cmdline_options : 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

#clientObject

Returns the value of attribute client.



124
125
126
# File 'lib/gitarro/backend.rb', line 124

def client
  @client
end

#gbexecObject

Returns the value of attribute gbexec.



124
125
126
# File 'lib/gitarro/backend.rb', line 124

def gbexec
  @gbexec
end

#optionsObject

Returns the value of attribute options.



124
125
126
# File 'lib/gitarro/backend.rb', line 124

def options
  @options
end

Instance Method Details

#open_newer_prsObject

public method for get prs opened and matching the changed_since condition



142
143
144
145
146
147
148
# File 'lib/gitarro/backend.rb', line 142

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

#retrigger_check(pr) ⇒ Object

public for retrigger the test



151
152
153
154
155
156
157
# File 'lib/gitarro/backend.rb', line 151

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.

Returns:

  • (Boolean)


191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/gitarro/backend.rb', line 191

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

Returns:

  • (Boolean)


178
179
180
181
182
183
184
185
186
187
# File 'lib/gitarro/backend.rb', line 178

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

Returns:

  • (Boolean)


160
161
162
163
164
165
# File 'lib/gitarro/backend.rb', line 160

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

Returns:

  • (Boolean)


167
168
169
170
171
172
173
174
175
176
# File 'lib/gitarro/backend.rb', line 167

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