Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 15 additions & 1 deletion common/lib/dependabot/pull_request_creator/message_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "pathname"
require "dependabot/clients/github_with_retries"
require "dependabot/clients/gitlab_with_retries"
require "dependabot/logger"
require "dependabot/metadata_finders"
require "dependabot/pull_request_creator"
require "dependabot/pull_request_creator/message"
Expand Down Expand Up @@ -38,7 +39,12 @@ def initialize(source:, dependencies:, files:, credentials:,
end

def pr_name
pr_name = pr_name_prefixer.pr_name_prefix
begin
pr_name = pr_name_prefixer.pr_name_prefix
rescue StandardError => e
Dependabot.logger.error("Error while generating PR name: #{e.message}")
pr_name = ""
end
pr_name += library? ? library_pr_name : application_pr_name
Copy link
Copy Markdown
Contributor

@honeyankit honeyankit Oct 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my understanding what is the library here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dependabot differentiates between library and application in a few places. For NPM, if you publish to the registry it's considered a library, otherwise it's an application. I actually didn't look at how this code changes depending on the type, but in another place it decides whether to increase the version vs widen the range.

return pr_name if files.first.directory == "/"

Expand All @@ -48,6 +54,9 @@ def pr_name
def pr_message
suffixed_pr_message_header + commit_message_intro + \
metadata_cascades + prefixed_pr_message_footer
rescue StandardError => e
Dependabot.logger.error("Error while generating PR message: #{e.message}")
suffixed_pr_message_header + prefixed_pr_message_footer
end

def commit_message
Expand All @@ -56,6 +65,11 @@ def commit_message
message += metadata_links
message += "\n\n" + message_trailers if message_trailers
message
rescue StandardError => e
Dependabot.logger.error("Error while generating commit message: #{e.message}")
message = commit_subject
message += "\n\n" + message_trailers if message_trailers
message
end

def message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def capitalize_first_word?
return capitalise_first_word_from_last_dependabot_commit_style if last_dependabot_commit_style

capitalise_first_word_from_previous_commits
rescue StandardError
# ignoring failure due to network call to find out if the PR should be capitalized
false
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ def commits_details(base:, head:)

it { is_expected.to eq("Bump business from 1.4.0 to 1.5.0") }

context "but the internet goes down" do
before do
stub_request(:any, /.*/).to_raise(SocketError)
end

it { is_expected.to eq("bump business from 1.4.0 to 1.5.0") }
end

context "but does have prefixed commits" do
let(:commits_response) { fixture("github", "commits_prefixed.json") }

Expand Down Expand Up @@ -886,6 +894,17 @@ def commits_details(base:, head:)
)
end

context "when there's a network error" do
before do
stub_request(:any, /.*/).to_raise(SocketError)
end

it "has a blank message" do
expect(pr_message).
to eq("")
end
end

context "without a github link proxy" do
let(:github_redirection_service) { nil }

Expand Down