Class: KnapsackPro::Crypto::BranchEncryptor

Inherits:
Object
  • Object
show all
Defined in:
lib/knapsack_pro/crypto/branch_encryptor.rb

Constant Summary collapse

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',
]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(branch) ⇒ BranchEncryptor

Returns a new instance of BranchEncryptor.



32
33
34
# File 'lib/knapsack_pro/crypto/branch_encryptor.rb', line 32

def initialize(branch)
  @branch = branch
end

Class Method Details

.call(branch) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/knapsack_pro/crypto/branch_encryptor.rb', line 24

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

Instance Method Details

#callObject



36
37
38
39
40
41
42
# File 'lib/knapsack_pro/crypto/branch_encryptor.rb', line 36

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