Sha256: bc78e6a9d1bf1a6d9fa3d6b6b791a55100c892eca9e57a3ed2320db7b6eca3ee

Contents?: true

Size: 1.95 KB

Versions: 53

Compression:

Stored size: 1.95 KB

Contents

# typed: true
# frozen_string_literal: true

require "dependabot/file_updaters"
require "dependabot/file_updaters/base"
require "dependabot/shared_helpers"
require "dependabot/errors"

module Dependabot
  module Composer
    class FileUpdater < Dependabot::FileUpdaters::Base
      require_relative "file_updater/manifest_updater"
      require_relative "file_updater/lockfile_updater"

      def self.updated_files_regex
        [
          /^composer\.json$/,
          /^composer\.lock$/
        ]
      end

      def updated_dependency_files
        updated_files = []

        if file_changed?(composer_json)
          updated_files <<
            updated_file(
              file: composer_json,
              content: updated_composer_json_content
            )
        end

        if lockfile
          updated_files <<
            updated_file(file: lockfile, content: updated_lockfile_content)
        end

        if updated_files.none? ||
           updated_files.sort_by(&:name) == dependency_files.sort_by(&:name)
          raise "No files have changed!"
        end

        updated_files
      end

      private

      def check_required_files
        raise "No composer.json!" unless get_original_file("composer.json")
      end

      def updated_composer_json_content
        ManifestUpdater.new(
          dependencies: dependencies,
          manifest: composer_json
        ).updated_manifest_content
      end

      def updated_lockfile_content
        @updated_lockfile_content ||=
          LockfileUpdater.new(
            dependencies: dependencies,
            dependency_files: dependency_files,
            credentials: credentials
          ).updated_lockfile_content
      end

      def composer_json
        @composer_json ||= get_original_file("composer.json")
      end

      def lockfile
        @lockfile ||= get_original_file("composer.lock")
      end
    end
  end
end

Dependabot::FileUpdaters.register("composer", Dependabot::Composer::FileUpdater)

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
dependabot-composer-0.288.0 lib/dependabot/composer/file_updater.rb
dependabot-composer-0.287.0 lib/dependabot/composer/file_updater.rb
dependabot-composer-0.286.0 lib/dependabot/composer/file_updater.rb
dependabot-composer-0.285.0 lib/dependabot/composer/file_updater.rb
dependabot-composer-0.284.0 lib/dependabot/composer/file_updater.rb
dependabot-composer-0.283.0 lib/dependabot/composer/file_updater.rb
dependabot-composer-0.282.0 lib/dependabot/composer/file_updater.rb
dependabot-composer-0.281.0 lib/dependabot/composer/file_updater.rb
dependabot-composer-0.280.0 lib/dependabot/composer/file_updater.rb
dependabot-composer-0.279.0 lib/dependabot/composer/file_updater.rb
dependabot-composer-0.278.0 lib/dependabot/composer/file_updater.rb
dependabot-composer-0.277.0 lib/dependabot/composer/file_updater.rb
dependabot-composer-0.276.0 lib/dependabot/composer/file_updater.rb
dependabot-composer-0.275.0 lib/dependabot/composer/file_updater.rb
dependabot-composer-0.274.0 lib/dependabot/composer/file_updater.rb
dependabot-composer-0.273.0 lib/dependabot/composer/file_updater.rb
dependabot-composer-0.272.0 lib/dependabot/composer/file_updater.rb
dependabot-composer-0.268.0 lib/dependabot/composer/file_updater.rb
dependabot-composer-0.267.0 lib/dependabot/composer/file_updater.rb
dependabot-composer-0.266.0 lib/dependabot/composer/file_updater.rb