Skip to content

Instantly share code, notes, and snippets.

@chulkilee
Created December 14, 2016 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chulkilee/6361d26130fcf76fbda02c872238fade to your computer and use it in GitHub Desktop.
Save chulkilee/6361d26130fcf76fbda02c872238fade to your computer and use it in GitHub Desktop.
Generate changelog for oj gem
#!/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
entries = []
current_entry = nil
doc = Nokogiri::HTML(open('http://www.ohler.com/dev/oj_misc/release_notes.html'))
body = doc.at_css('.content_box')
body.children.each do |cur|
text = cur.text.strip
next if text.empty?
case cur.name
when 'p'
entries << current_entry if current_entry
raise "Unknown format: #{text}" unless /^Release (?<version>\S+) \[(?<date>.+)\]$/ =~ text
current_entry = {
version: version,
date: Date.parse(date),
changes: []
}
when 'ul'
current_entry[:changes] += cur.search('li').map { |li| li.text.strip.gsub(/\n\s+/, ' ') }
end
end
entries << current_entry if current_entry
puts '# CHANGELOG'
puts
puts '## Unreleased'
puts
entries.each do |entry|
puts "## #{entry[:version]} - #{entry[:date]}"
puts
entry[:changes].each do |ch|
puts "- #{ch}"
end
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment