-
Notifications
You must be signed in to change notification settings - Fork 2
/
github_issues_to_file.rb
61 lines (50 loc) · 1.51 KB
/
github_issues_to_file.rb
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
#!/usr/bin/env ruby
# origin source
# https://gist.github.com/tkarpinski/2369729
require 'pp'
require 'octokit'
require 'pstore'
require 'yaml'
# 設定ファイル読み出し
if File.exists?("info.yml")
CONFIG = YAML.load_file("info.yml")
else
CONFIG = YAML.load_file("info_sample.yml")
end
# Github credentials to access your private project
USERNAME = CONFIG["username"]
PASSWORD = CONFIG["password"]
# Project you want to export issues from
USER = CONFIG["user"]
PROJECT = CONFIG["project"]
# Your local timezone offset to convert times
TIMEZONE_OFFSET="0"
client = Octokit::Client.new(:login => USERNAME, :password => PASSWORD)
# 保存先ファイル
db = PStore.new("#{PROJECT}_issues.db")
# open, close 両方のissueを全て取得
puts "Getting issues from Github..."
temp_issues = []
issues = []
page = 0
begin
page = page +1
temp_issues = client.list_issues("#{USER}/#{PROJECT}", :state => "closed", :page => page)
issues = issues + temp_issues;
end while not temp_issues.empty?
temp_issues = []
page = 0
begin
page = page +1
temp_issues = client.list_issues("#{USER}/#{PROJECT}", :state => "open", :page => page)
issues = issues + temp_issues;
end while not temp_issues.empty?
# 取得したissue をシリアライズ保存
puts "Processing #{issues.size} issues..."
issues.each do |issue|
puts "Processing issue #{issue['number']}..."
# ハッシュと同じようにキーを指定して保存
db.transaction do
db["issue_#{issue['number']}"] = issue
end # ここで保存される
end