Sha256: 76ba1b761f1d7163f68c5c9c358357ee43eedaddfbe8c0ceb69bf5283541a9ca

Contents?: true

Size: 957 Bytes

Versions: 2

Compression:

Stored size: 957 Bytes

Contents

# frozen_string_literal: true

require "refinements/string"

module Git
  module Lint
    module Commits
      # Automatically detects and loads host.
      class Loader
        include Dependencies[
          :git,
          :environment,
          circle_ci: "hosts.circle_ci",
          git_hub_action: "hosts.git_hub_action",
          netlify_ci: "hosts.git_hub_action",
          local: "hosts.local"
        ]

        using Refinements::String

        def call
          message = "Invalid repository. Are you within a Git repository?"
          fail Errors::Base, message unless git.exist?

          host.call
        end

        private

        def host
          if key? "CIRCLECI" then circle_ci
          elsif key? "GITHUB_ACTIONS" then git_hub_action
          elsif key? "NETLIFY" then netlify_ci
          else local
          end
        end

        def key?(key) = environment.fetch(key, "false").to_bool
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
git-lint-9.1.0 lib/git/lint/commits/loader.rb
git-lint-9.0.0 lib/git/lint/commits/loader.rb