Skip to content
Merged
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 scripts/changelog-check
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require 'open3'
require 'optparse'

CHANGELOG_REGEX =
%r{^changelog: (?<category>[\w -/]{2,}), (?<subcategory>[A-Z][\w -]{2,}), (?<change>.+)$}
%r{^(?:\* )?changelog: (?<category>[\w -/]{2,}), (?<subcategory>[A-Z][\w -]{2,}), (?<change>.+)$}
CATEGORIES = [
'Improvements', 'Accessibility', 'Bug Fixes', 'Internal'
]
Expand All @@ -18,6 +18,11 @@ def build_changelog(line)
CHANGELOG_REGEX.match(line)
end

def build_changelog_from_commit(commit)
commit.commit_messages.reverse.map { |message| build_changelog(message) }.compact.first ||
build_changelog(commit.title)
end

# Transforms a formatted git log into structured objects.
# The git format ends up printing a single commit as:
#
Expand All @@ -41,9 +46,10 @@ def get_git_log(base_branch, source_branch)
end
}.map do |title_and_commit_messages|
title = title_and_commit_messages.first.first.delete_prefix('title: ')
messages = title_and_commit_messages[1]
SquashedCommit.new(
title: title_and_commit_messages.first.first,
commit_messages: title_and_commit_messages[1],
title: title,
commit_messages: messages,
)
end
end
Expand Down Expand Up @@ -79,7 +85,7 @@ def generate_changelog(base_branch, source_branch)
log.each do |item|
# Skip this commit if the skip changelog message appears
next if item.commit_messages.any? { |message| message.include?(SKIP_CHANGELOG_MESSAGE) }
change = item.commit_messages.reverse.map { |message| build_changelog(message) }.compact.first
change = build_changelog_from_commit(item)
next unless change

pr_number = %r{\(#(?<pr>\d+)\)}.match(item[:title])
Expand Down