class ProjectReleaser::Project::Repository

Constants

DEFAULT_VERSION
VERSION_PARTS

Public Class Methods

new(repo_path) click to toggle source
# File lib/project_releaser/project/repository.rb, line 11
def initialize(repo_path)
  @git = open_repository(repo_path)
end

Public Instance Methods

checkout(branch) click to toggle source
# File lib/project_releaser/project/repository.rb, line 56
def checkout(branch)
  @git.checkout branch
rescue Git::GitExecuteError
  raise MissingBranch, "Branch '#{branch}' is missing"
end
current_branch() click to toggle source
# File lib/project_releaser/project/repository.rb, line 50
def current_branch
  raise RepositoryHasNoBranches unless @git.branches.count > 0

  @git.branches.find(&:current).name
end
current_version() click to toggle source
# File lib/project_releaser/project/repository.rb, line 15
def current_version
  Hash[VERSION_PARTS.zip versions.last]
end
fetch_tags() click to toggle source
# File lib/project_releaser/project/repository.rb, line 62
def fetch_tags
  @git.remotes.each { |r| @git.fetch(r.name, tags: true) }
end
has_branch?(branch_name) click to toggle source
# File lib/project_releaser/project/repository.rb, line 66
def has_branch?(branch_name)
  @git.branches.map(&:name).include? branch_name.to_s
end
merge(target_branch, source_branch) click to toggle source
# File lib/project_releaser/project/repository.rb, line 29
def merge(target_branch, source_branch)
  checkout target_branch
  begin
    @git.merge source_branch
  rescue
    Kernel.system 'git mergetool'
    @git.commit 'resolved merge conflict'
  end
end
pull(branches) click to toggle source
# File lib/project_releaser/project/repository.rb, line 19
def pull(branches)
  branches.each do |branch|
    checkout branch
    @git.remotes.each do |remote|
      @git.fetch remote.name # otherwise it wouldnt get new tags...
      @git.pull remote.name, branch
    end
  end
end
push(branch, version_name) click to toggle source
# File lib/project_releaser/project/repository.rb, line 39
def push(branch, version_name)
  checkout branch
  @git.add_tag version_name
  @git.push 'origin', branch
  @git.push 'origin', version_name
end
remotes() click to toggle source
# File lib/project_releaser/project/repository.rb, line 46
def remotes
  Hash[@git.remotes.map { |r| [r.name, r.url] }]
end
returning_to_current_branch() { |self| ... } click to toggle source
# File lib/project_releaser/project/repository.rb, line 70
def returning_to_current_branch
  branch = current_branch
  yield self
  checkout branch
end

Private Instance Methods

open_repository(repo_path) click to toggle source
# File lib/project_releaser/project/repository.rb, line 92
def open_repository(repo_path)
  ::Git.open repo_path
rescue ArgumentError
  raise RepositoryNotFound
end
versions() click to toggle source
# File lib/project_releaser/project/repository.rb, line 78
def versions
  tags = @git.tags
  return [DEFAULT_VERSION] if tags.empty?
  valid_tags = tags
  .map(&:name)
  .select { |n| n =~ /\Av?\d+(\.\d+){1,2}\z/ }

  return [DEFAULT_VERSION] if valid_tags.empty?
  valid_tags
    .map { |n| n.sub('v', '').split('.').map(&:to_i) }
    .map { |a| a.fill(0, a.size..2) }
    .sort
end