Sha256: 92161d10b865862c29cfe78b0c77abffe30ae5b98bc6a2fcc72704728ba60569

Contents?: true

Size: 1.43 KB

Versions: 4

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require 'cgi'

# Helper methods for common Git operations: checking / creating branches, preparing a pull request and
# committing / pushing files.
module GitHelper
  def self.current_branch
    `git --no-pager branch --show-current`.chomp
  end

  def self.check_or_create_branch(new_version)
    release_branch = "release/#{new_version}"
    branch_exists = !`git --no-pager branch -a --list --no-color #{release_branch}`.chomp.empty?
    if current_branch == release_branch
      puts 'Already on release branch'
    elsif branch_exists
      Rake.sh('git', 'checkout', release_branch)
    else # create it
      abort('Aborted, as not run from trunk nor release branch') unless current_branch == 'trunk' || Console.confirm("You are not on 'trunk', nor already on '#{release_branch}'. Do you really want to cut the release branch from #{current_branch}?")

      Rake.sh('git', 'checkout', '-b', release_branch)
    end
  end

  def self.prepare_github_pr(head, base, title, body)
    require 'open-uri'
    qtitle = CGI.escape(title)
    qbody = CGI.escape(body)
    uri = "https://github.com/Automattic/dangermattic/compare/#{base}...#{head}?expand=1&title=#{qtitle}&body=#{qbody}"
    Rake.sh('open', uri)
  end

  def self.commit_files(message, files, push: true)
    Rake.sh('git', 'add', *files)
    Rake.sh('git', 'commit', '-m', message)
    Rake.sh('git', 'push', '-q', '-u', 'origin', current_branch) if push
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
danger-dangermattic-1.2.2 rakelib/git_helpers.rake
danger-dangermattic-1.2.1 rakelib/git_helpers.rake
danger-dangermattic-1.2.0 rakelib/git_helpers.rake
danger-dangermattic-1.1.2 rakelib/git_helpers.rake