github-backup 0.9.0 → 0.10.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/github-backup +3 -3
- data/github-backup.gemspec +3 -5
- data/lib/github-backup/backup.rb +9 -43
- data/lib/github-backup/config.rb +47 -0
- data/lib/github-backup/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5369c3068e82f9ef8466455c2216ccd68d6c5b50
|
4
|
+
data.tar.gz: 06f0366d478b651c8ec6a160d0502af6e2e58b41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6723ef4b7331f84535277994b9f9bb627d9a91764f0945477a521d0f0ad6e4bf1c885b5c41bc98d591ddc30ffb2522a2e8eeb363e05f1167cdf4989baf0db073
|
7
|
+
data.tar.gz: 9996e98b8d954e0b96f17f6a15c28920194cc177692820fd82787f0e9770c4cffe9d826323da74c0c67e056266b2f9b1a51ac7d425cd97dd45742766f93cd032
|
data/Gemfile.lock
CHANGED
data/bin/github-backup
CHANGED
@@ -20,8 +20,8 @@ unless ARGV.length == 2
|
|
20
20
|
exit 1
|
21
21
|
end
|
22
22
|
|
23
|
-
username
|
24
|
-
|
23
|
+
username = ARGV.shift
|
24
|
+
options[:backup_root] = ARGV.shift
|
25
25
|
|
26
|
-
backup = GithubBackup::Backup.new(username,
|
26
|
+
backup = GithubBackup::Backup.new(username, options)
|
27
27
|
backup.execute
|
data/github-backup.gemspec
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
1
|
+
$:.unshift File.expand_path("../lib", __FILE__)
|
4
2
|
|
5
|
-
require
|
3
|
+
require "github-backup/version"
|
6
4
|
|
7
5
|
Gem::Specification.new do |s|
|
8
6
|
s.name = "github-backup"
|
@@ -17,7 +15,7 @@ Gem::Specification.new do |s|
|
|
17
15
|
|
18
16
|
s.files = `git ls-files`.split($/)
|
19
17
|
s.require_paths = ['lib']
|
20
|
-
s.executables
|
18
|
+
s.executables = "github-backup"
|
21
19
|
|
22
20
|
s.add_dependency "octokit", "~> 3.7"
|
23
21
|
end
|
data/lib/github-backup/backup.rb
CHANGED
@@ -1,25 +1,12 @@
|
|
1
1
|
module GithubBackup
|
2
2
|
class Backup
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :debug, :username, :client, :config
|
4
4
|
|
5
|
-
def initialize(username,
|
5
|
+
def initialize(username, options = {})
|
6
6
|
@username = username
|
7
|
-
@backup_root = backup_root
|
8
|
-
@options = options
|
9
7
|
@debug = false
|
10
|
-
|
11
|
-
|
12
|
-
config = read_gitconfig
|
13
|
-
if config.key?('github')
|
14
|
-
options[:token] = config['github'].fetch('token', nil)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
if options[:token]
|
19
|
-
@client = Octokit::Client.new(:access_token => options[:token])
|
20
|
-
else
|
21
|
-
@client = Octokit::Client.new
|
22
|
-
end
|
8
|
+
@config = Config.new(options)
|
9
|
+
@client = Octokit::Client.new(:access_token => config.token)
|
23
10
|
end
|
24
11
|
|
25
12
|
def execute
|
@@ -31,7 +18,11 @@ module GithubBackup
|
|
31
18
|
puts "Or, use the arguments to authenticate with your username and API token."
|
32
19
|
end
|
33
20
|
|
34
|
-
private
|
21
|
+
private
|
22
|
+
|
23
|
+
def backup_root
|
24
|
+
config.backup_root
|
25
|
+
end
|
35
26
|
|
36
27
|
def backup_directory_for(repository)
|
37
28
|
File.join(backup_root, repository.full_name) + '.git'
|
@@ -101,31 +92,6 @@ module GithubBackup
|
|
101
92
|
username == client.user.login
|
102
93
|
end
|
103
94
|
|
104
|
-
def read_gitconfig
|
105
|
-
config = {}
|
106
|
-
group = nil
|
107
|
-
|
108
|
-
return config unless File.exists?(gitconfig_path)
|
109
|
-
|
110
|
-
File.foreach(gitconfig_path) do |line|
|
111
|
-
line.strip!
|
112
|
-
if line[0] != ?# && line =~ /\S/
|
113
|
-
if line =~ /^\[(.*)\]$/
|
114
|
-
group = $1
|
115
|
-
config[group] ||= {}
|
116
|
-
else
|
117
|
-
key, value = line.split("=").map { |v| v.strip }
|
118
|
-
config[group][key] = value
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
config
|
123
|
-
end
|
124
|
-
|
125
|
-
def gitconfig_path
|
126
|
-
"#{ENV['HOME']}/.gitconfig"
|
127
|
-
end
|
128
|
-
|
129
95
|
def shell(command)
|
130
96
|
puts "EXECUTING: #{command}" if debug
|
131
97
|
IO.popen(command, 'r') do |io|
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module GithubBackup
|
2
|
+
class Config
|
3
|
+
|
4
|
+
DEFAULTS = {
|
5
|
+
:gitconfig_path => "#{ENV['HOME']}/.gitconfig",
|
6
|
+
}
|
7
|
+
|
8
|
+
attr_reader :backup_root, :gitconfig_path, :token
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
@backup_root = options.fetch(:backup_root) { raise ArgumentError, 'A backup_root option is required' }
|
12
|
+
@gitconfig_path = options.fetch(:gitconfig_path) { DEFAULTS[:gitconfig_path] }
|
13
|
+
@token = options.fetch(:token) { default_token }
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def default_token
|
19
|
+
config = read_gitconfig
|
20
|
+
if config.key?('github')
|
21
|
+
config['github'].fetch('token', nil)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def read_gitconfig
|
26
|
+
config = {}
|
27
|
+
group = nil
|
28
|
+
|
29
|
+
return config unless File.exists?(gitconfig_path)
|
30
|
+
|
31
|
+
File.foreach(gitconfig_path) do |line|
|
32
|
+
line.strip!
|
33
|
+
if line[0] != ?# && line =~ /\S/
|
34
|
+
if line =~ /^\[(.*)\]$/
|
35
|
+
group = $1
|
36
|
+
config[group] ||= {}
|
37
|
+
else
|
38
|
+
key, value = line.split("=").map { |v| v.strip }
|
39
|
+
config[group][key] = value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
config
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github-backup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Dollar
|
@@ -42,6 +42,7 @@ files:
|
|
42
42
|
- github-backup.gemspec
|
43
43
|
- lib/github-backup.rb
|
44
44
|
- lib/github-backup/backup.rb
|
45
|
+
- lib/github-backup/config.rb
|
45
46
|
- lib/github-backup/version.rb
|
46
47
|
homepage: http://github.com/ddollar/github-backup
|
47
48
|
licenses:
|