repo.rb 1.25 KB
Newer Older
1 2
# frozen_string_literal: true

3 4 5 6 7 8 9
module Bitbucket
  module Representation
    class Repo < Representation::Base
      attr_reader :owner, :slug

      def initialize(raw)
        super(raw)
10
      end
11

12 13 14 15 16 17 18 19 20 21
      def owner_and_slug
        @owner_and_slug ||= full_name.split('/', 2)
      end

      def owner
        owner_and_slug.first
      end

      def slug
        owner_and_slug.last
22 23 24 25 26 27
      end

      def clone_url(token = nil)
        url = raw['links']['clone'].find { |link| link['name'] == 'https' }.fetch('href')

        if token.present?
Douwe Maan's avatar
Douwe Maan committed
28
          clone_url = URI.parse(url)
29 30
          clone_url.user = "x-token-auth:#{token}"
          clone_url.to_s
31 32 33 34 35 36 37 38 39 40 41 42 43
        else
          url
        end
      end

      def description
        raw['description']
      end

      def full_name
        raw['full_name']
      end

44
      def issues_enabled?
45 46 47 48 49 50 51 52 53 54 55
        raw['has_issues']
      end

      def name
        raw['name']
      end

      def valid?
        raw['scm'] == 'git'
      end

56 57 58 59
      def has_wiki?
        raw['has_wiki']
      end

60 61 62 63 64 65 66 67 68 69 70 71 72 73
      def visibility_level
        if raw['is_private']
          Gitlab::VisibilityLevel::PRIVATE
        else
          Gitlab::VisibilityLevel::PUBLIC
        end
      end

      def to_s
        full_name
      end
    end
  end
end