DEV: Add link to PR when generating release notes

This commit is contained in:
Loïc Guitaut 2023-09-11 18:00:30 +02:00 committed by Loïc Guitaut
parent 6e672557fa
commit b7d7099d08
1 changed files with 10 additions and 5 deletions

View File

@ -82,11 +82,16 @@ def find_changes(repo, from, to)
changes = {} changes = {}
CHANGE_TYPES.each { |ct| changes[ct] = Set.new } CHANGE_TYPES.each { |ct| changes[ct] = Set.new }
repo_path =
`git -C #{repo} remote get-url origin`.match(%r{github.com[/:](?<repo>(?:(?!\.git).)*)}).try(
:[],
:repo,
)
out.each_line do |comment| out.each_line do |comment|
next if comment =~ /\A\s*Revert/ next if comment =~ /\A\s*Revert/
split_comments(comment).each do |line| split_comments(comment).each do |line|
ct = CHANGE_TYPES.find { |t| line =~ t[:pattern] } ct = CHANGE_TYPES.find { |t| line =~ t[:pattern] }
changes[ct] << better(line) if ct changes[ct] << better(line, repo_path) if ct
end end
end end
@ -100,10 +105,10 @@ def print_changes(heading, changes, importance)
puts changes.to_a, "" puts changes.to_a, ""
end end
def better(line) def better(line, repo_path)
line = remove_prefix(line) line = remove_prefix(line)
line = escape_brackets(line) line = escape_brackets(line)
line = remove_pull_request(line) line = link_to_pull_request(line, repo_path)
line[0] = '\#' if line[0] == "#" line[0] = '\#' if line[0] == "#"
if line[0] if line[0]
line[0] = line[0].capitalize line[0] = line[0].capitalize
@ -121,8 +126,8 @@ def escape_brackets(line)
line.gsub("<", "`<").gsub(">", ">`").gsub("[", "`[").gsub("]", "]`") line.gsub("<", "`<").gsub(">", ">`").gsub("[", "`[").gsub("]", "]`")
end end
def remove_pull_request(line) def link_to_pull_request(line, repo_path)
line.gsub(/ \(\#\d+\)\z/, "") line.gsub(/ \(\#(?<id>\d+)\)\z/, " ([\\k<id>](https://github.com/#{repo_path}/pull/\\k<id>))")
end end
def split_comments(text) def split_comments(text)