Class: Houston::Adapters::VersionControl::GitAdapter

Inherits:
Object
  • Object
show all
Defined in:
app/adapters/houston/adapters/version_control/git_adapter.rb,
app/adapters/houston/adapters/version_control/git_adapter/repo.rb,
app/adapters/houston/adapters/version_control/git_adapter/github_repo.rb,
app/adapters/houston/adapters/version_control/git_adapter/remote_repo.rb

Defined Under Namespace

Classes: GithubRepo, RemoteRepo, Repo

Class Method Summary collapse

Class Method Details

.build(project, location) ⇒ Object



21
22
23
# File 'app/adapters/houston/adapters/version_control/git_adapter.rb', line 21

def build(project, location)
  connect location, project.version_control_temp_path
end

.clone!(origin_uri, local_path, async: false) ⇒ Object



61
62
63
64
65
66
67
# File 'app/adapters/houston/adapters/version_control/git_adapter.rb', line 61

def clone!(origin_uri, local_path, async: false)
  if async
    Houston.async { _clone!(origin_uri, local_path, true) }
  else
    _clone!(origin_uri, local_path, false)
  end
end

.connect(location, temp_path) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/adapters/houston/adapters/version_control/git_adapter.rb', line 25

def connect(location, temp_path)
  location = Addressable::URI.parse(location.to_s)
  return Houston::Adapters::VersionControl::NullRepo if location.blank?

  connection = connect_to_repo! location, temp_path

  return self::Repo.new(connection) unless location.absolute?
  return self::GithubRepo.new(connection, location) if /github/ === location
  return self::RemoteRepo.new(connection, location)
rescue Rugged::RepositoryError, Rugged::OSError, Rugged::SshError
  Rails.logger.warn "\e[33m[git_adapter] #{$!.class}: #{$!.message}\e[0m"
  Houston::Adapters::VersionControl::NullRepo
end

.connect_to_repo!(repo_uri, temp_path) ⇒ Object



47
48
49
50
# File 'app/adapters/houston/adapters/version_control/git_adapter.rb', line 47

def connect_to_repo!(repo_uri, temp_path)
  git_path = get_local_path_to_repo(repo_uri, temp_path.to_s)
  Rugged::Repository.new(git_path)
end

.credentialsObject



69
70
71
72
73
74
# File 'app/adapters/houston/adapters/version_control/git_adapter.rb', line 69

def credentials
  Rugged::Credentials::SshKey.new(
    username: SSH_USERNAME,
    privatekey: SSH_PRIVATEKEY,
    publickey: SSH_PUBLICKEY)
end

.errors_with_parameters(project, location) ⇒ Object

Public API for a VersionControl::Adapter ————————————————————————- #



12
13
14
15
16
17
18
19
# File 'app/adapters/houston/adapters/version_control/git_adapter.rb', line 12

def errors_with_parameters(project, location)
  location = Addressable::URI.parse(location.to_s)
  connect_to_repo!(location, project.version_control_temp_path)
  {}
rescue Rugged::RepositoryError, Rugged::OSError, Rugged::SshError
  Rails.logger.error "#{$!.class.name}: #{$!.message}\n  #{$!.backtrace.take(7).join("\n  ")}"
  { git_location: ["might not be right. Houston can't seem to connect to it."] }
end

.get_local_path_to_repo(repo_uri, temp_path) ⇒ Object



52
53
54
55
56
57
58
59
# File 'app/adapters/houston/adapters/version_control/git_adapter.rb', line 52

def get_local_path_to_repo(repo_uri, temp_path)
  if repo_uri.absolute?
    clone!(repo_uri, temp_path) unless File.exists?(temp_path)
    temp_path
  else
    repo_uri.to_s
  end
end

.parametersObject



39
40
41
# File 'app/adapters/houston/adapters/version_control/git_adapter.rb', line 39

def parameters
  [:git_location]
end