This repository was archived by the owner on Mar 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup.rb
More file actions
64 lines (54 loc) · 1.43 KB
/
backup.rb
File metadata and controls
64 lines (54 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env ruby
require 'rubygems'
require 'octokit'
require 'json'
require 'grit'
include Grit
user = ""
password = ""
orgName = ""
unless ARGV[0]
puts "Usage: #{$O} [folderBackup]"
exit
end
folderBackup = ARGV[0]
client = Octokit::Client.new(:login => user, :password => password)
if !File.directory?(folderBackup)
puts "The directory '" + folderBackup + "' doesn't exist"
exit!
end
client.repositories(orgName).each { |repo|
puts "Backuping " + repo.name
dirName = File.join(folderBackup, repo.name)
if !File.directory?(dirName)
Dir.mkdir(dirName)
end
repoName = "%s/%s" % [orgName, repo.name]
if client.repository(repoName).has_issues
['open', 'closed'].each { |status|
page = 0
## navego las multiples paginas
begin
issues = client.list_issues(repoName, {
:page => page,
:state => status
})
issues.each { |issue|
## file where the issue is saved
issueFilename = '%s/%04d.js' % [dirName,issue.number]
json = JSON.pretty_generate(client.issue(repoName, issue.number))
File.open(issueFilename , 'w') {|f| f.write(json) }
}
page = page + 1
end until issues.length != 10
}
else
puts ' Ignore %s project without issues' % repoName
end
}
puts 'Commiting...'
repo = Repo.new(folderBackup)
Dir.chdir(folderBackup)
repo.add(".")
repo.commit_index("Backup...")
puts 'Finish commit...'