github-backup 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14a2b72342322f517cff0b6455acc64abe561d3f
4
- data.tar.gz: c6375f2d59bcd34f469c18642cc12d92fc33efa4
3
+ metadata.gz: 4b560781a0d4503a6c990e0700002b9f64365e77
4
+ data.tar.gz: 46735fd878f8c10052f323dcdca503c34df967e9
5
5
  SHA512:
6
- metadata.gz: c63d9712c4665a4ff5a701bdf28e6b18e960c14ec127851334ca77196d84e3fca3a1ea8c9f9135a4538123358e327498ef90e50ce5d3340b1e0c433d336cda84
7
- data.tar.gz: ce604134c1866bd58eed295936360475b185d10b3d1cd594258ceee280b7a9187a4a66eb622b2b512bffc6a46157a74eae8a613584bfd5509e3c08454c975de4
6
+ metadata.gz: 6091212894096370ba508a00eabf74d632ec065718257a59ea658e1d781f40a213c917253e3a3b028ddcf37c3eb5df07429e88eef223ac7589bcee84224fe872
7
+ data.tar.gz: 2b4dab9123f3a186882a73cc685173bd36d51226e2dea8ec2aa119f80576e7a0f36467a3f566f150b3787bbd0947865215a039a3f87bb52ec3bab4df083eb7cb
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,8 @@
1
+ .bundle
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ *.gem
7
+ /.rvmrc
8
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ github-backup (0.9.0)
5
+ octokit (~> 3.7)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ addressable (2.3.6)
11
+ faraday (0.9.0)
12
+ multipart-post (>= 1.2, < 3)
13
+ multipart-post (2.0.0)
14
+ octokit (3.7.0)
15
+ sawyer (~> 0.6.0, >= 0.5.3)
16
+ sawyer (0.6.0)
17
+ addressable (~> 2.3.5)
18
+ faraday (~> 0.8, < 0.10)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ github-backup!
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 David Dollar
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.
@@ -0,0 +1,15 @@
1
+ VERSION = $(shell ruby -Ilib/github-backup -rversion -e "puts GithubBackup::VERSION")
2
+
3
+ SOURCES = Gemfile Gemfile.lock bin/github-backup lib/github-backup.rb
4
+ GEMSPEC = github-backup.gemspec
5
+ GEM = github-backup-$(VERSION).gem
6
+
7
+ all: pkg/$(GEM)
8
+
9
+ release: pkg/$(GEM)
10
+ gem push pkg/$(GEM)
11
+
12
+ pkg/$(GEM): $(GEMSPEC) $(SOURCES)
13
+ gem build $(GEMSPEC)
14
+ @mkdir -p pkg/
15
+ mv $(GEM) pkg/$(GEM)
@@ -0,0 +1,40 @@
1
+ ## github-backup
2
+
3
+ Back up your Github repositories locally.
4
+
5
+ To install it as a Gem, just run:
6
+
7
+ $ gem install github-backup
8
+
9
+ To use it:
10
+
11
+ $ github-backup ddollar /path/to/my/backup/root
12
+
13
+ ## Authenticated Usage
14
+
15
+ ### Seamless authentication using .gitconfig defaults
16
+
17
+ You will need a `~/.gitconfig` file in place with a `[github]` section
18
+
19
+ See: http://github.com/guides/tell-git-your-user-name-and-email-address
20
+
21
+ ### Specify authentication at the command line
22
+
23
+ If you don't have a `[github]` section set up in your `~/.gitconfig` file, you
24
+ can provide your Github OAuth access token at the command line.
25
+
26
+ ## License
27
+
28
+ MIT License
29
+
30
+ ## Authorship
31
+
32
+ Created by David Dollar
33
+
34
+ Fixed for Github v3 by [Gareth Rees](https://github.com/garethrees)
35
+
36
+ [Other Contributors](https://github.com/ddollar/github-backup/graphs/contributors)
37
+
38
+ ## Copyright
39
+
40
+ Copyright (c) 2010 David Dollar.
@@ -23,5 +23,5 @@ end
23
23
  username = ARGV.shift
24
24
  root = ARGV.shift
25
25
 
26
- backup = GithubBackup.new(username, root, options)
26
+ backup = GithubBackup::Backup.new(username, root, options)
27
27
  backup.execute
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'github-backup/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "github-backup"
9
+ s.version = GithubBackup::VERSION
10
+
11
+ s.author = "David Dollar"
12
+ s.email = "david@dollar.io"
13
+ s.summary = "Backup your Github repositories"
14
+ s.description = "Library and command line tool for backing up GitHub repositories"
15
+ s.homepage = "http://github.com/ddollar/github-backup"
16
+ s.license = "MIT"
17
+
18
+ s.files = `git ls-files`.split($/)
19
+ s.require_paths = ['lib']
20
+ s.executables = "github-backup"
21
+
22
+ s.add_dependency "octokit", "~> 3.7"
23
+ end
@@ -0,0 +1,8 @@
1
+ require 'fileutils'
2
+ require 'octokit'
3
+ require 'pp'
4
+ require 'yaml'
5
+
6
+ Dir[File.dirname(__FILE__) + '/github-backup/*.rb'].each do |file|
7
+ require file
8
+ end
@@ -0,0 +1,138 @@
1
+ module GithubBackup
2
+ class Backup
3
+ attr_reader :backup_root, :debug, :username, :client
4
+
5
+ def initialize(username, backup_root, options = {})
6
+ @username = username
7
+ @backup_root = backup_root
8
+ @options = options
9
+ @debug = false
10
+
11
+ unless options.key?(:token)
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
23
+ end
24
+
25
+ def execute
26
+ backup_all
27
+ rescue Octokit::Unauthorized
28
+ puts "Github API authentication failed."
29
+ puts "Please add a [github] section to your ~/.gitconfig"
30
+ puts " See: http://github.com/guides/tell-git-your-user-name-and-email-address"
31
+ puts "Or, use the arguments to authenticate with your username and API token."
32
+ end
33
+
34
+ private ######################################################################
35
+
36
+ def backup_directory_for(repository)
37
+ File.join(backup_root, repository.full_name) + '.git'
38
+ end
39
+
40
+ def backup_all
41
+ FileUtils::mkdir_p(backup_root)
42
+ repositories.each do |repository|
43
+ puts "Backing up: #{repository.full_name}"
44
+ backup_repository repository
45
+ end
46
+ end
47
+
48
+ def repositories
49
+ repos = []
50
+ repos.concat(get_repositories_first_page)
51
+
52
+ # Iterate over paginated response
53
+ last_response = client.last_response
54
+ unless last_response.rels[:next].nil?
55
+ loop do
56
+ last_response = last_response.rels[:next].get
57
+ repos.concat(last_response.data)
58
+ break if last_response.rels[:next].nil?
59
+ end
60
+ end
61
+
62
+ repos
63
+ end
64
+
65
+ def get_repositories_first_page
66
+ if username_is_authenticated_user?
67
+ client.repos
68
+ elsif username_is_organisation?
69
+ client.org_repos(username)
70
+ else
71
+ client.repos(username)
72
+ end
73
+ end
74
+
75
+ def backup_repository(repository)
76
+ if File.exists?(backup_directory_for(repository))
77
+ backup_repository_incremental(repository)
78
+ else
79
+ backup_repository_initial(repository)
80
+ end
81
+ end
82
+
83
+ def backup_repository_initial(repository)
84
+ FileUtils::cd(backup_root) do
85
+ shell("git clone --mirror -n #{repository.ssh_url} #{repository.full_name}.git")
86
+ end
87
+ end
88
+
89
+ def backup_repository_incremental(repository)
90
+ FileUtils::cd(backup_directory_for(repository)) do
91
+ shell("git remote update")
92
+ end
93
+ end
94
+
95
+ def username_is_organisation?
96
+ client.user(username).type == 'Organization'
97
+ end
98
+
99
+ def username_is_authenticated_user?
100
+ return false unless client.token_authenticated?
101
+ username == client.user.login
102
+ end
103
+
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
+ def shell(command)
130
+ puts "EXECUTING: #{command}" if debug
131
+ IO.popen(command, 'r') do |io|
132
+ output = io.read
133
+ puts "OUTPUT:" if debug
134
+ puts output if debug
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,3 @@
1
+ module GithubBackup
2
+ VERSION = "0.9.0"
3
+ 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.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Dollar
@@ -24,14 +24,25 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.7'
27
- description:
27
+ description: Library and command line tool for backing up GitHub repositories
28
28
  email: david@dollar.io
29
29
  executables:
30
30
  - github-backup
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - ".document"
35
+ - ".gitignore"
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - LICENSE
39
+ - Makefile
40
+ - README.md
34
41
  - bin/github-backup
42
+ - github-backup.gemspec
43
+ - lib/github-backup.rb
44
+ - lib/github-backup/backup.rb
45
+ - lib/github-backup/version.rb
35
46
  homepage: http://github.com/ddollar/github-backup
36
47
  licenses:
37
48
  - MIT