Class: Schmersion::CommitParser

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

Constant Summary collapse

MAX_COMMITS =
100_000_000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, start_commit, end_commit, **options) ⇒ CommitParser

Returns a new instance of CommitParser.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/schmersion/commit_parser.rb', line 13

def initialize(repo, start_commit, end_commit, **options)
  @start_commit = start_commit
  @end_commit = end_commit
  @options = options

  @commits = []

  if @start_commit == :start
    # If start is provided, use the first commit as the initial reference.
    # Ideally this would actually start from the beginning of time and include
    # this commit.
    first_commit = repo.log(MAX_COMMITS).last
    @start_commit = first_commit.sha
  end

  @raw_commits = repo.log(MAX_COMMITS).between(@start_commit, @end_commit)

  parse
end

Instance Attribute Details

#commitsObject (readonly)

Returns the value of attribute commits.



11
12
13
# File 'lib/schmersion/commit_parser.rb', line 11

def commits
  @commits
end

Instance Method Details

#next_version_after(current_version, **options) ⇒ Object



46
47
48
49
# File 'lib/schmersion/commit_parser.rb', line 46

def next_version_after(current_version, **options)
  calculator = VersionCalculator.new(current_version, commits, **options)
  calculator.calculate
end

#parseObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/schmersion/commit_parser.rb', line 33

def parse
  @commits = []
  @raw_commits.each do |commit|
    commit = Commit.new(commit)

    next if skip_commit?(commit)

    @commits << commit
  end
  @commits = @commits.reverse
  @commits
end

#skip_commit?(commit) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
# File 'lib/schmersion/commit_parser.rb', line 51

def skip_commit?(commit)
  # We never want to see merge commits...
  return true if commit.raw_commit.parents.size > 1
  return true unless commit.message.valid?

  false
end