Class: ScmCheckout

Inherits:
Object
  • Object
show all
Includes:
Helpers, Skylight::Helpers
Defined in:
lib/scm_checkout.rb,
lib/skylight_instrumentation.rb

Direct Known Subclasses

GithubCheckout

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

sh

Constructor Details

#initialize(app, url, commit = nil) ⇒ ScmCheckout

Returns a new instance of ScmCheckout.



16
17
18
19
20
21
# File 'lib/scm_checkout.rb', line 16

def initialize(app, url, commit = nil)
  self.settings = app.settings
  self.app = app
  self.url = url
  self.commit = commit
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



14
15
16
# File 'lib/scm_checkout.rb', line 14

def app
  @app
end

#commitObject

Returns the value of attribute commit.



14
15
16
# File 'lib/scm_checkout.rb', line 14

def commit
  @commit
end

#nameObject

Returns the value of attribute name.



14
15
16
# File 'lib/scm_checkout.rb', line 14

def name
  @name
end

#settingsObject

Returns the value of attribute settings.



14
15
16
# File 'lib/scm_checkout.rb', line 14

def settings
  @settings
end

#urlObject

Returns the value of attribute url.



14
15
16
# File 'lib/scm_checkout.rb', line 14

def url
  @url
end

Instance Method Details

#checkoutObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/scm_checkout.rb', line 50

def checkout
  unlink_error_file
  if run_checkout && settings.scm_adapter.libraries[name]
    clear_source_files
    register_project
    flush_cache
    true
  else
    remove_project
    false
  end
end

#clear_source_filesObject



81
82
# File 'lib/scm_checkout.rb', line 81

def clear_source_files
end

#error_fileObject



67
68
69
70
71
# File 'lib/scm_checkout.rb', line 67

def error_file
  FileUtils.mkdir_p("#{settings.logdir}/errors")
  @error_file ||=
    "#{settings.logdir}/errors/#{[name.gsub('/', '_'), commit || 'unknown'].join('_')}.error.txt"
end

#flush_cacheObject



84
85
# File 'lib/scm_checkout.rb', line 84

def flush_cache
end

#is_primary_branch?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/scm_checkout.rb', line 46

def is_primary_branch?
  commit == primary_branch
end

#primary_branchObject

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/scm_checkout.rb', line 42

def primary_branch
  raise NotImplementedError
end

#project_pathObject



38
39
40
# File 'lib/scm_checkout.rb', line 38

def project_path
  [name, commit].compact.join('/')
end

#register_projectObject



27
28
29
30
31
32
# File 'lib/scm_checkout.rb', line 27

def register_project
  puts "#{Time.now}: Registering project #{name}"
  unlink_error_file
  app.recent_store.push(settings.scm_adapter.libraries[name])
  puts "#{Time.now}: Adding #{name} to recent projects list"
end

#remove_projectObject



87
88
# File 'lib/scm_checkout.rb', line 87

def remove_project
end

#repository_pathObject



34
35
36
# File 'lib/scm_checkout.rb', line 34

def repository_path
  File.join(settings.repos, name, commit)
end

#run_checkoutObject

Raises:

  • (NotImplementedError)


63
64
65
# File 'lib/scm_checkout.rb', line 63

def run_checkout
  raise NotImplementedError
end


77
78
79
# File 'lib/scm_checkout.rb', line 77

def unlink_error_file
  File.unlink(error_file) if File.file?(error_file)
end

#write_error_file(out) ⇒ Object



73
74
75
# File 'lib/scm_checkout.rb', line 73

def write_error_file(out)
  File.open(error_file, "a") {|f| f.write(out + "\n") }
end