module MrBump

Add helper functions to the MrBump namespace

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at mozilla.org/MPL/2.0/.

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at mozilla.org/MPL/2.0/.

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at mozilla.org/MPL/2.0/.

Public Class Methods

all_tagged_versions() click to toggle source
# File lib/mr_bump.rb, line 86
def self.all_tagged_versions
  all_tags.map do |tag|
    begin
      MrBump::Version.new(tag)
    rescue
      nil
    end
  end.compact
end
all_tags() click to toggle source
# File lib/mr_bump.rb, line 82
def self.all_tags
  `git tag -l`.each_line.map(&:strip)
end
change_log_items_for_range(rev, head) click to toggle source
# File lib/mr_bump.rb, line 113
def self.change_log_items_for_range(rev, head)
  ignored_branch = Regexp.new("^(#{release_branch_regex}|master|develop)$")
  make_change = lambda do |title, comment = []|
    change = MrBump::Change.from_gitlog(config_file, title, comment)
    change unless ignored_branch.match(change.branch_name)
  end

  chunked_log = merge_logs(rev, head).chunk { |change| change[/^Merge/].nil? }
  chunked_log.each_slice(2).map do |merge_str, comment|
    begin
      no_comment_changes = merge_str[1][0..-2].map(&make_change)
      commented_changes = make_change.call(merge_str[1][-1], comment.nil? ? [] : comment[1])
      no_comment_changes.push(commented_changes)
    rescue ArgumentError => e
      puts e
    end
  end.flatten.compact
end
config_file() click to toggle source
# File lib/mr_bump.rb, line 143
def self.config_file
  @config_file ||= MrBump::Config.new.config
end
current_branch() click to toggle source
# File lib/mr_bump.rb, line 13
def self.current_branch
  @current_branch ||= `git rev-parse --abbrev-ref HEAD`.strip.freeze
end
current_master() click to toggle source
# File lib/mr_bump.rb, line 101
def self.current_master
  uat = current_uat_major
  all_tagged_versions.select { |ver| ver < uat }.max
end
current_uat() click to toggle source
# File lib/mr_bump.rb, line 96
def self.current_uat
  uat = current_uat_major
  all_tagged_versions.select { |ver| ver.major == uat.major && ver.minor == uat.minor }.max
end
current_uat_major() click to toggle source
# File lib/mr_bump.rb, line 73
def self.current_uat_major
  branches = `git branch -r`.each_line.map(&:strip)
  latest_release_from_list(branches)
end
file_prepend(file, str) click to toggle source
# File lib/mr_bump.rb, line 132
def self.file_prepend(file, str)
  new_contents = ''
  File.open(file, 'r') do |fd|
    contents = fd.read
    new_contents = str + contents
  end
  File.open(file, 'w') do |fd|
    fd.write(new_contents)
  end
end
git_config() click to toggle source
# File lib/mr_bump.rb, line 153
def self.git_config
  @git_config ||= MrBump::GitConfig.from_current_path
end
last_release() click to toggle source
# File lib/mr_bump.rb, line 46
def self.last_release
  if on_release_branch? || (on_master_branch? && release_stale?)
    MrBump.current_uat
  elsif on_master_branch?
    MrBump.current_master
  elsif on_develop_branch?
    MrBump.current_uat_major
  end
end
latest_release_from_list(branches) click to toggle source
# File lib/mr_bump.rb, line 65
def self.latest_release_from_list(branches)
  regex = Regexp.new("^origin/#{release_branch_regex}$")
  branches.map do |branch|
    matches = regex.match(branch.force_encoding("UTF-8"))
    MrBump::Version.new(matches[1]) if matches
  end.compact.max || MrBump::Version.new('0.0.0')
end
merge_logs(rev, head) click to toggle source
# File lib/mr_bump.rb, line 106
def self.merge_logs(rev, head)
  git_cmd = "git log --pretty='format:%B' --grep " \
            "'(^Merge pull request | into #{current_branch}$)' --merges -E"
  log = `#{git_cmd} #{rev}..#{head}`
  log.each_line.map(&:strip).select { |str| !(str.nil? || str == '' || str[0] == '#') }
end
next_release() click to toggle source
# File lib/mr_bump.rb, line 56
def self.next_release
  return nil unless last_release
  if on_release_branch? || on_master_branch?
    last_release.bump_patch
  elsif on_develop_branch?
    last_release.bump_minor
  end
end
on_develop_branch?() click to toggle source
# File lib/mr_bump.rb, line 38
def self.on_develop_branch?
  !MrBump.current_branch[/^develop$/].nil?
end
on_master_branch?() click to toggle source
# File lib/mr_bump.rb, line 34
def self.on_master_branch?
  !MrBump.current_branch[/^master$/].nil?
end
on_release_branch?() click to toggle source
# File lib/mr_bump.rb, line 29
def self.on_release_branch?
  regex = Regexp.new("^#{release_branch_regex}$")
  !MrBump.current_branch[regex].nil?
end
release_branch_for_version(ver) click to toggle source
# File lib/mr_bump.rb, line 23
def self.release_branch_for_version(ver)
  prefix = config_file['release_prefix']
  suffix = config_file['release_suffix']
  "#{prefix}#{ver.major}.#{ver.minor}.0#{suffix}"
end
release_branch_regex() click to toggle source
# File lib/mr_bump.rb, line 17
def self.release_branch_regex
  prefix = Regexp.escape(config_file['release_prefix'])
  suffix = Regexp.escape(config_file['release_suffix'])
  "#{prefix}(\\d+\\.\\d+)(\\.\\d+)?#{suffix}"
end
release_stale?() click to toggle source
# File lib/mr_bump.rb, line 42
def self.release_stale?
  !`git branch master --contains #{MrBump.current_uat_major}`.strip.empty?
end
slack_notifier(version, changelog) click to toggle source
# File lib/mr_bump.rb, line 147
def self.slack_notifier(version, changelog)
  if config_file.key? 'slack'
    MrBump::Slack.new(git_config, config_file).bump(version, changelog)
  end
end
uat_branch() click to toggle source
# File lib/mr_bump.rb, line 78
def self.uat_branch
  release_branch_for_version(current_uat_major)
end