offline 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +5 -0
- data/bin/offline +1 -58
- data/lib/offline.rb +2 -0
- data/lib/offline/app.rb +51 -0
- data/lib/offline/github.rb +10 -2
- data/lib/offline/github/base.rb +16 -0
- data/lib/offline/github/clone.rb +6 -0
- data/lib/offline/github/mirror.rb +6 -0
- data/lib/offline/version.rb +1 -1
- data/offline.gemspec +1 -0
- data/spec/offline/app_spec.rb +15 -0
- data/spec/offline/github_spec.rb +19 -5
- metadata +64 -52
data/.travis.yml
ADDED
data/bin/offline
CHANGED
@@ -3,63 +3,6 @@ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
|
3
3
|
|
4
4
|
require "rubygems" # ruby1.9 doesn't "require" it though
|
5
5
|
require "bundler/setup"
|
6
|
-
require "thor"
|
7
6
|
require 'offline'
|
8
7
|
|
9
|
-
|
10
|
-
include Offline::Helpers
|
11
|
-
|
12
|
-
desc "mirror GITHUB_USER", "mirror the repositories of a given github user"
|
13
|
-
method_option :only, :type => :array, :required => false
|
14
|
-
method_option :without, :type => :array, :required => false
|
15
|
-
method_option :password, :type => :string, :required => false, :aliases => '-p'
|
16
|
-
method_option :output, :type => :string, :default => 'mirror', :required => false, :aliases => '-o'
|
17
|
-
def mirror(user)
|
18
|
-
mirror_directory = "#{options[:output]}/#{user}"
|
19
|
-
Pathname.new(mirror_directory).mkpath
|
20
|
-
reaper = Offline::Github.new(user, options[:password])
|
21
|
-
all_repos = reaper.repositories.map {|r| r["name"] }
|
22
|
-
repos = all_repos & (options[:only] || all_repos) # TODO: Might be a better way of doing this
|
23
|
-
repos = (repos) - Array(options[:without])
|
24
|
-
reaper.repositories.each do |repo|
|
25
|
-
next unless repos.include?(repo["name"])
|
26
|
-
puts "Mirroring: #{repo["name"]}"
|
27
|
-
target_directory = Pathname.new("#{mirror_directory}/#{repo["name"]}.git")
|
28
|
-
if target_directory.exist?
|
29
|
-
run("cd #{target_directory} && git fetch")
|
30
|
-
else
|
31
|
-
run("git clone --mirror git@github.com:#{repo["owner"]}/#{repo["name"]}.git #{target_directory}")
|
32
|
-
end
|
33
|
-
puts "" # blank line
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# TODO: Dry up
|
38
|
-
# Yes I did just copy and paste
|
39
|
-
desc "clone GITHUB_USER", "clone the repositories of a given github user"
|
40
|
-
method_option :only, :type => :array, :required => false
|
41
|
-
method_option :without, :type => :array, :required => false
|
42
|
-
method_option :password, :type => :string, :required => false, :aliases => '-p'
|
43
|
-
method_option :output, :type => :string, :default => 'clone', :required => false, :aliases => '-o'
|
44
|
-
def clone(user)
|
45
|
-
clone_directory = "#{options[:output]}/#{user}"
|
46
|
-
Pathname.new(clone_directory).mkpath
|
47
|
-
reaper = Offline::Github.new(user, options[:password])
|
48
|
-
all_repos = reaper.repositories.map {|r| r["name"] }
|
49
|
-
repos = all_repos & (options[:only] || all_repos) # TODO: Might be a better way of doing this
|
50
|
-
repos = (repos) - Array(options[:without])
|
51
|
-
reaper.repositories.each do |repo|
|
52
|
-
next unless repos.include?(repo["name"])
|
53
|
-
puts "Cloning: #{repo["name"]}"
|
54
|
-
target_directory = Pathname.new("#{clone_directory}/#{repo["name"]}")
|
55
|
-
if target_directory.exist?
|
56
|
-
run("cd #{target_directory} && git fetch")
|
57
|
-
else
|
58
|
-
run("git clone git@github.com:#{repo["owner"]}/#{repo["name"]}.git #{target_directory}")
|
59
|
-
end
|
60
|
-
puts "" # blank line
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
OfflineApp.start
|
8
|
+
Offline::App.start
|
data/lib/offline.rb
CHANGED
data/lib/offline/app.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module Offline
|
2
|
+
class App < Thor
|
3
|
+
include Offline::Helpers
|
4
|
+
|
5
|
+
desc "mirror GITHUB_REPOSITORY_OWNER", "mirror the repositories of a given github user"
|
6
|
+
method_option :only, :type => :array, :required => false
|
7
|
+
method_option :without, :type => :array, :required => false
|
8
|
+
method_option :"private-only", :type => :boolean, :aliases => '-P'
|
9
|
+
method_option :username, :type => :string, :required => false, :aliases => '-u'
|
10
|
+
method_option :password, :type => :string, :required => false, :aliases => '-p'
|
11
|
+
method_option :output, :type => :string, :default => 'mirror', :required => false, :aliases => '-o'
|
12
|
+
def mirror(owner)
|
13
|
+
do_clone(owner, :mirror, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "clone GITHUB_REPOSITORY_OWNER", "clones the repositories of a given github user"
|
17
|
+
method_option :only, :type => :array, :required => false
|
18
|
+
method_option :without, :type => :array, :required => false
|
19
|
+
method_option :"private-only", :type => :boolean, :aliases => '-P'
|
20
|
+
method_option :username, :type => :string, :required => false, :aliases => '-u'
|
21
|
+
method_option :password, :type => :string, :required => false, :aliases => '-p'
|
22
|
+
method_option :output, :type => :string, :default => 'clone', :required => false, :aliases => '-o'
|
23
|
+
def mirror(owner)
|
24
|
+
do_clone(owner, :clone, options)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def do_clone(owner, clone_type, options)
|
29
|
+
privacy = options["private-only"] ? :"private-only" : :all
|
30
|
+
mirror_directory = "#{options[:output]}/#{owner}"
|
31
|
+
Pathname.new(mirror_directory).mkpath
|
32
|
+
user = options[:username] || owner
|
33
|
+
reaper = Offline::Github.new(user, options[:password])
|
34
|
+
all_repos = reaper.repositories(owner, privacy).map {|r| r["name"] }
|
35
|
+
repos = all_repos & (options[:only] || all_repos) # TODO: Might be a better way of doing this
|
36
|
+
repos = (repos) - Array(options[:without])
|
37
|
+
|
38
|
+
reaper.repositories(owner, privacy).each do |repo|
|
39
|
+
next unless repos.include?(repo["name"])
|
40
|
+
puts "#{clone_type}: #{repo["name"]}"
|
41
|
+
target_directory = Pathname.new("#{mirror_directory}/#{repo["name"]}.git")
|
42
|
+
if target_directory.exist?
|
43
|
+
run("cd #{target_directory} && git fetch")
|
44
|
+
else
|
45
|
+
run("git clone #{"--mirror" if clone_type==:mirror} git@github.com:#{repo["owner"]}/#{repo["name"]}.git #{target_directory}")
|
46
|
+
end
|
47
|
+
puts "" # blank line
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/offline/github.rb
CHANGED
@@ -9,11 +9,19 @@ module Offline
|
|
9
9
|
@username = user
|
10
10
|
if pass
|
11
11
|
self.class.basic_auth user, pass
|
12
|
+
if self.class.get("/user/show").parsed_response["error"]=="not authorized"
|
13
|
+
raise Exception.new({"error"=>"not authorized"})
|
14
|
+
end
|
12
15
|
end
|
13
16
|
end
|
14
17
|
|
15
|
-
def repositories
|
16
|
-
|
18
|
+
def repositories(owner=nil, privacy=:all)
|
19
|
+
owner ||= @username
|
20
|
+
repos = self.class.get("/repos/show/#{owner}").parsed_response["repositories"]
|
21
|
+
if privacy==:"private-only"
|
22
|
+
repos = repos.select {|r| r["private"]==true }
|
23
|
+
end
|
24
|
+
repos
|
17
25
|
end
|
18
26
|
end
|
19
27
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Offline
|
2
|
+
module Github
|
3
|
+
class Base
|
4
|
+
include Offline::Helpers
|
5
|
+
|
6
|
+
def initialize(user, options)
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
def clone(source, target="", mirror=false)
|
12
|
+
run("git clone #{"--mirror" if mirror} #{source} #{target}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/offline/version.rb
CHANGED
data/offline.gemspec
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Offline::App do
|
4
|
+
context "Thor" do
|
5
|
+
it "should respond to start" do
|
6
|
+
Offline::App.should respond_to(:start)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
context "#mirror" do
|
11
|
+
it "should respond to start" do
|
12
|
+
Offline::App.should respond_to(:start)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/offline/github_spec.rb
CHANGED
@@ -5,14 +5,28 @@ describe Offline::Github do
|
|
5
5
|
Offline::Github.new('test').username.should == 'test'
|
6
6
|
end
|
7
7
|
|
8
|
-
context "
|
9
|
-
|
10
|
-
|
11
|
-
Offline::Github.should_receive(:get).with("/repos/show/test").and_return(response)
|
8
|
+
context "authenticated user" do
|
9
|
+
it "should fail if I give the wrong password" do
|
10
|
+
expect { Offline::Github.new('vertis', 'password') }.should raise_error
|
12
11
|
end
|
13
|
-
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#repositories" do
|
14
15
|
it "should return a list of repositories" do
|
16
|
+
user_response = mock("response", :parsed_response => {})
|
17
|
+
response = mock("response", :parsed_response => {"repositories" => []})
|
18
|
+
Offline::Github.should_receive(:get).with("/repos/show/test").and_return(response)
|
15
19
|
Offline::Github.new('test').repositories.should == []
|
16
20
|
end
|
21
|
+
|
22
|
+
it "should return only private repositories if requested" do
|
23
|
+
user_response = mock("response", :parsed_response => {})
|
24
|
+
response = mock("response", :parsed_response => {"repositories" => [{"name" => 'public_repo', "private"=>false}, {"name" => 'private_repo', "private"=>true}]})
|
25
|
+
Offline::Github.should_receive(:get).with("/user/show").and_return(user_response)
|
26
|
+
Offline::Github.should_receive(:get).with("/repos/show/test").and_return(response)
|
27
|
+
repos = Offline::Github.new('test', 'password').repositories('test', :"private-only")
|
28
|
+
repos.count.should == 1
|
29
|
+
repos.should == [{"name" => 'private_repo', "private"=>true}]
|
30
|
+
end
|
17
31
|
end
|
18
32
|
end
|
metadata
CHANGED
@@ -1,101 +1,113 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: offline
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.2
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Luke Chadwick
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-09-16 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: httparty
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70275019162960 !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
24
22
|
type: :runtime
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: thor
|
28
23
|
prerelease: false
|
29
|
-
|
24
|
+
version_requirements: *70275019162960
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: thor
|
27
|
+
requirement: &70275019162540 !ruby/object:Gem::Requirement
|
30
28
|
none: false
|
31
|
-
requirements:
|
32
|
-
- -
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version:
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
35
33
|
type: :runtime
|
36
|
-
version_requirements: *id002
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: rspec
|
39
34
|
prerelease: false
|
40
|
-
|
35
|
+
version_requirements: *70275019162540
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &70275019162120 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version:
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
46
44
|
type: :development
|
47
|
-
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70275019162120
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: &70275019161700 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70275019161700
|
48
58
|
description: Tools for working with github
|
49
|
-
email:
|
59
|
+
email:
|
50
60
|
- luke.a.chadwick@gmail.com
|
51
|
-
executables:
|
61
|
+
executables:
|
52
62
|
- offline
|
53
63
|
extensions: []
|
54
|
-
|
55
64
|
extra_rdoc_files: []
|
56
|
-
|
57
|
-
files:
|
65
|
+
files:
|
58
66
|
- .gitignore
|
59
67
|
- .rvmrc
|
68
|
+
- .travis.yml
|
60
69
|
- Gemfile
|
61
70
|
- LICENSE
|
62
71
|
- README.md
|
63
72
|
- Rakefile
|
64
73
|
- bin/offline
|
65
74
|
- lib/offline.rb
|
75
|
+
- lib/offline/app.rb
|
66
76
|
- lib/offline/github.rb
|
77
|
+
- lib/offline/github/base.rb
|
78
|
+
- lib/offline/github/clone.rb
|
79
|
+
- lib/offline/github/mirror.rb
|
67
80
|
- lib/offline/helpers.rb
|
68
81
|
- lib/offline/version.rb
|
69
82
|
- offline.gemspec
|
83
|
+
- spec/offline/app_spec.rb
|
70
84
|
- spec/offline/github_spec.rb
|
71
85
|
- spec/spec_helper.rb
|
72
86
|
homepage: https://github.com/vertis/offline
|
73
87
|
licenses: []
|
74
|
-
|
75
88
|
post_install_message:
|
76
89
|
rdoc_options: []
|
77
|
-
|
78
|
-
require_paths:
|
90
|
+
require_paths:
|
79
91
|
- lib
|
80
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
93
|
none: false
|
82
|
-
requirements:
|
83
|
-
- -
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version:
|
86
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
99
|
none: false
|
88
|
-
requirements:
|
89
|
-
- -
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
version:
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
92
104
|
requirements: []
|
93
|
-
|
94
105
|
rubyforge_project: offline
|
95
|
-
rubygems_version: 1.
|
106
|
+
rubygems_version: 1.8.10
|
96
107
|
signing_key:
|
97
108
|
specification_version: 3
|
98
109
|
summary: Tools for working with github
|
99
|
-
test_files:
|
110
|
+
test_files:
|
111
|
+
- spec/offline/app_spec.rb
|
100
112
|
- spec/offline/github_spec.rb
|
101
113
|
- spec/spec_helper.rb
|