PageRenderTime 56ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/release_scripts/generate_changelog.rb

https://bitbucket.org/phalgun/amarok-nepomuk
Ruby | 89 lines | 43 code | 19 blank | 27 comment | 0 complexity | a0e48b1f3a0ccef33eead317c1ab481c MD5 | raw file
Possible License(s): GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. #!/usr/bin/env ruby
  2. #
  3. # Script for generating a HTML page from Amarok's text ChangeLog
  4. #
  5. # (c) 2005-2006,2009
  6. # Mark Kretschmann <kretschmann@kde.org>,
  7. # Ian Monroe <ian@monroe.nu>,
  8. # Magnus Bergmark <magnus.bergmark@gmail.com>
  9. # License: GPL V2
  10. require 'cgi'
  11. $input = File.new( "ChangeLog", File::RDONLY )
  12. $output = File.new( "ChangeLog.html", File::CREAT | File::RDWR | File::TRUNC )
  13. $changelog = CGI::escapeHTML($input.read)
  14. # Remove the vim stuff
  15. $changelog.gsub!(/# vim:.*$/, '')
  16. # Remove whitespace from lines with only whitespace
  17. $changelog.gsub!(/^\s+$/, '')
  18. # Collapse multiple empty lines
  19. $changelog.gsub!(/\n{2,}/, "\n")
  20. # Replace bug number with direct link to bugs.kde.org
  21. $changelog.gsub!(/BR (\d+)/, '<a href="http://bugs.kde.org/show_bug.cgi?id=\\1">\\0</a>')
  22. # Make bullets
  23. bullet_item_regexp =
  24. /
  25. ^\s{4} # Start of line and four whitespace
  26. \*\s # The actual bullet
  27. (
  28. [^\n]* # Match everything up to the first newline
  29. (\s{6}[^\n]+)* # Match every following line if its indented
  30. )
  31. /xm;
  32. $changelog.gsub!(bullet_item_regexp) do |match|
  33. # Remove all the indentation spaces, too
  34. "\t<li>#{$1.gsub(/\s{2,}/, ' ')}</li>"
  35. end
  36. # Beautify heading
  37. $changelog.gsub!(/Amarok ChangeLog\n\=*\n/, "<h1>Amarok ChangeLog</h1>\n")
  38. # Create headers
  39. %w{FEATURES CHANGES BUGFIXES}.each do |header|
  40. $changelog.gsub!("#{header}:\n", "<h3>#{header.capitalize}</h3>")
  41. end
  42. # Format version headers
  43. $changelog.gsub!(/VERSION(.*$)/, '<h2>Version\\1</h2>');
  44. # Create <ul> and </ul> pairs around the headers
  45. # Lists start after a <h3></h3> and ends with the first other headline
  46. $changelog.gsub!(%r{(</h3>)(.*?)(<h\d>)}m, "\\1\n<ul>\n\\2\n</ul>\n\n\\3")
  47. # Now, we must parse the old syntax. It'll begin with version 1.2.1
  48. old_syntax_marker = "<h2>Version 1.2.1:</h2>"
  49. $changelog.sub!(/(#{old_syntax_marker})(.*)/m) do |old_contents|
  50. # The syntax here is pretty similar to the old lists, but we don't have any nice
  51. # bullet points in the file already. We will instead look at indentation
  52. bullet_item_regexp =
  53. /
  54. ^\s{2} # Start of line and two whitespace
  55. (
  56. [^\n]* # Match everything up to the first newline
  57. (\s{4}[^\n]+)* # Match every following line if its indented
  58. )
  59. /xm;
  60. old_contents.gsub!(bullet_item_regexp) do |match|
  61. # Remove all the indentation spaces, too
  62. "\t<li>#{$1.gsub(/\s{2,}/, ' ')}</li>"
  63. end
  64. # We also need to place <ul> and </ul> pairs everywhere
  65. # Lists start after a <h3></h3> and ends with the first other headline or EOF
  66. old_contents.gsub!(%r{(</h2>)(.*?)(<h\d>|\Z)}m, "\\1\n<ul>\n\\2\n</ul>\n\n\\3")
  67. old_contents
  68. end
  69. # Write destination file
  70. $output.write( $changelog )