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.



30
31
32
# File 'lib/knapsack_pro/crypto/branch_encryptor.rb', line 30

def initialize(branch)
  @branch = branch
end

Class Method Details

.call(branch) ⇒ Object



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

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

Instance Method Details

#callObject



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

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