Sha256: 95651919c08b582802b78a05ae4e7ce5d923bef674313bf08ee80f0372dc979d

Contents?: true

Size: 1.46 KB

Versions: 64

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

require "dependabot/file_fetchers/base"

module Dependabot
  module FileFetchers
    module Go
      class Modules < Dependabot::FileFetchers::Base
        def self.required_files_in?(filenames)
          filenames.include?("go.mod")
        end

        def self.required_files_message
          "Repo must contain a go.mod."
        end

        private

        def fetch_files
          unless go_mod
            raise(
              Dependabot::DependencyFileNotFound,
              File.join(directory, "go.mod")
            )
          end

          fetched_files = [go_mod]

          # Fetch the (optional) go.sum
          fetched_files << go_sum if go_sum

          # Fetch the main.go file if present, as this will later identify
          # this repo as an app.
          fetched_files << main if main

          fetched_files
        end

        def go_mod
          @go_mod ||= fetch_file_if_present("go.mod")
        end

        def go_sum
          @go_sum ||= fetch_file_if_present("go.sum")
        end

        def main
          return @main if @main

          go_files = repo_contents.select { |f| f.name.end_with?(".go") }

          go_files.each do |go_file|
            file = fetch_file_from_host(go_file.name, type: "package_main")
            next unless file.content.match?(/\s*package\s+main/)

            return @main = file.tap { |f| f.support_file = true }
          end

          nil
        end
      end
    end
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
dependabot-core-0.86.25 lib/dependabot/file_fetchers/go/modules.rb
dependabot-core-0.86.24 lib/dependabot/file_fetchers/go/modules.rb
dependabot-core-0.86.23 lib/dependabot/file_fetchers/go/modules.rb
dependabot-core-0.86.22 lib/dependabot/file_fetchers/go/modules.rb
dependabot-core-0.86.21 lib/dependabot/file_fetchers/go/modules.rb
dependabot-core-0.86.20 lib/dependabot/file_fetchers/go/modules.rb
dependabot-core-0.86.19 lib/dependabot/file_fetchers/go/modules.rb
dependabot-core-0.86.18 lib/dependabot/file_fetchers/go/modules.rb
dependabot-core-0.86.17 lib/dependabot/file_fetchers/go/modules.rb
dependabot-core-0.86.16 lib/dependabot/file_fetchers/go/modules.rb
dependabot-core-0.86.15 lib/dependabot/file_fetchers/go/modules.rb
dependabot-core-0.86.14 lib/dependabot/file_fetchers/go/modules.rb
dependabot-core-0.86.13 lib/dependabot/file_fetchers/go/modules.rb
dependabot-core-0.86.12 lib/dependabot/file_fetchers/go/modules.rb
dependabot-core-0.86.11 lib/dependabot/file_fetchers/go/modules.rb
dependabot-core-0.86.10 lib/dependabot/file_fetchers/go/modules.rb
dependabot-core-0.86.9 lib/dependabot/file_fetchers/go/modules.rb
dependabot-core-0.86.8 lib/dependabot/file_fetchers/go/modules.rb
dependabot-core-0.86.7 lib/dependabot/file_fetchers/go/modules.rb
dependabot-core-0.86.6 lib/dependabot/file_fetchers/go/modules.rb