-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_issues_to_csv.rb
More file actions
122 lines (105 loc) · 2.58 KB
/
github_issues_to_csv.rb
File metadata and controls
122 lines (105 loc) · 2.58 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# GitHub Issue Exporter
# refs: https://gist.github.com/tkarpinski/2369729
require 'octokit'
require 'csv'
require 'date'
require 'yaml'
def convert_body(body)
status = :default
desc = {us: '', ac: ''}
body.each_line do |line|
if line =~ /ユーザーストーリー/
status = :us
next
end
if line =~ /受け入れ条件/
status = :ac
next
end
if line.gsub(/(\s)/,"") == ""
next
end
line.gsub!(/(\r\n)/, "\r")
case status
when :us then
desc[:us] << line
when :ac
desc[:ac] << line
end
end
desc[:us].gsub!(/(\r$)/, "")
desc[:ac].gsub!(/(\r$)/, "")
desc
end
app_config = YAML.load_file("config.yml")
client = Octokit::Client.new(
:login => app_config["github"]["credential"]["username"],
:password => app_config["github"]["credential"]["password"])
csv = CSV.new(File.open(File.dirname(__FILE__) + "/issues_sjis.csv", 'w', :encoding => "SJIS"))
puts "Initialising CSV file..."
#CSV Headers
header = [
"番号",
"タイトル",
"ユーザーストーリー",
"受け入れ条件",
"作成日時",
"更新日時",
"マイルストーン",
"優先度",
"ステータス",
"作成者",
"GitHub Issue URL",
]
csv << header
puts "Getting issues from Github..."
temp_issues = []
issues = []
page = 0
begin
page = page +1
temp_issues = client.list_issues("#{app_config["github"]["repository"]}", :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("#{app_config["github"]["repository"]}", :state => "open", :page => page)
issues = issues + temp_issues;
end while not temp_issues.empty?
puts "Processing #{issues.size} issues..."
issues.each do |issue|
unless issue['labels'].to_s =~ /プロダクトバックログ/
next
end
puts "Processing issue #{issue['number']}..."
# Work out the priority based on our existing labels
case
when issue['labels'].to_s =~ /優先度:高/i
priority = "高"
when issue['labels'].to_s =~ /優先度:中/i
priority = "中"
when issue['labels'].to_s =~ /優先度:低/i
priority = "低"
end
milestone = issue['milestone'] || "None"
if (milestone != "None")
milestone = milestone['title']
end
desc = convert_body(issue['body'])
row = [
issue['number'],
issue['title'],
desc[:us],
desc[:ac],
issue['created_at'],
issue['updated_at'],
milestone,
priority,
issue['state'],
issue['user']['login'],
issue['html_url']
]
csv << row
end