Sha256: df12a2d0ac73afb160c615048bd3352882c98a4141b44d25092eb948b06cadd8

Contents?: true

Size: 1.6 KB

Versions: 10

Compression:

Stored size: 1.6 KB

Contents

require 'thor'
require 'gitx'
require 'gitx/cli/base_command'
require 'gitx/cli/update_command'
require 'gitx/github'

module Gitx
  module Cli
    class ReleaseCommand < BaseCommand
      include Gitx::Github

      desc 'release', 'release the current branch to production'
      method_option :cleanup, type: :boolean, desc: 'cleanup merged branches after release'
      def release(branch = nil)
        return unless yes?("Release #{current_branch.name} to #{Gitx::BASE_BRANCH}? (y/n)", :green)

        branch ||= current_branch.name
        assert_not_protected_branch!(branch, 'release')
        checkout_branch(branch)
        execute_command(UpdateCommand, :update)

        pull_request = find_or_create_pull_request(branch)
        return unless confirm_branch_status?(branch)

        checkout_branch Gitx::BASE_BRANCH
        run_cmd "git pull origin #{Gitx::BASE_BRANCH}"
        run_cmd %Q(git merge --no-ff -m "[gitx] Releasing #{branch} to #{Gitx::BASE_BRANCH} (Pull request ##{pull_request.number})" #{branch})
        run_cmd 'git push origin HEAD'

        after_release
      end

      private

      def confirm_branch_status?(branch)
        status = branch_status(branch)
        if status == 'success'
          true
        else
          yes?("Branch status is currently: #{status}.  Proceed with release? (y/n)", :red)
        end
      end

      def after_release
        after_release_scripts = config.after_release_scripts.dup
        after_release_scripts << 'git cleanup' if options[:cleanup]
        after_release_scripts.each do |cmd|
          run_cmd cmd
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
gitx-2.20.0 lib/gitx/cli/release_command.rb
gitx-2.20.0.ci.117.1 lib/gitx/cli/release_command.rb
gitx-2.19.0.ci.114.1 lib/gitx/cli/release_command.rb
gitx-2.19.0.ci.112.1 lib/gitx/cli/release_command.rb
gitx-2.19.0 lib/gitx/cli/release_command.rb
gitx-2.18.0.ci.106.1 lib/gitx/cli/release_command.rb
gitx-2.18.0 lib/gitx/cli/release_command.rb
gitx-2.18.0.pre.ci.104.1 lib/gitx/cli/release_command.rb
gitx-2.18.0.pre lib/gitx/cli/release_command.rb
gitx-2.17.0.pre.ci.101.1 lib/gitx/cli/release_command.rb