Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions common/lib/dependabot/pull_request_updater/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,28 +182,30 @@ def update_branch(commit)
end

def commit_message
# Take the commit message from the old commit
commit_being_updated.message
fallback_message =
"#{pull_request.title}\n\nDependabot looked everywhere and " \
"was unable to find the original pull request head commit, " \
"#{old_commit}."
Comment thread
bdragon marked this conversation as resolved.

# Take the commit message from the old commit. If the old commit can't
# be found, use the PR title as the commit message.
commit_being_updated&.message || fallback_message
end

def commit_being_updated
@commit_being_updated ||=
return @commit_being_updated if defined?(@commit_being_updated)

@commit_being_updated =
if pull_request.commits == 1
github_client_for_source.
git_commit(source.repo, pull_request.head.sha)
else
author_name = author_details&.fetch(:name, nil) || "dependabot"
commits =
github_client_for_source.
pull_request_commits(source.repo, pull_request_number).
reverse

commit =
commits.find { |c| c.sha == old_commit } ||
commits.find { |c| c.commit.author.name.include?(author_name) } ||
commits.first
pull_request_commits(source.repo, pull_request_number)

commit.commit
commit = commits.find { |c| c.sha == old_commit }
commit&.commit
end
end

Expand Down
21 changes: 21 additions & 0 deletions common/spec/dependabot/pull_request_updater/github_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,27 @@
)
end
end

context "the original PR head commit cannot be found" do
let(:old_commit) { "oldcommitsha" }

it "generates a reasonable fallback commit message" do
updater.update

expect(WebMock).
to have_requested(:post, "#{watched_repo_url}/git/commits").
with(
body: {
parents: ["basecommitsha"],
tree: "cd8274d15fa3ae2ab983129fb037999f264ba9a7",
message:
"Bump business from 1.4.0 to 1.5.0\n\n" \
"Dependabot looked everywhere and was unable to find " \
"the original pull request head commit, oldcommitsha."
Comment thread
bdragon marked this conversation as resolved.
Outdated
}
)
end
end
end

context "when the default branch has changed" do
Expand Down