Sha256: 8b9359fae19d8bb4ffa341df21b1a05e5d136484b9d4da34d81beb61d6871b08

Contents?: true

Size: 1000 Bytes

Versions: 23

Compression:

Stored size: 1000 Bytes

Contents

# frozen_string_literal: true

module KnapsackPro
  module Crypto
    class BranchEncryptor
      NON_ENCRYPTABLE_BRANCHES = [
        'master',
        'main',
        'develop',
        'development',
        'dev',
        'staging',
        'production',
        # GitHub Actions has branch names starting with refs/heads/
        'refs/heads/master',
        'refs/heads/main',
        'refs/heads/develop',
        'refs/heads/development',
        'refs/heads/dev',
        'refs/heads/staging',
        'refs/heads/production',
      ]

      def self.call(branch)
        if KnapsackPro::Config::Env.branch_encrypted?
          new(branch).call
        else
          branch
        end
      end

      def initialize(branch)
        @branch = branch
      end

      def call
        if NON_ENCRYPTABLE_BRANCHES.include?(branch)
          branch
        else
          Digestor.salt_hexdigest(branch)[0..6]
        end
      end

      private

      attr_reader :branch
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
knapsack_pro-7.13.0 lib/knapsack_pro/crypto/branch_encryptor.rb
knapsack_pro-7.12.1 lib/knapsack_pro/crypto/branch_encryptor.rb
knapsack_pro-7.12.0 lib/knapsack_pro/crypto/branch_encryptor.rb
knapsack_pro-7.11.0 lib/knapsack_pro/crypto/branch_encryptor.rb
knapsack_pro-7.10.0 lib/knapsack_pro/crypto/branch_encryptor.rb
knapsack_pro-7.9.0 lib/knapsack_pro/crypto/branch_encryptor.rb
knapsack_pro-7.8.2 lib/knapsack_pro/crypto/branch_encryptor.rb
knapsack_pro-7.8.1 lib/knapsack_pro/crypto/branch_encryptor.rb
knapsack_pro-7.8.0 lib/knapsack_pro/crypto/branch_encryptor.rb
knapsack_pro-7.7.0 lib/knapsack_pro/crypto/branch_encryptor.rb
knapsack_pro-7.6.2 lib/knapsack_pro/crypto/branch_encryptor.rb
knapsack_pro-7.6.1 lib/knapsack_pro/crypto/branch_encryptor.rb
knapsack_pro-7.6.0 lib/knapsack_pro/crypto/branch_encryptor.rb
knapsack_pro-7.1.0 lib/knapsack_pro/crypto/branch_encryptor.rb
knapsack_pro-7.0.1 lib/knapsack_pro/crypto/branch_encryptor.rb
knapsack_pro-7.0.0 lib/knapsack_pro/crypto/branch_encryptor.rb
knapsack_pro-6.0.4 lib/knapsack_pro/crypto/branch_encryptor.rb
knapsack_pro-6.0.3 lib/knapsack_pro/crypto/branch_encryptor.rb
knapsack_pro-6.0.2 lib/knapsack_pro/crypto/branch_encryptor.rb
knapsack_pro-6.0.1 lib/knapsack_pro/crypto/branch_encryptor.rb