Skip to content

Instantly share code, notes, and snippets.

@olivierlacan
Last active August 29, 2015 14:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olivierlacan/af246b98101a7cf33360 to your computer and use it in GitHub Desktop.
Save olivierlacan/af246b98101a7cf33360 to your computer and use it in GitHub Desktop.
Really naive CHANGELOG parser we used on Code School for a while to export public-facing release notes from a private-ish CHANGELOG.md file.
require 'vandamme'
module PagesHelper
def changes
changes = {}
sections = changelog_file.each_with_index do |day, index|
change_sets = {}
day[1].scan(section_title_scanner) do |match|
section_title = "#{match.first}"
section_content = $~.post_match.strip # removing new lines
puts "section title: #{section_title}"
changelog_scanner = StringScanner.new(section_content)
changelog_scanner.scan_until(section_title_scanner)
# on the last iteration, there will be no pre_match because there is no
# next section to scan_until, in that case simply return the fulll
# section_content as it only contains a list of items.
content = (changelog_scanner.pre_match || section_content).split(/- /).reject do |a|
# filter out stuff marked as [INTERNAL] unless an internal query param is found
# I know, super secure, right?
if a.include?('[INTERNAL]') && !params[:internal]
true
elsif a.empty?
true
end
end
change_sets.merge!({ "#{section_title}" => content }) unless content.empty?
end
changes.merge!({ "#{day.first}" => change_sets }) unless change_sets.empty?
end
@changes ||= changes
end
private
def section_title_scanner
Regexp.new('#{3} (.*)') # section separators ("### Added", "### Fixed")
end
def changelog_file
@changelog ||= begin
log = File.open('CHANGELOG.md').read
parser = Vandamme::Parser.new(changelog: log, version_header_exp: '#{2} (\d{4}-\d{2}-\d{2})', format: 'markdown')
days = parser.parse
end
end
end
- changes.each do |set|
%article.content-section
%h2.mbm= time_tag Date.parse(set.first), Date.parse(set.first).to_formatted_s(:long)
- if !set.last.empty?
- set.last.each do |section|
.content-section
%h3.h4= section.first
%ul.list.list--styled
- section.last.each do |item|
%li.list-item
:markdown
#{item}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment