backup-github 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
+ environment_id="ruby-1.9.3-p0@backup-github"
8
+
9
+ #
10
+ # Uncomment the following lines if you want to verify rvm version per project
11
+ #
12
+ # rvmrc_rvm_version="1.10.2" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+ #
18
+
19
+ #
20
+ # Uncomment following line if you want options to be set only for given project.
21
+ #
22
+ # PROJECT_JRUBY_OPTS=( --1.9 )
23
+ #
24
+ # The variable PROJECT_JRUBY_OPTS requires the following to be run in shell:
25
+ #
26
+ # chmod +x ${rvm_path}/hooks/after_use_jruby_opts
27
+ #
28
+
29
+ #
30
+ # First we attempt to load the desired environment directly from the environment
31
+ # file. This is very fast and efficient compared to running through the entire
32
+ # CLI and selector. If you want feedback on which environment was used then
33
+ # insert the word 'use' after --create as this triggers verbose mode.
34
+ #
35
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
36
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
37
+ then
38
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
39
+
40
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
41
+ then
42
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
43
+ fi
44
+ else
45
+ # If the environment file has not yet been created, use the RVM CLI to select.
46
+ if ! rvm --create "$environment_id"
47
+ then
48
+ echo "Failed to create RVM environment '${environment_id}'."
49
+ return 1
50
+ fi
51
+ fi
52
+
53
+ #
54
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
55
+ # it be automatically loaded. Uncomment the following and adjust the filename if
56
+ # necessary.
57
+ #
58
+ # filename=".gems"
59
+ # if [[ -s "$filename" ]]
60
+ # then
61
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
62
+ # fi
63
+
64
+ # If you use bundler, this might be useful to you:
65
+ # if [[ -s Gemfile ]] && ! command -v bundle >/dev/null
66
+ # then
67
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
68
+ # gem install bundler
69
+ # fi
70
+ # if [[ -s Gemfile ]] && command -v bundle
71
+ # then
72
+ # bundle install
73
+ # fi
74
+
75
+ if [[ $- == *i* ]] # check for interactive shells
76
+ then
77
+ echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
78
+ else
79
+ echo "Using: $GEM_HOME" # don't use colors in interactive shells
80
+ fi
81
+
data/Gemfile CHANGED
@@ -5,8 +5,8 @@ group :development do
5
5
  gem "rdoc", "~> 3.12"
6
6
  gem "bundler", "~> 1.0.0"
7
7
  gem "jeweler", "~> 1.8.3"
8
- gem "mocha", "~> 0.10.3"
9
- # gem "pry" # active for debug
8
+ gem "mocha", "~> 0.10.3"
9
+ #gem "pry" # active for debug
10
10
  end
11
11
 
12
12
  group :default do
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- backup-github (1.1.0)
4
+ backup-github (2.0.0)
5
5
  grit (~> 2.4.1)
6
6
  json (~> 1.6.4)
7
7
  octokit (~> 0.6.5)
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # backup-github
2
2
 
3
- Utility tool to backup github repository issues. It will backup up all the issues from all the repositories from a given github account.
3
+ Utility tool to backup github repository issues. It will backup all repositories from a given github account. The backup comprises the git repostory, the wiki and the issues.
4
4
 
5
5
  It works with a local git repository, on which issues from all repositories of a github account are serialized to json and commited. Thanks to git, all changes are versioned, and saved.
6
6
 
@@ -13,7 +13,7 @@ To install you can just download the gem with:
13
13
  Then, to run the backup command:
14
14
 
15
15
  ```bash
16
- backup-github -r path/to/my/backup/dir -u github_user -p github_pwd
16
+ backup-github -r path/to/my/backup/dir -u github_user -p github_pwd
17
17
  ```
18
18
 
19
19
  If, instead you want to backup up all the issues from an Organization within github, then you run:
@@ -26,19 +26,23 @@ If, instead you want to backup up all the issues from an Organization within git
26
26
 
27
27
  To properly configure the backup system, we recommend setting a cron job to run the command once a day.
28
28
 
29
+ ## Dependencies
30
+
31
+ Besides the gem dependencies, the git binary is required.
32
+
29
33
  ## Contributing to backup-github
30
-
34
+
31
35
  * Check out the latest master to make sure the feature hasn't been implemented
32
36
  or the bug hasn't been fixed yet.
33
- * Check out the issue tracker to make sure someone already hasn't requested it
37
+ * Check out the issue tracker to make sure someone already hasn't requested it
34
38
  and/or contributed it.
35
39
  * Fork the project.
36
40
  * Start a feature/bugfix branch.
37
41
  * Commit and push until you are happy with your contribution.
38
42
  * Make sure to add tests for it. This is important so I don't break it in a
39
43
  future version unintentionally.
40
- * Please try not to mess with the Rakefile, version, or history. If you want to
41
- have your own version, or is otherwise necessary, that is fine, but please
44
+ * Please try not to mess with the Rakefile, version, or history. If you want to
45
+ have your own version, or is otherwise necessary, that is fine, but please
42
46
  isolate to its own commit so I can cherry-pick around it.
43
47
 
44
48
  ## Copyright
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 2.0.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "backup-github"
8
- s.version = "1.1.0"
8
+ s.version = "2.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mariano A. Cortesi"]
12
- s.date = "2012-02-01"
12
+ s.date = "2012-03-06"
13
13
  s.description = "Command to backup Github Issues as JSON files in a Git Repository"
14
14
  s.email = "mariano@zauberlabs.com"
15
15
  s.executables = ["gh-backup-issues"]
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.files = [
21
21
  ".document",
22
22
  ".rspec",
23
+ ".rvmrc",
23
24
  "Gemfile",
24
25
  "Gemfile.lock",
25
26
  "LICENSE.txt",
data/lib/backup-github.rb CHANGED
@@ -7,8 +7,11 @@ require 'ostruct'
7
7
  require 'pathname'
8
8
  require 'logger'
9
9
 
10
+ #Grit.debug=true
11
+
12
+ Issue = Struct.new "Issue", :number, :content
10
13
  $logger = Logger.new($stdout)
11
-
14
+
12
15
  class GithubBackup
13
16
 
14
17
  def initialize(github)
@@ -19,58 +22,71 @@ class GithubBackup
19
22
  JSON.pretty_generate( issue.content )
20
23
  end
21
24
 
22
- def save_issue(dir, issue)
23
- file = dir + ('%04d.js' % issue.number)
24
- file.open('w') { |f| f.write(serialize_issue(issue)) }
25
- @gitrepo.add(file.to_s)
25
+ def save_issue(issue)
26
+ File.open('%04d.js' % issue.number, "w") { |f| f.write(serialize_issue(issue)) }
26
27
  end
27
28
 
28
- def run( orgname, local_repo )
29
- Dir.chdir(local_repo) do |path|
30
- @gitrepo = begin
31
- Grit::Repo.new(".")
32
- rescue Grit::InvalidGitRepositoryError => e
33
- $logger.warn "Not a git Repository, creating a new one"
34
- Grit::Repo.init(".")
29
+ def backup_gitrepo( giturl, path )
30
+ $logger.info "Backuping #{path.to_path}"
31
+ if path.directory?
32
+ $logger.info "Backuping #{path.to_path} -> UPDATE"
33
+ gritty = Grit::Git.new(path.realpath.to_path)
34
+ gritty.fetch({:timeout=>false})
35
+ else
36
+ $logger.info "Backuping #{path.to_path} -> NEW"
37
+ path.mkpath
38
+ gritty = Grit::Git.new(".")
39
+ gritty.clone({:mirror=>true, :timeout=>false}, giturl, path.realpath.to_path)
35
40
  end
41
+ end
42
+
43
+ def run( orgname, local_repo )
44
+ @github.repositories(orgname)[0,3].each do |repo|
45
+ reponame = "#{orgname}/#{repo.name}"
46
+ $logger.info "Backuping #{reponame}"
47
+
48
+ repopath = Pathname.new(local_repo) + repo.name
49
+ repopath.mkpath
36
50
 
37
- orgdir = Pathname.new orgname
38
-
39
- repositories = @github.repositories orgname
40
-
41
- repositories.each do |repo|
42
- reponame = "#{orgname}/#{repo.name}"
43
- $logger.info "Backuping #{reponame}"
44
-
45
- if @github.has_issues? reponame
46
- projectdir = orgdir + repo.name
47
- projectdir.mkpath
48
-
49
- @github.on_issues(reponame) {|issue| save_issue(projectdir, issue)}
50
- else
51
- $logger.info "No issues for #{reponame}"
51
+ $logger.info("Backup Reporsitory")
52
+ backup_gitrepo(repo.ssh_url, repopath + "git-bare" )
53
+
54
+ $logger.info("Backup Wiki")
55
+ backup_gitrepo(repo.ssh_url.gsub(".git", ".wiki.git"), repopath + "wiki-bare" )
56
+
57
+ # Backup Issues
58
+ if @github.has_issues? reponame
59
+ issuespath = repopath + "issues"
60
+ issuespath.mkpath
61
+ Dir.chdir(issuespath) do
62
+ # After endless problems with Grit, fallback to sytem exec
63
+ `git init` unless File.directory? ".git"
64
+ $logger.info("Fetching issues")
65
+ @github.on_issues(reponame) {|issue| save_issue(issue)}
66
+
67
+ $logger.info("Add & Commit issues")
68
+ `git add .`
69
+ `git commit -m backup`
52
70
  end
71
+ else
72
+ $logger.info "No issues for #{reponame}"
53
73
  end
54
-
55
- @gitrepo.commit_index("Backup...")
56
- $logger.info 'Backup Finished'
57
74
  end
58
75
  end
59
-
60
76
  end
61
77
 
62
78
 
63
79
  class GithubAPIAdapter
64
80
  @@ISSUE_STATES = %w{open closed}
65
-
66
- def initialize(client)
81
+
82
+ def initialize(client)
67
83
  @client = client
68
84
  end
69
85
 
70
86
  def has_issues?(reponame)
71
87
  @client.repository(reponame).has_issues
72
88
  end
73
-
89
+
74
90
  def on_issues(reponame, &block)
75
91
  @@ISSUE_STATES.each do |status|
76
92
  page = 0
@@ -78,8 +94,7 @@ class GithubAPIAdapter
78
94
  begin
79
95
  issues = @client.list_issues( reponame, :page => page, :state => status )
80
96
  issues.each do |issue|
81
- yield OpenStruct.new(:number => issue.number,
82
- :content => @client.issue(reponame, issue.number))
97
+ yield Issue.new(issue.number, @client.issue(reponame, issue.number))
83
98
  end
84
99
  page += 1
85
100
  end until issues.length != 10
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backup-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-01 00:00:00.000000000 Z
12
+ date: 2012-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: octokit
16
- requirement: &70183486958840 !ruby/object:Gem::Requirement
16
+ requirement: &70334031341660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.6.5
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70183486958840
24
+ version_requirements: *70334031341660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &70183486957760 !ruby/object:Gem::Requirement
27
+ requirement: &70334031341180 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.6.4
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70183486957760
35
+ version_requirements: *70334031341180
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: grit
38
- requirement: &70183486956980 !ruby/object:Gem::Requirement
38
+ requirement: &70334031340700 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.4.1
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70183486956980
46
+ version_requirements: *70334031340700
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: trollop
49
- requirement: &70183486956320 !ruby/object:Gem::Requirement
49
+ requirement: &70334031340220 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.16.2
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70183486956320
57
+ version_requirements: *70334031340220
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &70183486955700 !ruby/object:Gem::Requirement
60
+ requirement: &70334031339740 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 2.8.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70183486955700
68
+ version_requirements: *70334031339740
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rdoc
71
- requirement: &70183486954960 !ruby/object:Gem::Requirement
71
+ requirement: &70334031339260 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '3.12'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70183486954960
79
+ version_requirements: *70334031339260
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: bundler
82
- requirement: &70183486954280 !ruby/object:Gem::Requirement
82
+ requirement: &70334031338780 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 1.0.0
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70183486954280
90
+ version_requirements: *70334031338780
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: jeweler
93
- requirement: &70183486951860 !ruby/object:Gem::Requirement
93
+ requirement: &70334031338300 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 1.8.3
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70183486951860
101
+ version_requirements: *70334031338300
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: mocha
104
- requirement: &70183486948440 !ruby/object:Gem::Requirement
104
+ requirement: &70334031337820 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: 0.10.3
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70183486948440
112
+ version_requirements: *70334031337820
113
113
  description: Command to backup Github Issues as JSON files in a Git Repository
114
114
  email: mariano@zauberlabs.com
115
115
  executables:
@@ -121,6 +121,7 @@ extra_rdoc_files:
121
121
  files:
122
122
  - .document
123
123
  - .rspec
124
+ - .rvmrc
124
125
  - Gemfile
125
126
  - Gemfile.lock
126
127
  - LICENSE.txt
@@ -148,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
149
  version: '0'
149
150
  segments:
150
151
  - 0
151
- hash: 3014412636560081919
152
+ hash: -2566165398545649519
152
153
  required_rubygems_version: !ruby/object:Gem::Requirement
153
154
  none: false
154
155
  requirements: