Sha256: 7b3f50856e75e908dfd50fc9ec542f2f55c55d852547f6f7a7b0b324c26efdc7

Contents?: true

Size: 1.27 KB

Versions: 10

Compression:

Stored size: 1.27 KB

Contents

require 'thor'
require 'gitx'
require 'gitx/cli/base_command'

module Gitx
  module Cli
    class StartCommand < BaseCommand
      EXAMPLE_BRANCH_NAMES = %w( api-fix-invalid-auth desktop-cleanup-avatar-markup share-form-add-edit-link )
      VALID_BRANCH_NAME_REGEX = /^[A-Za-z0-9\-_]+$/

      desc 'start', 'start a new git branch with latest changes from master'
      method_option :issue, type: :numeric, aliases: '-i', desc: 'Github issue number'
      def start(branch_name = nil)
        until valid_new_branch_name?(branch_name)
          branch_name = ask("What would you like to name your branch? (ex: #{EXAMPLE_BRANCH_NAMES.sample})")
        end

        checkout_branch config.base_branch
        run_git_cmd 'pull'
        repo.create_branch branch_name, config.base_branch
        checkout_branch branch_name
        run_git_cmd('commit', '--allow-empty', '--message', "Starting work on #{branch_name} (Issue ##{options[:issue]})") if options[:issue]
      end

      private

      def valid_new_branch_name?(branch)
        return false if repo_branches.include?(branch)
        branch =~ VALID_BRANCH_NAME_REGEX
      end

      def repo_branches
        @branch_names ||= repo.branches.each_name.map do |branch|
          branch.split('/').last
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
gitx-2.22.0.ci.154.1 lib/gitx/cli/start_command.rb
gitx-2.22.0 lib/gitx/cli/start_command.rb
gitx-2.21.5.ci.153.1 lib/gitx/cli/start_command.rb
gitx-2.21.5.ci.151.1 lib/gitx/cli/start_command.rb
gitx-2.21.5 lib/gitx/cli/start_command.rb
gitx-2.21.4.ci.145.1 lib/gitx/cli/start_command.rb
gitx-2.21.4 lib/gitx/cli/start_command.rb
gitx-2.21.3.ci.135.1 lib/gitx/cli/start_command.rb
gitx-2.21.3 lib/gitx/cli/start_command.rb
gitx-2.21.2.ci.134.1 lib/gitx/cli/start_command.rb