github-backups 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
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.3.4
1
+ 0.4.0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "github-backups"
8
- s.version = "0.3.4"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["hbt"]
@@ -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[:passwd]
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
- forks = json("/repos/#{opts[:username]}/#{repo['name']}/forks?page=#{i}&per_page=100")
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
- %x{git remote add #{f['owner']['login']} #{f['git_url']}}
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 `; do git branch --track $remote; done}
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
- issues = json("/repos/#{opts[:username]}/#{repo['name']}/issues?page=#{i}&per_page=100")
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
@@ -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
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: github-backups
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.4
5
+ version: 0.4.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - hbt