Class: ChangelogParser
- Inherits:
-
Object
- Object
- ChangelogParser
- Defined in:
- lib/changelog_parser.rb
Instance Method Summary collapse
- #commit_message_divider ⇒ Object
- #commit_parts_divider ⇒ Object
-
#initialize(all = false) ⇒ ChangelogParser
constructor
A new instance of ChangelogParser.
- #is_merge?(line) ⇒ Boolean
- #is_version_bump?(line) ⇒ Boolean
- #log_to_lines ⇒ Object
- #parse_lines ⇒ Object
- #print_changelog(line) ⇒ Object
- #print_version_bump(line) ⇒ Object
- #read_log ⇒ Object
Constructor Details
#initialize(all = false) ⇒ ChangelogParser
Returns a new instance of ChangelogParser.
2 3 4 5 6 |
# File 'lib/changelog_parser.rb', line 2 def initialize(all = false) @all = all read_log parse_lines end |
Instance Method Details
#commit_message_divider ⇒ Object
12 13 14 |
# File 'lib/changelog_parser.rb', line 12 def "__END_OF_COMMIT__\n" end |
#commit_parts_divider ⇒ Object
8 9 10 |
# File 'lib/changelog_parser.rb', line 8 def commit_parts_divider "__END_OF_PART__" end |
#is_merge?(line) ⇒ Boolean
37 38 39 |
# File 'lib/changelog_parser.rb', line 37 def is_merge?(line) line =~ /Merge/ end |
#is_version_bump?(line) ⇒ Boolean
41 42 43 |
# File 'lib/changelog_parser.rb', line 41 def is_version_bump?(line) line =~ /Version bump to/ ? true : false end |
#log_to_lines ⇒ Object
22 23 24 |
# File 'lib/changelog_parser.rb', line 22 def log_to_lines @log.split().collect{ |l| l.gsub("\n", " ") } end |
#parse_lines ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/changelog_parser.rb', line 26 def parse_lines self.log_to_lines.each do |line| next if is_merge?(line) if is_version_bump?(line) print_version_bump(line) else print_changelog(line) end end end |
#print_changelog(line) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/changelog_parser.rb', line 49 def print_changelog(line) commit_parts = line.split(commit_parts_divider) = commit_parts[2] = commit_parts[1].to_s = .scan(/changelog:\s(.*)/i).flatten.first if puts " * #{.strip} - #{}" else puts " * #{.strip} - #{}" if @all end end |
#print_version_bump(line) ⇒ Object
45 46 47 |
# File 'lib/changelog_parser.rb', line 45 def print_version_bump(line) puts "=== #{line.split(commit_parts_divider)[0].gsub("Version bump to", "").gsub(" ", " ")}" end |
#read_log ⇒ Object
16 17 18 19 20 |
# File 'lib/changelog_parser.rb', line 16 def read_log format = %w(%s %B %an).join(commit_parts_divider) format << @log = `git log -n 100 --no-merges --format='#{format}'` end |