Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect casing in some Dependabot PR titles #8355

Merged
merged 1 commit into from
Nov 13, 2023
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
14 changes: 10 additions & 4 deletions common/lib/dependabot/pull_request_creator/pr_name_prefixer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def capitalise_first_word_from_last_dependabot_commit_style
case last_dependabot_commit_style
when :gitmoji then true
when :conventional_prefix, :conventional_prefix_with_scope
last_dependabot_commit_message.match?(/: (\[[Ss]ecurity\] )?(B|U)/)
last_dependabot_commit_title.match?(/: (\[[Ss]ecurity\] )?(B|U)/)
else raise "Unknown commit style #{last_dependabot_commit_style}"
end
end
Expand All @@ -152,7 +152,7 @@ def capitalise_first_word_from_previous_commits
end

def last_dependabot_commit_style
return unless (msg = last_dependabot_commit_message)
return unless (msg = last_dependabot_commit_title)

return :gitmoji if msg.start_with?("⬆️")
return :conventional_prefix if msg.match?(/\A(chore|build|upgrade):/i)
Expand All @@ -162,7 +162,7 @@ def last_dependabot_commit_style
end

def last_dependabot_commit_prefix
last_dependabot_commit_message&.split(/[:(]/)&.first
last_dependabot_commit_title&.split(/[:(]/)&.first
end

# rubocop:disable Metrics/PerceivedComplexity
Expand Down Expand Up @@ -245,7 +245,7 @@ def capitalize_angular_commit_prefix?
ANGULAR_PREFIXES.any? { |pre| message.match?(/#{pre}[:(]/i) }
end

return last_dependabot_commit_message&.start_with?(/[A-Z]/) if semantic_messages.none?
return last_dependabot_commit_title&.start_with?(/[A-Z]/) if semantic_messages.none?

capitalized_msgs = semantic_messages
.select { |m| m.start_with?(/[A-Z]/) }
Expand Down Expand Up @@ -329,6 +329,12 @@ def recent_codecommit_commit_messages
.map(&:strip)
end

def last_dependabot_commit_title
return @last_dependabot_commit_title if defined?(@last_dependabot_commit_title)

@last_dependabot_commit_title = last_dependabot_commit_message&.split("\n")&.first
end

def last_dependabot_commit_message
@last_dependabot_commit_message ||=
case source.provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@
let(:json_header) { { "Content-Type" => "application/json" } }
let(:watched_repo_url) { "https://api.github.com/repos/#{source.repo}" }

describe "#capitalize_first_word?" do
subject(:capitalize_first_word) { builder.capitalize_first_word? }

before do
stub_request(:get, watched_repo_url + "/commits?per_page=100")
.to_return(status: 200,
body: fixture("github", "commits_conventional_long_messages.json"),
headers: json_header)
end

it { is_expected.to be false }
end

describe "#pr_name_prefix" do
subject(:pr_name_prefix) { builder.pr_name_prefix }

Expand Down
Loading