Class: GithubBackup
- Inherits:
-
Object
- Object
- GithubBackup
- Defined in:
- lib/backup-github.rb
Instance Method Summary collapse
- #backup_gitrepo(giturl, path) ⇒ Object
-
#initialize(github) ⇒ GithubBackup
constructor
A new instance of GithubBackup.
- #run(orgname, local_repo) ⇒ Object
- #save_issue(issue) ⇒ Object
- #serialize_issue(issue) ⇒ Object
Constructor Details
#initialize(github) ⇒ GithubBackup
Returns a new instance of GithubBackup.
17 18 19 |
# File 'lib/backup-github.rb', line 17 def initialize(github) @github = github end |
Instance Method Details
#backup_gitrepo(giturl, path) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/backup-github.rb', line 29 def backup_gitrepo( giturl, path ) $logger.info "Backuping #{path.to_path}" if path.directory? $logger.info "Backuping #{path.to_path} -> UPDATE" gritty = Grit::Git.new(path.realpath.to_path) gritty.fetch({:timeout=>false}) else $logger.info "Backuping #{path.to_path} -> NEW" path.mkpath gritty = Grit::Git.new(".") gritty.clone({:mirror=>true, :timeout=>false}, giturl, path.realpath.to_path) end end |
#run(orgname, local_repo) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/backup-github.rb', line 43 def run( orgname, local_repo ) @github.repositories(orgname)[0,3].each do |repo| reponame = "#{orgname}/#{repo.name}" $logger.info "Backuping #{reponame}" repopath = Pathname.new(local_repo) + repo.name repopath.mkpath $logger.info("Backup Reporsitory") backup_gitrepo(repo.ssh_url, repopath + "git-bare" ) $logger.info("Backup Wiki") backup_gitrepo(repo.ssh_url.gsub(".git", ".wiki.git"), repopath + "wiki-bare" ) # Backup Issues if @github.has_issues? reponame issuespath = repopath + "issues" issuespath.mkpath Dir.chdir(issuespath) do # After endless problems with Grit, fallback to sytem exec `git init` unless File.directory? ".git" $logger.info("Fetching issues") @github.on_issues(reponame) {|issue| save_issue(issue)} $logger.info("Add & Commit issues") `git add .` `git commit -m backup` end else $logger.info "No issues for #{reponame}" end end end |
#save_issue(issue) ⇒ Object
25 26 27 |
# File 'lib/backup-github.rb', line 25 def save_issue(issue) File.open('%04d.js' % issue.number, "w") { |f| f.write(serialize_issue(issue)) } end |
#serialize_issue(issue) ⇒ Object
21 22 23 |
# File 'lib/backup-github.rb', line 21 def serialize_issue(issue) JSON.pretty_generate( issue.content ) end |