summaryrefslogtreecommitdiff
path: root/app/models/network/commit.rb
blob: 3cd0c015fa021edb2626836e820ddad609a691c8 (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
34
35
36
37
38
39
require "grit"

module Network
  class Commit
    include ActionView::Helpers::TagHelper

    attr_reader :refs
    attr_accessor :time, :spaces, :parent_spaces

    def initialize(raw_commit, refs)
      @commit = Gitlab::Git::Commit.new(raw_commit)
      @time = -1
      @spaces = []
      @parent_spaces = []
      @refs = refs || []
    end

    def method_missing(m, *args, &block)
      @commit.send(m, *args, &block)
    end

    def space
      if @spaces.size > 0
        @spaces.first
      else
        0
      end
    end

    def parents(map)
      @commit.parents.map do |p|
        if map.include?(p.id)
          map[p.id]
        end
      end
      .compact
    end
  end
end