Class: GithubCheckout
Instance Attribute Summary collapse
Attributes inherited from ScmCheckout
#app, #commit, #name, #settings, #url
Instance Method Summary
collapse
Methods inherited from ScmCheckout
#checkout, #error_file, #is_primary_branch?, #project_path, #register_project, #unlink_error_file, #write_error_file
Methods included from Helpers
sh
Constructor Details
#initialize(app, url, commit = nil) ⇒ GithubCheckout
Returns a new instance of GithubCheckout.
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/scm_checkout.rb', line 94
def initialize(app, url, commit = nil)
super
case url
when Array
self.username, self.project = *url
when %r{^(?:https?|git)://(?:www\.?)?github\.com/([^/]+)/([^/]+?)(?:\.git)?/?$}
self.username, self.project = $1, $2
else
raise InvalidSchemeError
end
self.name = "#{username}/#{project}"
self.commit = primary_branch unless commit
end
|
Instance Attribute Details
#project ⇒ Object
Returns the value of attribute project.
92
93
94
|
# File 'lib/scm_checkout.rb', line 92
def project
@project
end
|
#username ⇒ Object
Returns the value of attribute username.
92
93
94
|
# File 'lib/scm_checkout.rb', line 92
def username
@username
end
|
Instance Method Details
#clear_source_files ⇒ Object
134
135
136
|
# File 'lib/scm_checkout.rb', line 134
def clear_source_files
SourceCleaner.new(repository_path).clean
end
|
#commit=(value) ⇒ Object
108
109
110
111
112
113
114
115
|
# File 'lib/scm_checkout.rb', line 108
def commit=(value)
value = nil if value == ''
if value
value = value[0,6] if value.length == 40
value = value[/\A\s*([a-z0-9.\/-_]+)/i, 1]
end
@commit = value
end
|
#flush_cache ⇒ Object
138
139
140
141
|
# File 'lib/scm_checkout.rb', line 138
def flush_cache
Cache.invalidate("/github", "/github/~#{project[0,1]}",
"/github/#{name}/", "/list/github/#{name}/", "/")
end
|
#fork? ⇒ Boolean
143
144
145
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/scm_checkout.rb', line 143
def fork?
return @is_fork unless @is_fork.nil?
if !File.directory?(File.join(settings.repos, name))
json = JSON.parse(URI.open("https://api.github.com/repos/#{username}/#{project}", &:read))
@is_fork = json["fork"] if json
else
@is_fork = true
end
@is_fork
rescue IOError, OpenURI::HTTPError, Timeout::Error
@is_fork = nil
false
end
|
#primary_branch ⇒ Object
157
158
159
160
|
# File 'lib/scm_checkout.rb', line 157
def primary_branch
File.read(primary_branch_file).strip
rescue Errno::ENOENT
end
|
#remove_project ⇒ Object
121
122
123
124
|
# File 'lib/scm_checkout.rb', line 121
def remove_project
cmd = "rm -rf #{settings.repos}/#{project}/#{username} #{settings.repos}/#{project}"
sh(cmd, title: "Removing #{name}")
end
|
#repository_path ⇒ Object
117
118
119
|
# File 'lib/scm_checkout.rb', line 117
def repository_path
File.join(settings.repos, project, username, commit)
end
|
#run_checkout ⇒ Object
126
127
128
129
130
131
132
|
# File 'lib/scm_checkout.rb', line 126
def run_checkout
return unless run_checkout_git
root_path = File.expand_path(File.join(settings.repos, '..', '..'))
doc_command = "cd #{root_path.inspect} && bundle exec rake docker:doc SOURCE=#{repository_path.inspect}"
sh(doc_command, title: "Building documentation for #{name}", write_error: true) == 0
end
|