github-backup 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +10 -2
- data/bin/github-backup +17 -2
- data/lib/github-backup.rb +40 -10
- metadata +7 -26
data/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Back up your Github repositories locally.
|
|
|
4
4
|
|
|
5
5
|
To install it as a Gem, just run:
|
|
6
6
|
|
|
7
|
-
$
|
|
7
|
+
$ gem install github-backup
|
|
8
8
|
|
|
9
9
|
To use it:
|
|
10
10
|
|
|
@@ -18,13 +18,21 @@ You will need a `~/.gitconfig` file in place with a `[github]` section
|
|
|
18
18
|
|
|
19
19
|
See: http://github.com/guides/tell-git-your-user-name-and-email-address
|
|
20
20
|
|
|
21
|
+
### Specify authentication at the command line
|
|
22
|
+
|
|
23
|
+
If you don't have a `[github]` section set up in your `~/.gitconfig` file, you
|
|
24
|
+
can provide your user name and Github API at the command line.
|
|
25
|
+
|
|
21
26
|
## License
|
|
22
27
|
|
|
23
28
|
MIT License
|
|
24
29
|
|
|
25
30
|
## Author
|
|
26
31
|
|
|
27
|
-
David Dollar
|
|
32
|
+
Created by David Dollar
|
|
33
|
+
|
|
34
|
+
Patches contributed by:
|
|
35
|
+
Gabriel Gilder
|
|
28
36
|
|
|
29
37
|
## Copyright
|
|
30
38
|
|
data/bin/github-backup
CHANGED
|
@@ -4,14 +4,29 @@ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
4
4
|
|
|
5
5
|
require 'octopi'
|
|
6
6
|
require 'github-backup'
|
|
7
|
+
require 'optparse'
|
|
8
|
+
|
|
9
|
+
options = {}
|
|
10
|
+
optionparser = OptionParser.new do |opts|
|
|
11
|
+
opts.banner = "Usage: github-backup [options] username local_backup_root"
|
|
12
|
+
|
|
13
|
+
opts.on("-t", "--token TOKEN", "Github API Token") do |t|
|
|
14
|
+
options[:token] = t
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
opts.on("-u", "--username USER", "Github API Username") do |u|
|
|
18
|
+
options[:login] = u
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
optionparser.parse!
|
|
7
22
|
|
|
8
23
|
unless ARGV.length == 2
|
|
9
|
-
puts
|
|
24
|
+
puts optionparser.help
|
|
10
25
|
exit 1
|
|
11
26
|
end
|
|
12
27
|
|
|
13
28
|
username = ARGV.shift
|
|
14
29
|
root = ARGV.shift
|
|
15
30
|
|
|
16
|
-
backup = Github::Backup.new(username, root)
|
|
31
|
+
backup = Github::Backup.new(username, root, options)
|
|
17
32
|
backup.execute
|
data/lib/github-backup.rb
CHANGED
|
@@ -5,41 +5,71 @@ module Github; end
|
|
|
5
5
|
|
|
6
6
|
class Github::Backup
|
|
7
7
|
|
|
8
|
-
VERSION = "0.
|
|
8
|
+
VERSION = "0.5.0"
|
|
9
9
|
|
|
10
10
|
include Octopi
|
|
11
11
|
|
|
12
12
|
attr_reader :backup_root, :debug, :username
|
|
13
13
|
|
|
14
|
-
def initialize(username, backup_root)
|
|
14
|
+
def initialize(username, backup_root, options = {})
|
|
15
15
|
@username = username
|
|
16
16
|
@backup_root = backup_root
|
|
17
|
+
@options = options
|
|
18
|
+
if (options[:token] && !options[:login])
|
|
19
|
+
options[:login] = @username
|
|
20
|
+
end
|
|
17
21
|
@debug = false
|
|
18
22
|
end
|
|
19
23
|
|
|
20
24
|
def execute
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
repositories = User.find(username).repositories.sort_by { |r| r.name }
|
|
24
|
-
repositories.each do |repository|
|
|
25
|
-
puts "Backing up: #{repository.name}"
|
|
26
|
-
backup_repository repository
|
|
27
|
-
end
|
|
28
|
-
end
|
|
25
|
+
backup_all @options
|
|
26
|
+
|
|
29
27
|
rescue Errno::ENOENT
|
|
30
28
|
puts "Please install git and create a ~/.gitconfig"
|
|
31
29
|
puts " See: http://github.com/guides/tell-git-your-user-name-and-email-address"
|
|
32
30
|
rescue NoMethodError
|
|
33
31
|
puts "Please add a [github] section to your ~/.gitconfig"
|
|
34
32
|
puts " See: http://github.com/guides/tell-git-your-user-name-and-email-address"
|
|
33
|
+
rescue Octopi::APIError => e
|
|
34
|
+
# only handle "Authentication required" errors
|
|
35
|
+
unless (e.message =~ /status 401$/)
|
|
36
|
+
raise e
|
|
37
|
+
end
|
|
38
|
+
puts "Github API authentication failed."
|
|
39
|
+
puts "Please add a [github] section to your ~/.gitconfig"
|
|
40
|
+
puts " See: http://github.com/guides/tell-git-your-user-name-and-email-address"
|
|
41
|
+
puts "Or, use the arguments to authenticate with your username and API token."
|
|
35
42
|
end
|
|
36
43
|
|
|
37
44
|
private ######################################################################
|
|
38
45
|
|
|
46
|
+
def github_authenticate(options={})
|
|
47
|
+
if (options[:login])
|
|
48
|
+
authenticated_with(options) do
|
|
49
|
+
yield
|
|
50
|
+
end
|
|
51
|
+
else
|
|
52
|
+
authenticated do
|
|
53
|
+
yield
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
39
58
|
def backup_directory_for(repository)
|
|
40
59
|
File.join(backup_root, repository.name)
|
|
41
60
|
end
|
|
42
61
|
|
|
62
|
+
def backup_all(options={})
|
|
63
|
+
FileUtils::mkdir_p(backup_root)
|
|
64
|
+
github_authenticate(options) do
|
|
65
|
+
repositories = User.find(username).repositories.sort_by { |r| r.name }
|
|
66
|
+
repositories.each do |repository|
|
|
67
|
+
puts "Backing up: #{repository.name}"
|
|
68
|
+
backup_repository repository
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
43
73
|
def backup_repository(repository)
|
|
44
74
|
if File.exists?(backup_directory_for(repository))
|
|
45
75
|
backup_repository_incremental(repository)
|
metadata
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: github-backup
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
segments:
|
|
7
|
-
- 0
|
|
8
|
-
- 4
|
|
9
|
-
- 1
|
|
10
|
-
version: 0.4.1
|
|
4
|
+
prerelease:
|
|
5
|
+
version: 0.5.0
|
|
11
6
|
platform: ruby
|
|
12
7
|
authors:
|
|
13
8
|
- |
|
|
@@ -17,37 +12,29 @@ autorequire:
|
|
|
17
12
|
bindir: bin
|
|
18
13
|
cert_chain: []
|
|
19
14
|
|
|
20
|
-
date:
|
|
15
|
+
date: 2011-09-05 00:00:00 -04:00
|
|
21
16
|
default_executable:
|
|
22
17
|
dependencies:
|
|
23
18
|
- !ruby/object:Gem::Dependency
|
|
19
|
+
name: parka
|
|
24
20
|
requirement: &id001 !ruby/object:Gem::Requirement
|
|
25
21
|
none: false
|
|
26
22
|
requirements:
|
|
27
23
|
- - ">="
|
|
28
24
|
- !ruby/object:Gem::Version
|
|
29
|
-
hash: 3
|
|
30
|
-
segments:
|
|
31
|
-
- 0
|
|
32
25
|
version: "0"
|
|
33
26
|
type: :development
|
|
34
|
-
name: parka
|
|
35
27
|
prerelease: false
|
|
36
28
|
version_requirements: *id001
|
|
37
29
|
- !ruby/object:Gem::Dependency
|
|
30
|
+
name: octopi
|
|
38
31
|
requirement: &id002 !ruby/object:Gem::Requirement
|
|
39
32
|
none: false
|
|
40
33
|
requirements:
|
|
41
34
|
- - ~>
|
|
42
35
|
- !ruby/object:Gem::Version
|
|
43
|
-
|
|
44
|
-
segments:
|
|
45
|
-
- 0
|
|
46
|
-
- 2
|
|
47
|
-
- 8
|
|
48
|
-
version: 0.2.8
|
|
36
|
+
version: 0.4.5
|
|
49
37
|
type: :runtime
|
|
50
|
-
name: octopi
|
|
51
38
|
prerelease: false
|
|
52
39
|
version_requirements: *id002
|
|
53
40
|
description: Backup your Github repositories
|
|
@@ -78,23 +65,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
78
65
|
requirements:
|
|
79
66
|
- - ">="
|
|
80
67
|
- !ruby/object:Gem::Version
|
|
81
|
-
hash: 3
|
|
82
|
-
segments:
|
|
83
|
-
- 0
|
|
84
68
|
version: "0"
|
|
85
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
70
|
none: false
|
|
87
71
|
requirements:
|
|
88
72
|
- - ">="
|
|
89
73
|
- !ruby/object:Gem::Version
|
|
90
|
-
hash: 3
|
|
91
|
-
segments:
|
|
92
|
-
- 0
|
|
93
74
|
version: "0"
|
|
94
75
|
requirements: []
|
|
95
76
|
|
|
96
77
|
rubyforge_project: nowarning
|
|
97
|
-
rubygems_version: 1.
|
|
78
|
+
rubygems_version: 1.6.2
|
|
98
79
|
signing_key:
|
|
99
80
|
specification_version: 3
|
|
100
81
|
summary: Backup your Github repositories
|