github-backups 0.1.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/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.8.3"
13
+ gem "json"
14
+ gem "httparty"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ httparty (0.8.3)
6
+ multi_json (~> 1.0)
7
+ multi_xml
8
+ jeweler (1.8.3)
9
+ bundler (~> 1.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ rdoc
13
+ json (1.7.3)
14
+ multi_json (1.3.5)
15
+ multi_xml (0.5.1)
16
+ rake (0.9.2.2)
17
+ rdoc (3.12)
18
+ json (~> 1.4)
19
+ shoulda (3.0.1)
20
+ shoulda-context (~> 1.0.0)
21
+ shoulda-matchers (~> 1.0.0)
22
+ shoulda-context (1.0.0)
23
+ shoulda-matchers (1.0.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.0.0)
30
+ httparty
31
+ jeweler (~> 1.8.3)
32
+ json
33
+ rdoc (~> 3.12)
34
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 hbt
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.mkd ADDED
@@ -0,0 +1,38 @@
1
+ # github-backup
2
+
3
+ Command-line tool to backup data from github
4
+
5
+ ## Copies
6
+
7
+ * repos
8
+ * forks
9
+ * branches
10
+ * issues
11
+ * wiki
12
+
13
+
14
+ ## Usage
15
+ `
16
+ Usage: github-backup -u [username] -o [dir]
17
+ e.g
18
+ github-backup -u hbt -o /tmp
19
+
20
+ -e, --email EMAIL Optional: GitHub email/username. Required for private repos
21
+ -p, --password PASSWORD Optional: GitHub password. Required for private repos
22
+ -u, --username USERNAME *Required: GitHub username
23
+ -o, --output-dir DIR *Required: Backup directory
24
+ -r, --repository-name NAME Optional: limit to this repository name
25
+ -f, --forks Optional: fetch all forks
26
+ -b, --init-branches Optional: init all branches
27
+ -i, --dump-issues Optional: dump all issues
28
+ --dump-issues-filename FILENAME
29
+ Optional: dump issues filename
30
+ -w, --wiki Optional: dump wiki
31
+ -h, --help Displays this screen
32
+ `
33
+
34
+ ## Copyright
35
+
36
+ Copyright (c) 2012 hbt. See LICENSE.txt for
37
+ further details.
38
+
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "github-backups"
18
+ gem.homepage = "http://github.com/hbt/github-backup"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Backup all repos, wiki, issues, forks, branches from github}
21
+ gem.description = %Q{Command-line tool designed to back up repos from github}
22
+ gem.email = "hassenbentanfous@gmail.com"
23
+ gem.authors = ["hbt"]
24
+ gem.executables = ["github-backup"]
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+
37
+ task :default => :test
38
+
39
+ require 'rdoc/task'
40
+ Rake::RDocTask.new do |rdoc|
41
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "github-backup #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/github-backup ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.join(File.absolute_path(File.dirname(__FILE__)), '../lib/github-backup.rb')
@@ -0,0 +1,69 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "github-backup"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["hbt"]
12
+ s.date = "2012-05-24"
13
+ s.description = "Command-line tool designed to back up repos from github"
14
+ s.email = "hassenbentanfous@gmail.com"
15
+ s.executables = ["github-backup"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.mkd"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.mkd",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/github-backup",
29
+ "github-backup.gemspec",
30
+ "lib/github-backup.rb",
31
+ "lib/github/repos.rb",
32
+ "lib/utils/options.rb",
33
+ "test/helper.rb",
34
+ "test/test_github-backup.rb"
35
+ ]
36
+ s.homepage = "http://github.com/hbt/github-backup"
37
+ s.licenses = ["MIT"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = "1.8.15"
40
+ s.summary = "Backup all repos, wiki, issues, forks, branches from github"
41
+
42
+ if s.respond_to? :specification_version then
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
47
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
50
+ s.add_development_dependency(%q<json>, [">= 0"])
51
+ s.add_development_dependency(%q<httparty>, [">= 0"])
52
+ else
53
+ s.add_dependency(%q<shoulda>, [">= 0"])
54
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
57
+ s.add_dependency(%q<json>, [">= 0"])
58
+ s.add_dependency(%q<httparty>, [">= 0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<shoulda>, [">= 0"])
62
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
65
+ s.add_dependency(%q<json>, [">= 0"])
66
+ s.add_dependency(%q<httparty>, [">= 0"])
67
+ end
68
+ end
69
+
@@ -0,0 +1,85 @@
1
+ require 'fileutils'
2
+
3
+ module GitHubBackup
4
+ module GitHub
5
+ class << self
6
+ attr_accessor :opts
7
+ def options=(v)
8
+ self.opts = v
9
+ end
10
+
11
+ def backup_repos()
12
+ # get all repos
13
+ (1..100).each do |i|
14
+ repos = json("/users/#{opts[:username]}/repos?page=#{i}per_page=100")
15
+ repos.each do |f|
16
+ # do we limit to a specific repo?
17
+ next unless f['name'] == opts[:reponame] if opts[:reponame]
18
+ backup_repo f
19
+ end
20
+ break if repos.size == 0
21
+ end
22
+
23
+ end
24
+
25
+ def backup_repo(repo)
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
+
32
+ # run pull
33
+ %x{git fetch origin}
34
+
35
+ # 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
45
+ end
46
+ end
47
+
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']
53
+ end
54
+
55
+ def dump_issues(repo)
56
+ Dir.chdir(repo['repo_path'])
57
+
58
+ filename = repo['repo_path'] + "/issues_dump.txt"
59
+ FileUtils.rm filename if File.exists?(filename)
60
+
61
+ content = ''
62
+ (1..100).each do |i|
63
+ issues = json("/repos/#{opts[:username]}/#{repo['name']}/issues?page=#{i}&per_page=100")
64
+ content += issues.join("")
65
+ break if issues.size == 0
66
+ end
67
+
68
+ File.open(filename, 'w') {|f| f.write(content)}
69
+ end
70
+
71
+ def dump_wiki(repo)
72
+ Dir.chdir(opts[:bakdir])
73
+ wiki_path = "#{opts[:bakdir]}/#{repo['name']}.wiki"
74
+ %x{git clone git@github.com:#{repo['owner']['login']}/#{repo['name']}.wiki.git} unless File.exists?(wiki_path)
75
+ Dir.chdir(wiki_path)
76
+ %x{git fetch origin}
77
+ end
78
+
79
+ def json(url)
80
+ auth = {:username => opts[:email], :password => opts[:passwd]} if opts[:email] and opts[:passwd]
81
+ HTTParty.get('https://api.github.com' << url, :basic_auth => auth).parsed_response
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,31 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'httparty'
5
+ require 'json'
6
+
7
+ module GitHubBackup
8
+ class << self
9
+ def require_all
10
+ Dir[File.join(File.dirname(__FILE__), %W(** *.rb))].each do |f|
11
+ require f unless f == File.expand_path(__FILE__)
12
+ end
13
+ end
14
+
15
+ def main
16
+ require_all
17
+ backup
18
+ end
19
+
20
+ def backup
21
+ GitHubBackup::Options.parse
22
+ opts = GitHubBackup::Options.options
23
+
24
+ GitHubBackup::GitHub.options = opts
25
+ GitHubBackup::GitHub.backup_repos
26
+ end
27
+
28
+ end
29
+ end
30
+
31
+ GitHubBackup.main
@@ -0,0 +1,87 @@
1
+ require 'optparse'
2
+
3
+ module GitHubBackup
4
+ class Options
5
+ class << self
6
+ attr_accessor :options
7
+ def parse
8
+ self.options ||= {}
9
+
10
+ optparse = OptionParser.new do|opts|
11
+
12
+ # TODO: update usage
13
+ opts.banner = "Usage: github-backup -u [username] -o [dir]
14
+ e.g
15
+ github-backup -u hbt -o /tmp \n\n"
16
+ # backup.rb *githubUsername* *githubPassword* [--github-user=XXX] [--repo=XXX] [--all-branches] [--all-forks] [--issues] [--wiki]
17
+ # backup.rb [--github-user=XXX] [--repo=XXX] [--all-branches] [--all-forks] [--issues] [--wiki]
18
+ # backup.rb --username=XXX --password=XXX [--github-user=XXX] --repo=XXX --all-branches --all-forks --issues --wiki
19
+
20
+ opts.on( '-e', '--email EMAIL', 'Optional: GitHub email/username. Required for private repos') do |f|
21
+ self.options[:email] = f
22
+ end
23
+
24
+ opts.on( '-p', '--password PASSWORD', 'Optional: GitHub password. Required for private repos') do |f|
25
+ self.options[:passwd] = f
26
+ end
27
+
28
+ opts.on( '-u', '--username USERNAME', '*Required: GitHub username') do |f|
29
+ self.options[:username] = f
30
+ end
31
+
32
+ opts.on( '-o', '--output-dir DIR', '*Required: Backup directory') do |f|
33
+ self.options[:bakdir] = File.expand_path(f)
34
+ end
35
+
36
+ opts.on( '-r', '--repository-name NAME', 'Optional: limit to this repository name' ) do |f|
37
+ self.options[:reponame] = f
38
+ end
39
+
40
+ opts.on( '-f', '--forks', 'Optional: fetch all forks' ) do
41
+ self.options[:forks] = true
42
+ end
43
+
44
+ opts.on( '-b', '--init-branches', 'Optional: init all branches' ) do
45
+ self.options[:init_branches] = true
46
+ end
47
+
48
+ opts.on( '-i', '--dump-issues', 'Optional: dump all issues' ) do
49
+ self.options[:issues] = true
50
+ end
51
+
52
+ opts.on( nil, '--dump-issues-filename FILENAME', 'Optional: dump issues filename' ) do |f|
53
+ self.options[:issues_filename] = f
54
+ end
55
+
56
+ opts.on( '-w', '--wiki', 'Optional: dump wiki' ) do
57
+ self.options[:wiki] = true
58
+ end
59
+
60
+ opts.on( '-v', '--version', 'Displays current version ' ) do
61
+ #TODO
62
+ end
63
+
64
+ opts.on( '-h', '--help', 'Displays this screen' ) do
65
+ p opts
66
+ exit
67
+ end
68
+ end
69
+
70
+ optparse.parse!
71
+
72
+ if !is_valid?
73
+ puts optparse
74
+ exit
75
+ end
76
+ end
77
+
78
+ # check required options
79
+ def is_valid?
80
+ return false unless self.options[:bakdir] && File.exists?(self.options[:bakdir])
81
+ return false unless self.options[:username]
82
+ true
83
+ end
84
+
85
+ end
86
+ end
87
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'github-backup'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestGithubBackup < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: github-backups
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - hbt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-05-24 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: shoulda
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: rdoc
28
+ requirement: &id002 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: "3.12"
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: bundler
39
+ requirement: &id003 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 1.0.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: jeweler
50
+ requirement: &id004 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.8.3
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: json
61
+ requirement: &id005 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *id005
70
+ - !ruby/object:Gem::Dependency
71
+ name: httparty
72
+ requirement: &id006 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *id006
81
+ description: Command-line tool designed to back up repos from github
82
+ email: hassenbentanfous@gmail.com
83
+ executables:
84
+ - github-backup
85
+ extensions: []
86
+
87
+ extra_rdoc_files:
88
+ - LICENSE.txt
89
+ - README.mkd
90
+ files:
91
+ - .document
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE.txt
95
+ - README.mkd
96
+ - Rakefile
97
+ - VERSION
98
+ - bin/github-backup
99
+ - github-backup.gemspec
100
+ - lib/github-backup.rb
101
+ - lib/github/repos.rb
102
+ - lib/utils/options.rb
103
+ - test/helper.rb
104
+ - test/test_github-backup.rb
105
+ homepage: http://github.com/hbt/github-backup
106
+ licenses:
107
+ - MIT
108
+ post_install_message:
109
+ rdoc_options: []
110
+
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: -385962001
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: "0"
128
+ requirements: []
129
+
130
+ rubyforge_project:
131
+ rubygems_version: 1.8.15
132
+ signing_key:
133
+ specification_version: 3
134
+ summary: Backup all repos, wiki, issues, forks, branches from github
135
+ test_files: []
136
+