class Crashbreak::GithubIntegrationService

Public Class Methods

new(error_hash) click to toggle source
# File lib/crashbreak/github_integration_service.rb, line 3
def initialize(error_hash)
  @error_id = error_hash['id']
  @error_deploy_revision = error_hash['deploy_revision']
end

Public Instance Methods

create_pull_request() click to toggle source
# File lib/crashbreak/github_integration_service.rb, line 18
def create_pull_request
  client.create_pull_request(repo_name, development_branch_name, error_branch_name.gsub('heads/', ''), "Crashbreak - fix for error #{@error_id}", '')
end
push_test() click to toggle source
# File lib/crashbreak/github_integration_service.rb, line 8
def push_test
  create_branch(branch_sha)
  create_test_file
end
remove_test() click to toggle source
# File lib/crashbreak/github_integration_service.rb, line 13
def remove_test
  client.delete_contents(repo_name, file_path, "Remove test for error #{@error_id}",
                         test_file_sha, branch: "refs/#{error_branch_name}")
end

Private Instance Methods

branch_sha() click to toggle source
# File lib/crashbreak/github_integration_service.rb, line 24
def branch_sha
  @branch_sha ||= begin
    if @error_deploy_revision
      client.commit(repo_name, @error_deploy_revision).sha rescue repo_sha
    else
      repo_sha
    end
  end
end
client() click to toggle source
# File lib/crashbreak/github_integration_service.rb, line 56
def client
  @client ||= Octokit::Client.new(login: Crashbreak.configure.github_login, password: Crashbreak.configure.github_password)
end
create_branch(sha) click to toggle source
# File lib/crashbreak/github_integration_service.rb, line 42
def create_branch(sha)
  client.create_ref repo_name, error_branch_name, sha
end
create_test_file() click to toggle source
# File lib/crashbreak/github_integration_service.rb, line 46
def create_test_file
  client.create_contents repo_name, file_path, "Add test file for error #{@error_id}",
                         file_content, { branch: "refs/#{error_branch_name}" }
end
development_branch_name() click to toggle source
# File lib/crashbreak/github_integration_service.rb, line 72
def development_branch_name
  Crashbreak.configure.github_development_branch
end
error_branch_name() click to toggle source
# File lib/crashbreak/github_integration_service.rb, line 64
def error_branch_name
  "heads/crashbreak-error-#{@error_id}"
end
file_content() click to toggle source
# File lib/crashbreak/github_integration_service.rb, line 51
def file_content
  test_file_content = File.read(Crashbreak.configurator.request_spec_template_path)
  test_file_content.gsub('<%= error_id %>', @error_id.to_s)
end
file_path() click to toggle source
# File lib/crashbreak/github_integration_service.rb, line 68
def file_path
  Crashbreak.configure.request_spec_file_path
end
repo_name() click to toggle source
# File lib/crashbreak/github_integration_service.rb, line 60
def repo_name
  Crashbreak.configure.github_repo_name
end
repo_sha() click to toggle source
# File lib/crashbreak/github_integration_service.rb, line 34
def repo_sha
  client.ref(repo_name, 'heads/master').object.sha
end
test_file_sha() click to toggle source
# File lib/crashbreak/github_integration_service.rb, line 38
def test_file_sha
  @test_file_sha ||= client.contents(repo_name, path: file_path, ref: error_branch_name).sha
end