summaryrefslogtreecommitdiff
path: root/lib/gitlab/git/branch.rb
blob: 9447cfa0fb68af9063f95f0a9b306304407a6e8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true

module Gitlab
  module Git
    class Branch < Ref
      STALE_BRANCH_THRESHOLD = 3.months

      def self.find(repo, branch_name)
        if branch_name.is_a?(Gitlab::Git::Branch)
          branch_name
        else
          repo.find_branch(branch_name)
        end
      end

      def initialize(repository, name, target, target_commit)
        super(repository, name, target, target_commit)
      end

      def active?
        self.dereferenced_target.committed_date >= STALE_BRANCH_THRESHOLD.ago
      end

      def stale?
        !active?
      end

      def state
        active? ? :active : :stale
      end
    end
  end
end