-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Luke Chadwick
committed
Jul 26, 2011
1 parent
75f90ca
commit dc89365
Showing
7 changed files
with
103 additions
and
58 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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module Offline | ||
class App < Thor | ||
include Offline::Helpers | ||
|
||
desc "mirror GITHUB_USER", "mirror the repositories of a given github user" | ||
method_option :only, :type => :array, :required => false | ||
method_option :without, :type => :array, :required => false | ||
method_option :password, :type => :string, :required => false, :aliases => '-p' | ||
method_option :output, :type => :string, :default => 'mirror', :required => false, :aliases => '-o' | ||
def mirror(user) | ||
mirror_directory = "#{options[:output]}/#{user}" | ||
Pathname.new(mirror_directory).mkpath | ||
reaper = Offline::Github.new(user, options[:password]) | ||
all_repos = reaper.repositories.map {|r| r["name"] } | ||
repos = all_repos & (options[:only] || all_repos) # TODO: Might be a better way of doing this | ||
repos = (repos) - Array(options[:without]) | ||
reaper.repositories.each do |repo| | ||
next unless repos.include?(repo["name"]) | ||
puts "Mirroring: #{repo["name"]}" | ||
target_directory = Pathname.new("#{mirror_directory}/#{repo["name"]}.git") | ||
if target_directory.exist? | ||
run("cd #{target_directory} && git fetch") | ||
else | ||
run("git clone --mirror git@github.com:#{repo["owner"]}/#{repo["name"]}.git #{target_directory}") | ||
end | ||
puts "" # blank line | ||
end | ||
end | ||
|
||
# TODO: Dry up | ||
# Yes I did just copy and paste | ||
desc "clone GITHUB_USER", "clone the repositories of a given github user" | ||
method_option :only, :type => :array, :required => false | ||
method_option :without, :type => :array, :required => false | ||
method_option :password, :type => :string, :required => false, :aliases => '-p' | ||
method_option :output, :type => :string, :default => 'clone', :required => false, :aliases => '-o' | ||
def clone(user) | ||
clone_directory = "#{options[:output]}/#{user}" | ||
Pathname.new(clone_directory).mkpath | ||
reaper = Offline::Github.new(user, options[:password]) | ||
all_repos = reaper.repositories.map {|r| r["name"] } | ||
repos = all_repos & (options[:only] || all_repos) # TODO: Might be a better way of doing this | ||
repos = (repos) - Array(options[:without]) | ||
reaper.repositories.each do |repo| | ||
next unless repos.include?(repo["name"]) | ||
puts "Cloning: #{repo["name"]}" | ||
target_directory = Pathname.new("#{clone_directory}/#{repo["name"]}") | ||
if target_directory.exist? | ||
run("cd #{target_directory} && git fetch") | ||
else | ||
run("git clone git@github.com:#{repo["owner"]}/#{repo["name"]}.git #{target_directory}") | ||
end | ||
puts "" # blank line | ||
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Offline | ||
module Github | ||
class Base | ||
include Offline::Helpers | ||
|
||
def initialize(user, options) | ||
|
||
end | ||
|
||
private | ||
def clone(source, target="", mirror=false) | ||
run("git clone #{"--mirror" if mirror} #{source} #{target}") | ||
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Offline | ||
module Github | ||
class Clone < Base | ||
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Offline | ||
module Github | ||
class Mirror < Base | ||
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'spec_helper' | ||
|
||
describe Offline::App do | ||
context "Thor" do | ||
it "should respond to start" do | ||
Offline::App.should respond_to(:start) | ||
end | ||
end | ||
|
||
context "#mirror" do | ||
it "should respond to start" do | ||
Offline::App.should respond_to(:start) | ||
end | ||
end | ||
end |