Class: ChangelogParser

Inherits:
Object
  • Object
show all
Defined in:
lib/changelog_parser.rb

Instance Method Summary collapse

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_dividerObject



12
13
14
# File 'lib/changelog_parser.rb', line 12

def commit_message_divider
  "__END_OF_COMMIT__\n"
end

#commit_parts_dividerObject



8
9
10
# File 'lib/changelog_parser.rb', line 8

def commit_parts_divider
  "__END_OF_PART__"
end

#is_merge?(line) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/changelog_parser.rb', line 37

def is_merge?(line)
  line =~ /Merge/
end

#is_version_bump?(line) ⇒ Boolean

Returns:

  • (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_linesObject



22
23
24
# File 'lib/changelog_parser.rb', line 22

def log_to_lines
  @log.split(commit_message_divider).collect{ |l| l.gsub("\n", " ") }
end

#parse_linesObject



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


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)
  author            = commit_parts[2]
  commit_message    = commit_parts[1].to_s
  changelog_message = commit_message.scan(/changelog:\s(.*)/i).flatten.first

  if changelog_message
    puts "   * #{changelog_message.strip} - #{author}"
  else
    puts "   * #{commit_message.strip} - #{author}" if @all
  end
end


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_logObject



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 << commit_message_divider
  @log = `git log -n 100 --no-merges --format='#{format}'`
end