Class: ChangesSince::CommitParser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, options) ⇒ CommitParser

Returns a new instance of CommitParser.



7
8
9
10
11
# File 'lib/changes_since/commit_parser.rb', line 7

def initialize(tag, options)
  git   = Git.open(Dir.pwd)
  @log  = git.log(100000).between(tag)
  @options = options
end

Instance Attribute Details

#logObject (readonly)

Returns the value of attribute log.



5
6
7
# File 'lib/changes_since/commit_parser.rb', line 5

def log
  @log
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/changes_since/commit_parser.rb', line 5

def options
  @options
end

Instance Method Details

#parseObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/changes_since/commit_parser.rb', line 42

def parse
  commits = if options[:all]
    parse_all_commits
  else
    log.select { |commit| commit.message =~ /Merge pull request/ }
  end

  if options[:author_filter]
    author_re = /#{options[:author_filter].join("|")}/i
    commits = commits.select do |commit|
      [commit.author.name, commit.author.email].any? do |str|
        str =~ author_re
      end
    end
  end
  commits
end

#parse_all_commitsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/changes_since/commit_parser.rb', line 13

def parse_all_commits
  interesting = Set.new
  all_commits = log.to_a

  link_re = /^\s*\[(.*?)\]/m
  linked_commits, remaining_commits = all_commits.partition do |commit|
    commit.message =~ link_re
  end

  linked_commits.uniq! do |commit|
    commit.message[link_re,1]
  end

  interesting = interesting + linked_commits

  interesting_re = /
    (?:\#(bug|public|internal)) | # anything explicitly tagged
    (?:closes\s\#\d+) | # a squash-merge commit closing the linked PR
    (?:Merge\spull\srequest) # a straight PR merge
  /xmi

  remaining_commits.each do |commit|
    if commit.message =~ interesting_re
      interesting << commit
    end
  end
  commits = interesting.to_a
end