github-backups 0.3.4 → 0.4.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.mkd +4 -3
- data/VERSION +1 -1
- data/github-backups.gemspec +1 -1
- data/lib/github/repos.rb +20 -5
- data/lib/utils/options.rb +4 -0
- metadata +1 -1
data/README.mkd
CHANGED
@@ -7,12 +7,12 @@ Command-line tool to backup data from github
|
|
7
7
|
* repos
|
8
8
|
* forks
|
9
9
|
* branches
|
10
|
-
* issues
|
10
|
+
* issues (into a JSON file per repository)
|
11
11
|
* wiki
|
12
12
|
|
13
13
|
|
14
14
|
## Usage
|
15
|
-
|
15
|
+
|
16
16
|
Usage: github-backup -u [username] -o [dir]
|
17
17
|
e.g
|
18
18
|
github-backup -u hbt -o /tmp
|
@@ -21,6 +21,7 @@ github-backup -u hbt -o /tmp
|
|
21
21
|
-o, --output-dir DIR *Required: Backup directory
|
22
22
|
-p, --password PASSWORD Optional: GitHub password. Required for private repos
|
23
23
|
-r, --repository-name NAME Optional: limit to this repository name
|
24
|
+
-O, --organization NAME Optional: Organization name to use for fetching repositories, instead of the user
|
24
25
|
-f, --forks Optional: fetch all forks
|
25
26
|
-b, --init-branches Optional: init all branches
|
26
27
|
-i, --dump-issues Optional: dump all issues
|
@@ -28,7 +29,7 @@ github-backup -u hbt -o /tmp
|
|
28
29
|
-C, --compress Optional: run gc to compress git repo
|
29
30
|
-v, --version Displays current version
|
30
31
|
-h, --help Displays this screen
|
31
|
-
|
32
|
+
|
32
33
|
|
33
34
|
## Copyright
|
34
35
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/github-backups.gemspec
CHANGED
data/lib/github/repos.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'fileutils'
|
2
|
+
require 'pp'
|
2
3
|
|
3
4
|
module GitHubBackup
|
4
5
|
module GitHub
|
@@ -11,7 +12,9 @@ module GitHubBackup
|
|
11
12
|
def backup_repos()
|
12
13
|
# get all repos
|
13
14
|
(1..100).each do |i|
|
14
|
-
if opts[:
|
15
|
+
if opts[:organization]
|
16
|
+
url = "/orgs/#{opts[:organization]}/repos"
|
17
|
+
elsif opts[:passwd]
|
15
18
|
url ="/user/repos"
|
16
19
|
else
|
17
20
|
url = "/users/#{opts[:username]}/repos"
|
@@ -55,9 +58,16 @@ module GitHubBackup
|
|
55
58
|
|
56
59
|
# do we get all forks
|
57
60
|
(1..100).each do |i|
|
58
|
-
|
61
|
+
if opts[:organization]
|
62
|
+
url = "/repos/#{opts[:organization]}/#{repo['name']}/forks"
|
63
|
+
else
|
64
|
+
url = "/repos/#{opts[:username]}/#{repo['name']}/forks"
|
65
|
+
end
|
66
|
+
forks = json("#{url}?page=#{i}&per_page=100")
|
67
|
+
pp forks
|
59
68
|
forks.each do |f|
|
60
|
-
|
69
|
+
puts "Adding remote #{f['owner']['login']} from #{f['ssh_url']}.."
|
70
|
+
%x{git remote add #{f['owner']['login']} #{f['ssh_url']}}
|
61
71
|
%x{git fetch #{f['owner']['login']}}
|
62
72
|
end
|
63
73
|
break if forks.size == 0
|
@@ -66,7 +76,7 @@ module GitHubBackup
|
|
66
76
|
|
67
77
|
def create_all_branches(repo)
|
68
78
|
Dir.chdir(repo['repo_path'])
|
69
|
-
%x{for remote in `git branch -r
|
79
|
+
%x{for remote in `git branch -r`; do git branch --track $remote; done}
|
70
80
|
end
|
71
81
|
|
72
82
|
def dump_issues(repo)
|
@@ -77,7 +87,12 @@ module GitHubBackup
|
|
77
87
|
|
78
88
|
content = ''
|
79
89
|
(1..100).each do |i|
|
80
|
-
|
90
|
+
if opts[:organization]
|
91
|
+
url = "/repos/#{opts[:organization]}/#{repo['name']}/issues"
|
92
|
+
else
|
93
|
+
url = "/repos/#{opts[:username]}/#{repo['name']}/issues"
|
94
|
+
end
|
95
|
+
issues = json("#{url}?page=#{i}&per_page=100")
|
81
96
|
content += issues.join("")
|
82
97
|
break if issues.size == 0
|
83
98
|
end
|
data/lib/utils/options.rb
CHANGED
@@ -26,6 +26,10 @@ github-backup -u hbt -o /tmp \n\n"
|
|
26
26
|
self.options[:passwd] = f
|
27
27
|
end
|
28
28
|
|
29
|
+
opts.on( '-O', '--organization ORGANIZATION_NAME', 'Optional: Organization name of the organization to fetch repositories from') do |f|
|
30
|
+
self.options[:organization] = f
|
31
|
+
end
|
32
|
+
|
29
33
|
opts.on( '-r', '--repository-name NAME', 'Optional: limit to this repository name' ) do |f|
|
30
34
|
self.options[:reponame] = f
|
31
35
|
end
|