Skip to content

Commit

Permalink
removing complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
robaiken committed Mar 4, 2025
1 parent a6cc803 commit 536f83e
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions common/lib/dependabot/pull_request_creator/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 536f83e

Please sign in to comment.