2018-11-09 13:39:43 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-04 13:43:06 -05:00
|
|
|
module Gitlab
|
|
|
|
module Git
|
|
|
|
class Branch < Ref
|
2017-11-15 09:56:36 -05:00
|
|
|
STALE_BRANCH_THRESHOLD = 3.months
|
|
|
|
|
2018-01-30 05:22:08 -05:00
|
|
|
def self.find(repo, branch_name)
|
|
|
|
if branch_name.is_a?(Gitlab::Git::Branch)
|
|
|
|
branch_name
|
|
|
|
else
|
|
|
|
repo.find_branch(branch_name)
|
2017-10-27 11:55:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-14 09:30:58 -04:00
|
|
|
def initialize(repository, name, target, target_commit)
|
|
|
|
super(repository, name, target, target_commit)
|
2017-03-17 15:36:46 -04:00
|
|
|
end
|
2017-11-15 09:56:36 -05:00
|
|
|
|
|
|
|
def active?
|
|
|
|
self.dereferenced_target.committed_date >= STALE_BRANCH_THRESHOLD.ago
|
|
|
|
end
|
|
|
|
|
|
|
|
def stale?
|
|
|
|
!active?
|
|
|
|
end
|
|
|
|
|
|
|
|
def state
|
|
|
|
active? ? :active : :stale
|
|
|
|
end
|
2021-05-12 11:10:25 -04:00
|
|
|
|
|
|
|
def cache_key
|
|
|
|
"branch:" + Digest::SHA1.hexdigest([name, target, dereferenced_target&.sha].join(':'))
|
|
|
|
end
|
2017-01-04 13:43:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|