Skip to content

Commit

Permalink
Add Dependabot logger
Browse files Browse the repository at this point in the history
  • Loading branch information
feelepxyz committed Jan 14, 2021
1 parent 257c79d commit 186bb06
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 21 deletions.
3 changes: 3 additions & 0 deletions bin/dry-run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
require "optparse"
require "json"
require "byebug"
require "logger"

require "dependabot/file_fetchers"
require "dependabot/file_parsers"
Expand All @@ -85,6 +86,8 @@
require "dependabot/python"
require "dependabot/terraform"

Dependabot.logger = Logger.new($stdout)

# GitHub credentials with write permission to the repo you want to update
# (so that you can create a new branch, commit and pull request).
# If using a private registry it's also possible to add details of that here.
Expand Down
13 changes: 13 additions & 0 deletions common/lib/dependabot/logger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require "logger"

module Dependabot
def self.logger
@logger ||= Logger.new(nil)
end

def self.logger=(logger)
@logger = logger
end
end
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# frozen_string_literal: true

require "dependabot/npm_and_yarn/file_updater"
require "dependabot/errors"
require "dependabot/logger"
require "dependabot/npm_and_yarn/file_parser"
require "dependabot/npm_and_yarn/update_checker/registry_finder"
require "dependabot/npm_and_yarn/native_helpers"
require "dependabot/npm_and_yarn/file_updater"
require "dependabot/npm_and_yarn/helpers"
require "dependabot/npm_and_yarn/native_helpers"
require "dependabot/npm_and_yarn/update_checker/registry_finder"
require "dependabot/shared_helpers"
require "dependabot/errors"

# rubocop:disable Metrics/ClassLength
module Dependabot
Expand Down Expand Up @@ -152,7 +153,7 @@ def run_npm_updater(lockfile_name:, top_level_dependency_updates:, lockfile_cont

def run_npm_top_level_updater(lockfile_name:, top_level_dependency_updates:, lockfile_content:)
npm_version = Dependabot::NpmAndYarn::Helpers.npm_version(lockfile_content)
puts npm_version
Dependabot.logger.info(npm_version)

SharedHelpers.run_helper_subprocess(
command: NativeHelpers.helper_path,
Expand All @@ -167,7 +168,7 @@ def run_npm_top_level_updater(lockfile_name:, top_level_dependency_updates:, loc

def run_npm_subdependency_updater(lockfile_name:, lockfile_content:)
npm_version = Dependabot::NpmAndYarn::Helpers.npm_version(lockfile_content)
puts npm_version
Dependabot.logger.info(npm_version)

SharedHelpers.run_helper_subprocess(
command: NativeHelpers.helper_path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

require "dependabot/dependency"
require "dependabot/errors"
require "dependabot/logger"
require "dependabot/npm_and_yarn/file_parser"
require "dependabot/npm_and_yarn/native_helpers"
require "dependabot/npm_and_yarn/helpers"
require "dependabot/npm_and_yarn/native_helpers"
require "dependabot/npm_and_yarn/update_checker"
require "dependabot/npm_and_yarn/update_checker/dependency_files_builder"
require "dependabot/shared_helpers"
Expand Down Expand Up @@ -44,10 +45,9 @@ def conflicting_dependencies(dependency:, target_version:)
# parser doesn't deal with at the moment.
if dependency_files_builder.package_locks.any? ||
dependency_files_builder.shrinkwraps.any?
dependency_files_builder.package_locks
package_lock = dependency_files_builder.package_locks.find { |f| f.name == "package-lock.json" }
npm_version = Dependabot::NpmAndYarn::Helpers.npm_version(package_lock&.content)
puts npm_version
Dependabot.logger.info(npm_version)

SharedHelpers.run_helper_subprocess(
command: NativeHelpers.helper_path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

require "dependabot/dependency"
require "dependabot/errors"
require "dependabot/logger"
require "dependabot/npm_and_yarn/file_parser"
require "dependabot/npm_and_yarn/file_updater/npmrc_builder"
require "dependabot/npm_and_yarn/file_updater/package_json_preparer"
require "dependabot/npm_and_yarn/native_helpers"
require "dependabot/npm_and_yarn/helpers"
require "dependabot/npm_and_yarn/native_helpers"
require "dependabot/npm_and_yarn/sub_dependency_files_filterer"
require "dependabot/npm_and_yarn/update_checker"
require "dependabot/npm_and_yarn/update_checker/dependency_files_builder"
Expand Down Expand Up @@ -112,7 +113,7 @@ def run_npm_updater(path, lockfile_name, lockfile_content)
SharedHelpers.with_git_configured(credentials: credentials) do
Dir.chdir(path) do
npm_version = Dependabot::NpmAndYarn::Helpers.npm_version(lockfile_content)
puts npm_version
Dependabot.logger.info(npm_version)

SharedHelpers.run_helper_subprocess(
command: NativeHelpers.helper_path,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# frozen_string_literal: true

require "dependabot/errors"
require "dependabot/git_commit_checker"
require "dependabot/npm_and_yarn/update_checker"
require "dependabot/npm_and_yarn/file_parser"
require "dependabot/npm_and_yarn/version"
require "dependabot/npm_and_yarn/requirement"
require "dependabot/npm_and_yarn/native_helpers"
require "dependabot/npm_and_yarn/helpers"
require "dependabot/logger"
require "dependabot/npm_and_yarn/dependency_files_filterer"
require "dependabot/shared_helpers"
require "dependabot/errors"
require "dependabot/npm_and_yarn/file_parser"
require "dependabot/npm_and_yarn/file_updater/npmrc_builder"
require "dependabot/npm_and_yarn/file_updater/package_json_preparer"
require "dependabot/npm_and_yarn/helpers"
require "dependabot/npm_and_yarn/native_helpers"
require "dependabot/npm_and_yarn/requirement"
require "dependabot/npm_and_yarn/update_checker"
require "dependabot/npm_and_yarn/version"
require "dependabot/shared_helpers"

# rubocop:disable Metrics/ClassLength
module Dependabot
Expand Down Expand Up @@ -414,9 +415,12 @@ def run_yarn_checker(path:, version:)
def run_npm_checker(path:, version:)
SharedHelpers.with_git_configured(credentials: credentials) do
Dir.chdir(path) do
package_lock = dependency_files_builder.package_locks.find { |f| f.name == "package-lock.json" }
package_lock = dependency_files_builder.package_locks.find do |f|
# Find the lockfile that's in the current directory
f.name == [path, "package-lock.json"].join("/").sub(%r{\A.?\/}, "")
end
npm_version = Dependabot::NpmAndYarn::Helpers.npm_version(package_lock&.content)
puts npm_version
Dependabot.logger.info(npm_version)

SharedHelpers.run_helper_subprocess(
command: NativeHelpers.helper_path,
Expand Down

0 comments on commit 186bb06

Please sign in to comment.