From b7d7099d086da96104e001bdf046b5c4bdb205dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guitaut?= Date: Mon, 11 Sep 2023 18:00:30 +0200 Subject: [PATCH] DEV: Add link to PR when generating release notes --- lib/tasks/release_note.rake | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/tasks/release_note.rake b/lib/tasks/release_note.rake index 9f96eb4c4b3..11e439a73d5 100644 --- a/lib/tasks/release_note.rake +++ b/lib/tasks/release_note.rake @@ -82,11 +82,16 @@ def find_changes(repo, from, to) changes = {} CHANGE_TYPES.each { |ct| changes[ct] = Set.new } + repo_path = + `git -C #{repo} remote get-url origin`.match(%r{github.com[/:](?(?:(?!\.git).)*)}).try( + :[], + :repo, + ) out.each_line do |comment| next if comment =~ /\A\s*Revert/ split_comments(comment).each do |line| ct = CHANGE_TYPES.find { |t| line =~ t[:pattern] } - changes[ct] << better(line) if ct + changes[ct] << better(line, repo_path) if ct end end @@ -100,10 +105,10 @@ def print_changes(heading, changes, importance) puts changes.to_a, "" end -def better(line) +def better(line, repo_path) line = remove_prefix(line) line = escape_brackets(line) - line = remove_pull_request(line) + line = link_to_pull_request(line, repo_path) line[0] = '\#' if line[0] == "#" if line[0] line[0] = line[0].capitalize @@ -121,8 +126,8 @@ def escape_brackets(line) line.gsub("<", "`<").gsub(">", ">`").gsub("[", "`[").gsub("]", "]`") end -def remove_pull_request(line) - line.gsub(/ \(\#\d+\)\z/, "") +def link_to_pull_request(line, repo_path) + line.gsub(/ \(\#(?\d+)\)\z/, " ([\\k](https://github.com/#{repo_path}/pull/\\k))") end def split_comments(text)