This repository has been archived by the owner on Mar 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
summarize.rb
executable file
·75 lines (63 loc) · 1.8 KB
/
summarize.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env ruby
class Proposal < Struct.new(:name, :kvs, :summary, :md_url)
def state
kvs["State"]
end
end
class ProposalCollection < Struct.new(:proposals)
SORT_PRIORITY = {
"in-progress" => 0,
"discussing" => 1,
"accepted" => 2,
"finished" => 4,
"rejected" => 5,
nil => 6, # unknown
}
def self.build
proposals = []
Dir["proposals/*.md"].each do |file|
lines = File.read(file).split("\n")
kv_prefix = "- "
if lines.length == 0 || !lines[0].start_with?(kv_prefix)
raise "Error: Expected '#{file}' to start with metadata (marked by '#{kv_prefix}')"
end
still_kvs = true
kv_lines = lines.select { |l| still_kvs &= l.start_with?(kv_prefix) }
in_summary = false
summary_lines = lines.select do |l|
if l == "# Summary"
in_summary = true
next
elsif in_summary && l.start_with?("# ")
in_summary = false
end
in_summary
end
proposals << Proposal.new.tap do |p|
p.name = file[/\/(.*)\.md/,1]
p.md_url = file
p.summary = summary_lines.join
p.kvs = Hash[kv_lines.map { |l| l.sub(kv_prefix, "").split(": ", 2) }]
end
end
ProposalCollection.new(proposals)
end
def sorted
proposals.group_by { |p| p.state }.sort_by { |state,_| SORT_PRIORITY[state] }.each { |_,ps| ps.sort_by!(&:name) }
end
def print_md
puts "# Summary\n\n"
sorted.each do |state, props|
puts "## #{state}\n\n"
props.each do |prop|
puts "- [#{prop.name}](#{prop.md_url})"
prop.kvs.each do |k, v|
puts " - #{k}: #{v}"
end
puts " - Summary: #{prop.summary}" unless prop.summary.empty?
puts ""
end
end
end
end
ProposalCollection.build.print_md