summaryrefslogtreecommitdiff
path: root/lib/gitlab/graphql/representation/submodule_tree_entry.rb
blob: 65716dff75d1853da68c73fa78e48bbcb2f5d870 (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
# frozen_string_literal: true

module Gitlab
  module Graphql
    module Representation
      class SubmoduleTreeEntry < SimpleDelegator
        class << self
          def decorate(submodules, tree)
            repository = tree.repository
            submodule_links = Gitlab::SubmoduleLinks.new(repository)

            submodules.map do |submodule|
              self.new(submodule, submodule_links.for(submodule, tree.sha))
            end
          end
        end

        def initialize(submodule, submodule_links)
          @submodule_links = submodule_links

          super(submodule)
        end

        def web_url
          @submodule_links.first
        end

        def tree_url
          @submodule_links.last
        end
      end
    end
  end
end