Skip to content

Commit

Permalink
Merge pull request #5448 from NobodysNightmare/extract-file-actions
Browse files Browse the repository at this point in the history
GitLab: Extract local actions variable into method
  • Loading branch information
jurre committed Aug 1, 2022
2 parents 3c7f27e + c8944d3 commit 7d6d305
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 37 deletions.
38 changes: 20 additions & 18 deletions common/lib/dependabot/pull_request_creator/gitlab.rb
Expand Up @@ -92,34 +92,36 @@ def create_branch
)
end

# @param [DependencyFile] file
def file_action(file)
if file.operation == Dependabot::DependencyFile::Operation::DELETE
"delete"
elsif file.operation == Dependabot::DependencyFile::Operation::CREATE
"create"
else
"update"
end
end

def create_commit
return create_submodule_update_commit if files.count == 1 && files.first.type == "submodule"

actions = files.map do |file|
gitlab_client_for_source.create_commit(
source.repo,
branch_name,
commit_message,
file_actions
)
end

def file_actions
files.map do |file|
{
action: file_action(file),
file_path: file.type == "symlink" ? file.symlink_target : file.path,
content: file.content
}
end
end

gitlab_client_for_source.create_commit(
source.repo,
branch_name,
commit_message,
actions
)
# @param [DependencyFile] file
def file_action(file)
if file.operation == Dependabot::DependencyFile::Operation::DELETE
"delete"
elsif file.operation == Dependabot::DependencyFile::Operation::CREATE
"create"
else
"update"
end
end

def create_submodule_update_commit
Expand Down
40 changes: 21 additions & 19 deletions common/lib/dependabot/pull_request_updater/gitlab.rb
Expand Up @@ -63,34 +63,36 @@ def commit_being_updated
gitlab_client_for_source.commit(source.repo, old_commit)
end

# @param [DependencyFile] file
def file_action(file)
if file.operation == Dependabot::DependencyFile::Operation::DELETE
"delete"
elsif file.operation == Dependabot::DependencyFile::Operation::CREATE
"create"
else
"update"
end
def create_commit
gitlab_client_for_source.create_commit(
source.repo,
merge_request.source_branch,
commit_being_updated.title,
file_actions,
force: true,
start_branch: merge_request.target_branch
)
end

def create_commit
actions = files.map do |file|
def file_actions
files.map do |file|
{
action: file_action(file),
file_path: file.type == "symlink" ? file.symlink_target : file.path,
content: file.content
}
end
end

gitlab_client_for_source.create_commit(
source.repo,
merge_request.source_branch,
commit_being_updated.title,
actions,
force: true,
start_branch: merge_request.target_branch
)
# @param [DependencyFile] file
def file_action(file)
if file.operation == Dependabot::DependencyFile::Operation::DELETE
"delete"
elsif file.operation == Dependabot::DependencyFile::Operation::CREATE
"create"
else
"update"
end
end
end
end
Expand Down

0 comments on commit 7d6d305

Please sign in to comment.