Class: Larrow::Runner::Vcs::Github

Inherits:
Base
  • Object
show all
Defined in:
lib/larrow/runner/vcs/github.rb

Constant Summary collapse

URL_TEMPLATE =
'https://raw.githubusercontent.com/%s/%s/%s/%s'

Instance Attribute Summary collapse

Attributes inherited from Base

#larrow_file

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Github

url sample: [email protected]:fsword/larrow-qingcloud.git github.com/fsword/larrow-qingcloud.git



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/larrow/runner/vcs/github.rb', line 11

def initialize url
  self.branch = 'master'
  case url
  when /git@github\.com:(.+)\/(.+)\.git/
    self.organize = $1
    self.name     = $2
  when /http.:\/\/github.com\/(.+)\/(.+)\.git/
    self.organize = $1
    self.name     = $2
  end
end

Instance Attribute Details

#branchObject

Returns the value of attribute branch.



7
8
9
# File 'lib/larrow/runner/vcs/github.rb', line 7

def branch
  @branch
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/larrow/runner/vcs/github.rb', line 7

def name
  @name
end

#organizeObject

Returns the value of attribute organize.



7
8
9
# File 'lib/larrow/runner/vcs/github.rb', line 7

def organize
  @organize
end

Instance Method Details

#formatted_urlObject



23
24
25
# File 'lib/larrow/runner/vcs/github.rb', line 23

def formatted_url
  '[email protected]:%s/%s.git' % [organize, name]
end

#get(filename) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/larrow/runner/vcs/github.rb', line 27

def get filename
  url = URL_TEMPLATE % [organize, name, branch, filename]
  resp = Faraday.get(url)
  case resp.status
  when 200
    resp.body
  when 404
    nil
  else
    raise resp.body
  end
end

#update_source(node, target_dir) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/larrow/runner/vcs/github.rb', line 40

def update_source node, target_dir
  template = ["git clone ",
              "--depth 1",
              "http://github.com/%s/%s.git",
              "-b %s %s"].join(' ')
  cmd = template % [organize, name, branch, target_dir]
  node.execute cmd
end