From 536f83ec1b74e4134a7d16630fdd3acda5146c99 Mon Sep 17 00:00:00 2001 From: Rob Aiken Date: Tue, 4 Mar 2025 14:41:45 +0000 Subject: [PATCH] removing complexity --- .../dependabot/pull_request_creator/github.rb | 54 +++++++++++-------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/common/lib/dependabot/pull_request_creator/github.rb b/common/lib/dependabot/pull_request_creator/github.rb index dd51a04891..a0f3cddb24 100644 --- a/common/lib/dependabot/pull_request_creator/github.rb +++ b/common/lib/dependabot/pull_request_creator/github.rb @@ -290,33 +290,43 @@ def commit_options(tree) options end + sig { params(file: T.untyped).returns(T::Hash[Symbol, T.untyped]) } + def submodule_tree_node(file) + { + path: file.path.sub(%r{^/}, ""), + mode: Dependabot::DependencyFile::Mode::SUBMODULE, + type: "commit", + sha: file.content + } + end + + sig { params(file: T.untyped).returns(T::Hash[Symbol, T.untyped]) } + def file_tree_node(file) + content = if file.operation == Dependabot::DependencyFile::Operation::DELETE + { sha: nil } + elsif file.binary? + sha = T.unsafe(github_client_for_source).create_blob( + source.repo, file.content, "base64" + ) + { sha: sha } + else + { content: file.content } + end + + { + path: file.realpath, + mode: file.mode || Dependabot::DependencyFile::Mode::FILE, + type: "blob" + }.merge(content) + end + sig { returns(T.untyped) } def create_tree file_trees = files.map do |file| if file.type == "submodule" - { - path: file.path.sub(%r{^/}, ""), - mode: Dependabot::DependencyFile::Mode::SUBMODULE, - type: "commit", - sha: file.content - } + submodule_tree_node(file) else - content = if file.operation == Dependabot::DependencyFile::Operation::DELETE - { sha: nil } - elsif file.binary? - sha = T.unsafe(github_client_for_source).create_blob( - source.repo, file.content, "base64" - ) - { sha: sha } - else - { content: file.content } - end - - { - path: file.realpath, - mode: file.mode || Dependabot::DependencyFile::Mode::FILE, - type: "blob" - }.merge(content) + file_tree_node(file) end end