Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support git repo on local filesystem
Instead of using GitHub, you can now point Clickistrano at a git repo in the local filesystem. This is only particularly useful if you use your own private server for Git shared repo hosting, and can also practically use that server to run Clickistrano.
- Loading branch information
Mat Brown
committed
Jan 5, 2010
1 parent
965e146
commit 7e899e4
Showing
5 changed files
with
86 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,40 +1,28 @@ | |||
require 'fileutils' | require 'fileutils' | ||
|
|
||
class ConfigPuller | module ConfigPuller | ||
ConfigRequestError = Class.new(StandardError) | autoload :Github, File.join(File.dirname(__FILE__), 'config_puller', 'github') | ||
autoload :Local, File.join(File.dirname(__FILE__), 'config_puller', 'local') | |||
|
|
||
def initialize(config) | class <<self | ||
@config = config | def [](name) | ||
end | const_get(name.split("_").map { |part| part.capitalize }.join) | ||
|
|||
def pull(files, branch) | |||
http = Net::HTTP.new('github.com', 443) | |||
http.use_ssl = true | |||
files.each do |path| | |||
request_path = "/#{account}/#{repository}/raw/#{branch}/#{path}?login=#{account}&token=#{token}" | |||
puts request_path | |||
response = http.get(request_path) | |||
if response.code == '200' | |||
file_path = "caproot/#{path}" | |||
FileUtils.mkdir_p(File.dirname(file_path)) | |||
File.open(file_path, 'w') { |f| f << response.body } | |||
else | |||
raise ConfigRequestError, "Got response code #{response.code} when requesting #{request_path}" | |||
end | |||
end | end | ||
end | end | ||
|
|
||
private | class Abstract | ||
ConfigRequestError = Class.new(StandardError) | |||
|
|
||
def repository | def initialize(config) | ||
@config['repository'] | @config = config | ||
end | end | ||
|
|
||
def account | private | ||
@config['account'] | |||
end | |||
|
|
||
def token | def write_file(path, contents) | ||
@config['token'] | file_path = File.join('caproot', path) | ||
FileUtils.mkdir_p(File.dirname(file_path)) | |||
File.open(file_path, 'w') { |f| f << contents } | |||
end | |||
end | end | ||
end | end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,32 @@ | |||
module ConfigPuller | |||
class Github < Abstract | |||
def pull(files, branch) | |||
http = Net::HTTP.new('github.com', 443) | |||
http.use_ssl = true | |||
files.each do |path| | |||
request_path = "/#{account}/#{repository}/raw/#{branch}/#{path}?login=#{account}&token=#{token}" | |||
puts request_path | |||
response = http.get(request_path) | |||
if response.code == '200' | |||
write_file(response.body) | |||
else | |||
raise ConfigRequestError, "Got response code #{response.code} when requesting #{request_path}" | |||
end | |||
end | |||
end | |||
|
|||
private | |||
|
|||
def repository | |||
@config['repository'] | |||
end | |||
|
|||
def account | |||
@config['account'] | |||
end | |||
|
|||
def token | |||
@config['token'] | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,26 @@ | |||
using_gems = false | |||
begin | |||
require 'grit' | |||
rescue LoadError => e | |||
raise(e) if using_gems | |||
using_gems = true | |||
retry | |||
end | |||
|
|||
module ConfigPuller | |||
class Local < Abstract | |||
def pull(files, branch) | |||
repo = Grit::Repo.new(repository) | |||
commit = repo.get_head(branch).commit | |||
files.each do |path| | |||
write_file(path, (repo.tree(commit.id) / path).data) | |||
end | |||
end | |||
|
|||
private | |||
|
|||
def repository | |||
@config['repository'] | |||
end | |||
end | |||
end |