class TestExecutor

This is a private class, which has the task to execute/run tests called by Backend

Public Class Methods

new(options) click to toggle source
# File lib/gitarro/backend.rb, line 78
def initialize(options)
  @options = options
  @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)
end

Public Instance Methods

export_pr_data(pr) click to toggle source
# File lib/gitarro/backend.rb, line 101
def export_pr_data(pr)
    export_pr_variables(pr)
    export_pr_data_to_simple_file(pr)
    export_pr_data_to_json_file(pr)
end
pr_test(pr) click to toggle source

this will clone the repo and execute the tests

# File lib/gitarro/backend.rb, line 89
def pr_test(pr)
  clone_repo(@noshallow, pr)
  # do valid tests and return the result
  run_script
end
run_script() click to toggle source

run validation script for validating the PR.

# File lib/gitarro/backend.rb, line 96
def run_script
  puts `#{@test_file}`
  $CHILD_STATUS.exitstatus.nonzero? ? 'failure' : 'success'
end

Private Instance Methods

clone_repo(noshallow, pr) click to toggle source
# File lib/gitarro/backend.rb, line 135
def clone_repo(noshallow, pr)
  shallow = GitShallowClone.new(@git_dir, pr, @options)
  # by default we use always shallow clone
  unless noshallow
    shallow.clone
    return
  end
  # this is for using the merging to ref
  full_clone(pr)
end
export_pr_data_to_json_file(pr) click to toggle source
# File lib/gitarro/backend.rb, line 120
def export_pr_data_to_json_file(pr)
  pr = pr.to_hash
  pr[:files] = @client.pull_request_files(@repo, pr[:number]).map(&:to_h)
  File.open('.gitarro_pr.json', 'w') do |file|
     file.write(JSON.generate(pr))
  end
end
export_pr_data_to_simple_file(pr) click to toggle source
# File lib/gitarro/backend.rb, line 109
def export_pr_data_to_simple_file(pr)
  # save this file in local dir where gitarro is executed.
  # This part is kept for compatibility purposes
  File.open('.gitarro_vars', 'w') do |file|
     file.write("GITARRO_PR_AUTHOR: #{pr.head.user.login}\n" \
     "GITARRO_PR_TITLE:  #{pr.title}\n" \
     "GITARRO_PR_NUMBER: #{pr.number}\n" \
     "GITARRO_PR_TARGET_REPO: #{@repo}\n")
  end
end
export_pr_variables(pr) click to toggle source
# File lib/gitarro/backend.rb, line 128
def export_pr_variables(pr)
  ENV['GITARRO_PR_AUTHOR'] = pr.head.user.login.to_s
  ENV['GITARRO_PR_TITLE'] = pr.title.to_s
  ENV['GITARRO_PR_NUMBER'] = pr.number.to_s
  ENV['GITARRO_PR_TARGET_REPO'] = @repo
end
full_clone(pr) click to toggle source
# File lib/gitarro/backend.rb, line 146
def full_clone(pr)
  git = GitOp.new(@git_dir, pr, @options)
  git.merge_pr_totarget(pr.base.ref, pr.head.ref)
  git.del_pr_branch(pr.base.ref, pr.head.ref)
end