Sha256: 1db3b4bd26ae018520b639ddb6089d915d982633b707def79fe08b002861fdd8

Contents?: true

Size: 1.67 KB

Versions: 216

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

require "gitlab"

module Dependabot
  module Clients
    class Gitlab
      #######################
      # Constructor methods #
      #######################

      def self.for_source(source:, credentials:)
        access_token =
          credentials.
          select { |cred| cred["type"] == "git_source" }.
          find { |cred| cred["host"] == source.hostname }&.
          fetch("password")

        new(
          endpoint: source.api_endpoint,
          private_token: access_token || ""
        )
      end

      def self.for_gitlab_dot_com(credentials:)
        access_token =
          credentials.
          select { |cred| cred["type"] == "git_source" }.
          find { |cred| cred["host"] == "gitlab.com" }&.
          fetch("password")

        new(
          endpoint: "https://gitlab.com/api/v4",
          private_token: access_token || ""
        )
      end

      #################
      # VCS Interface #
      #################

      def fetch_commit(repo, branch)
        branch(repo, branch).commit.id
      end

      def fetch_default_branch(repo)
        project(repo).default_branch
      end

      ############
      # Proxying #
      ############

      def initialize(**args)
        @client = ::Gitlab::Client.new(args)
      end

      def method_missing(method_name, *args, &block)
        if @client.respond_to?(method_name)
          mutatable_args = args.map(&:dup)
          @client.public_send(method_name, *mutatable_args, &block)
        else
          super
        end
      end

      def respond_to_missing?(method_name, include_private = false)
        @client.respond_to?(method_name) || super
      end
    end
  end
end

Version data entries

216 entries across 216 versions & 2 rubygems

Version Path
dependabot-common-0.95.69 lib/dependabot/clients/gitlab.rb
dependabot-common-0.95.68 lib/dependabot/clients/gitlab.rb
dependabot-common-0.95.67 lib/dependabot/clients/gitlab.rb
dependabot-common-0.95.66 lib/dependabot/clients/gitlab.rb
dependabot-common-0.95.65 lib/dependabot/clients/gitlab.rb
dependabot-common-0.95.64 lib/dependabot/clients/gitlab.rb
dependabot-common-0.95.63 lib/dependabot/clients/gitlab.rb
dependabot-common-0.95.62 lib/dependabot/clients/gitlab.rb
dependabot-common-0.95.61 lib/dependabot/clients/gitlab.rb
dependabot-common-0.95.60 lib/dependabot/clients/gitlab.rb
dependabot-common-0.95.59 lib/dependabot/clients/gitlab.rb
dependabot-common-0.95.58 lib/dependabot/clients/gitlab.rb
dependabot-common-0.95.57 lib/dependabot/clients/gitlab.rb
dependabot-common-0.95.56 lib/dependabot/clients/gitlab.rb
dependabot-common-0.95.55 lib/dependabot/clients/gitlab.rb
dependabot-common-0.95.54 lib/dependabot/clients/gitlab.rb
dependabot-common-0.95.53 lib/dependabot/clients/gitlab.rb
dependabot-common-0.95.52 lib/dependabot/clients/gitlab.rb
dependabot-common-0.95.51 lib/dependabot/clients/gitlab.rb
dependabot-common-0.95.50 lib/dependabot/clients/gitlab.rb