class SemVerComponents::LocalGit

Public Class Methods

new(git_repo, git_from, git_to) click to toggle source

Constructor

Parameters
  • git_repo (String): The git repository to analyze

  • git_from (String or nil): The git from ref

  • git_to (String): The git to ref

# File lib/sem_ver_components/local_git.rb, line 15
def initialize(git_repo, git_from, git_to)
  @git_repo = git_repo
  @git_from = git_from
  @git_to = git_to
  @git = Git.open(@git_repo)
end

Public Instance Methods

analyze_commits() click to toggle source

Semantically analyze commits.

Result
  • Array< Hash<Symbol, Object> >: The commits information:

    • components_bump_levels (Hash<String or nil, Integer>): Set of bump levels (0: patch, 1: minor, 2: major) per component name (nil for global)

    • commit (Git::Object::Commit): Corresponding git commit

# File lib/sem_ver_components/local_git.rb, line 38
def analyze_commits
  git_log.between(git_from.nil? ? git_log.last.sha : git_from, git_to).map do |git_commit|
    # Analyze the message
    # Always consider a minimum of global patch bump per commit.
    components_bump_levels = { nil => [0] }
    git_commit.message.scan(/\[([^\]]+)\]/).flatten(1).each do |commit_label|
      commit_type, component = commit_label =~ /^(.+)\((.+)\)$/ ? [$1, $2] : [commit_label, nil]
      components_bump_levels[component] = [] unless components_bump_levels.key?(component)
      components_bump_levels[component] <<
        case commit_type.downcase
        when 'break', 'breaking', 'major'
          2
        when 'feat', 'feature', 'minor'
          1
        else
          0
        end
    end
    {
      commit: git_commit,
      components_bump_levels: Hash[components_bump_levels.map { |component, component_bump_levels| [component, component_bump_levels.max] }]
    }
  end
end
git_log() click to toggle source

Get full the git log. Keep a cache of it.

Result
  • Array< Git::Object::Commit >: Full git log

# File lib/sem_ver_components/local_git.rb, line 27
def git_log
  @git_log = @git.log(nil) unless defined?(@git_log)
  @git_log
end
on_release_branch?() click to toggle source

Is the git to ref part of a release branch?

Result
  • Boolean: Is the git to ref part of a release branch?

# File lib/sem_ver_components/local_git.rb, line 67
def on_release_branch?
  @git_to == 'master'
end