Sha256: 1e200d765d3a2856efd5d69baad2cf5431c5b7643f5af3abc8d8eb6561794cdd

Contents?: true

Size: 1.06 KB

Versions: 7

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true
module Shipit
  class Commands
    class << self
      def for(model)
        "#{model.class.name}Commands".constantize.new(model)
      end

      def git_version
        @git_version ||= parse_git_version(%x(git --version))
      end

      def parse_git_version(raw_git_version)
        match_info = raw_git_version.match(/(\d+\.\d+\.\d+)/)
        raise 'git command not found' unless match_info
        Gem::Version.new(match_info[1])
      end
    end

    delegate :git_version, to: :class

    def env
      base_env
    end

    def git(*args)
      kwargs = args.extract_options!
      kwargs[:env] ||= base_env
      Command.new("git", *args, **kwargs)
    end
    ruby2_keywords :git if respond_to?(:ruby2_keywords, true)

    private

    def base_env
      @base_env ||= Shipit.env.merge(
        'GITHUB_DOMAIN' => github.domain,
        'GITHUB_TOKEN' => github.token,
        'GIT_ASKPASS' => Shipit::Engine.root.join('lib', 'snippets', 'git-askpass').realpath.to_s,
      )
    end

    def github
      Shipit.github
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
shipit-engine-0.39.0 lib/shipit/commands.rb
shipit-engine-0.38.0 lib/shipit/commands.rb
shipit-engine-0.37.0 lib/shipit/commands.rb
shipit-engine-0.36.1 lib/shipit/commands.rb
shipit-engine-0.36.0 lib/shipit/commands.rb
shipit-engine-0.35.1 lib/shipit/commands.rb
shipit-engine-0.35.0 lib/shipit/commands.rb