Sha256: 4e3d80bd7728e733d99fa91ae5c31cba242cd01bab9ecc042195b1c5d794bf9f

Contents?: true

Size: 1.57 KB

Versions: 15

Compression:

Stored size: 1.57 KB

Contents

require 'thor'
require 'gitx'
require 'gitx/cli/base_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 #{config.base_branch}? (y/n)", :green)

        branch ||= current_branch.name
        assert_not_protected_branch!(branch, 'release')
        checkout_branch(branch)
        run_git_cmd 'update'

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

        checkout_branch config.base_branch
        run_git_cmd 'pull', 'origin', config.base_branch
        run_git_cmd 'merge', '--no-ff', '--message', "[gitx] Releasing #{branch} to #{config.base_branch} (Pull request ##{pull_request.number})", branch
        run_git_cmd '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

15 entries across 15 versions & 1 rubygems

Version Path
gitx-3.0.0.ci.188.1 lib/gitx/cli/release_command.rb
gitx-3.0.0 lib/gitx/cli/release_command.rb
gitx-2.23.2.ci.182.1 lib/gitx/cli/release_command.rb
gitx-2.23.2 lib/gitx/cli/release_command.rb
gitx-2.23.1.ci.174.1 lib/gitx/cli/release_command.rb
gitx-2.23.1 lib/gitx/cli/release_command.rb
gitx-2.23.0.ci.162.1 lib/gitx/cli/release_command.rb
gitx-2.23.0 lib/gitx/cli/release_command.rb
gitx-2.22.0.ci.154.1 lib/gitx/cli/release_command.rb
gitx-2.22.0 lib/gitx/cli/release_command.rb
gitx-2.21.5.ci.153.1 lib/gitx/cli/release_command.rb
gitx-2.21.5.ci.151.1 lib/gitx/cli/release_command.rb
gitx-2.21.5 lib/gitx/cli/release_command.rb
gitx-2.21.4.ci.145.1 lib/gitx/cli/release_command.rb
gitx-2.21.4 lib/gitx/cli/release_command.rb