github-backups 0.2.0 → 0.3.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 CHANGED
@@ -25,9 +25,9 @@ github-backup -u hbt -o /tmp
25
25
  -f, --forks Optional: fetch all forks
26
26
  -b, --init-branches Optional: init all branches
27
27
  -i, --dump-issues Optional: dump all issues
28
- --dump-issues-filename FILENAME
29
- Optional: dump issues filename
30
28
  -w, --wiki Optional: dump wiki
29
+ -C, --compress Optional: run gc to compress git repo
30
+ -v, --version Displays current version
31
31
  -h, --help Displays this screen
32
32
  `
33
33
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "github-backups"
8
- s.version = "0.2.0"
8
+ s.version = "0.3.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"]
data/lib/github/repos.rb CHANGED
@@ -24,32 +24,45 @@ module GitHubBackup
24
24
 
25
25
  def backup_repo(repo)
26
26
  Dir.chdir(opts[:bakdir])
27
- repo_path = "#{opts[:bakdir]}/#{repo['name']}"
28
- # clone
29
- %x{git clone #{repo['ssh_url']}} unless File.exists?(repo_path)
30
- Dir.chdir(repo_path)
31
27
 
32
- # run pull
28
+ repo['repo_path'] = "#{opts[:bakdir]}/#{repo['name']}"
29
+
30
+ clone repo unless File.exists?(repo['repo_path'])
31
+ fetch_changes repo
32
+ get_forks repo if opts[:forks] and repo['forks'] > 1
33
+ create_all_branches repo if opts[:init_branches]
34
+ dump_issues repo if opts[:issues] && repo['has_issues']
35
+ dump_wiki repo if opts[:wiki] && repo['has_wiki']
36
+ repack repo if opts[:repack]
37
+ end
38
+
39
+ def clone(repo)
40
+ Dir.chdir(repo['repo_path'])
41
+ %x{git clone #{repo['ssh_url']}}
42
+ end
43
+
44
+ def fetch_changes(repo)
45
+ Dir.chdir(repo['repo_path'])
33
46
  %x{git fetch origin}
47
+ end
48
+
49
+ def get_forks(repo)
50
+ Dir.chdir(repo['repo_path'])
34
51
 
35
52
  # do we get all forks
36
- if opts[:forks] and repo['forks'] > 1
37
- (1..100).each do |i|
38
- forks = json("/repos/#{opts[:username]}/#{repo['name']}/forks?page=#{i}&per_page=100")
39
- forks.each do |f|
40
- %x{git remote add #{f['owner']['login']} #{f['git_url']}}
41
- %x{git fetch #{f['owner']['login']}}
42
-
43
- end
44
- break if forks.size == 0
53
+ (1..100).each do |i|
54
+ forks = json("/repos/#{opts[:username]}/#{repo['name']}/forks?page=#{i}&per_page=100")
55
+ forks.each do |f|
56
+ %x{git remote add #{f['owner']['login']} #{f['git_url']}}
57
+ %x{git fetch #{f['owner']['login']}}
45
58
  end
59
+ break if forks.size == 0
46
60
  end
61
+ end
47
62
 
48
- %x{for remote in `git branch -r `; do git branch --track $remote; done} if opts[:init_branches]
49
-
50
- repo['repo_path'] = repo_path
51
- dump_issues repo if opts[:issues] && repo['has_issues']
52
- dump_wiki repo if opts[:wiki] && repo['has_wiki']
63
+ def create_all_branches(repo)
64
+ Dir.chdir(repo['repo_path'])
65
+ %x{for remote in `git branch -r `; do git branch --track $remote; done}
53
66
  end
54
67
 
55
68
  def dump_issues(repo)
@@ -78,6 +91,11 @@ module GitHubBackup
78
91
  end
79
92
  end
80
93
 
94
+ def repack(repo)
95
+ Dir.chdir(repo['repo_path'])
96
+ %x{git gc --aggressive --auto}
97
+ end
98
+
81
99
  def json(url)
82
100
  auth = {:username => opts[:email], :password => opts[:passwd]} if opts[:email] and opts[:passwd]
83
101
  HTTParty.get('https://api.github.com' << url, :basic_auth => auth).parsed_response
data/lib/utils/options.rb CHANGED
@@ -49,6 +49,10 @@ github-backup -u hbt -o /tmp \n\n"
49
49
  self.options[:wiki] = true
50
50
  end
51
51
 
52
+ opts.on( '-C', '--compress', 'Optional: run gc to compress git repo' ) do
53
+ self.options[:repack] = true
54
+ end
55
+
52
56
  opts.on( '-v', '--version', 'Displays current version ' ) do
53
57
  #TODO
54
58
  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.2.0
5
+ version: 0.3.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - hbt
@@ -116,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
116
  requirements:
117
117
  - - ">="
118
118
  - !ruby/object:Gem::Version
119
- hash: -954207121
119
+ hash: -797375283
120
120
  segments:
121
121
  - 0
122
122
  version: "0"