Skip to content

Commit 9f738e8

Browse files
committed
Expand GitHub style references in ChangeLog to URL
1 parent 35de259 commit 9f738e8

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

lib/rdoc/parser/changelog.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,18 @@ def create_entries(entries)
274274
def initialize(base, commit, author, email, date, contents)
275275
case contents
276276
when String
277+
if base&.match(%r[\A([^:/]+:/+[^/]+/)[^/]+/[^/]+/])
278+
repo, host = $&, $1
279+
contents = contents.dup
280+
contents.gsub!(/\b(?:(?i:fix(?:e[sd])?) +)\K#(\d+\b)|\bGH-(\d+)\b|\(\K\#(\d+)(?=\))/) do
281+
"[#$&](#{repo}pull/#{$1 || $2 || $3})"
282+
end
283+
contents.gsub!(%r[(?<![-\w#/@]|\]\[)([-\w]+/[-\w]+)(?:@(\h{8,40})|\#(\d+))(?![-\w#/@]|\]\[)]) do
284+
path = defined?($2) ? "commit/#{$2}" : "pull/#{$3}"
285+
"[#$&](#{host}#{$1}/#{path})"
286+
end
287+
end
288+
277289
contents = RDoc::Markdown.parse(contents).parts.each do |body|
278290
case body
279291
when RDoc::Markup::Heading

test/rdoc/parser/changelog_test.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,32 @@ def test_scan_git_commit_date
473473
assert_equal expected, @top_level.comment.parse
474474
end
475475

476+
def test_scan_git_reference
477+
ruby = "https://github.com/ruby/"
478+
repo = "#{ruby}ruby/"
479+
entry = log_entry("#{repo}commit/",
480+
"a8a989b6f651b878c690f5fd0a728e19a54dd2b9",
481+
"Nobuyoshi Nakada", "nobu@ruby-lang.org",
482+
"2026-01-03 13:28:58 +0900",
483+
<<~LOG)
484+
Test net-imap with ruby/net-imap#593
485+
486+
Fix #15791
487+
488+
GH-15791
489+
490+
(#15791)
491+
492+
Fix up [ruby/net-imap#543].
493+
LOG
494+
head, *bodies = entry.contents
495+
assert_include head.text, "{ruby/net-imap#593}[#{ruby}net-imap/pull/593]"
496+
assert_include bodies.shift.text, "Fix {#15791}[#{repo}pull/15791]"
497+
assert_include bodies.shift.text, "{GH-15791}[#{repo}pull/15791]"
498+
assert_include bodies.shift.text, "({#15791}[#{repo}pull/15791])"
499+
assert_include bodies.shift.text, "{ruby/net-imap#543}[#{ruby}net-imap/pull/543]"
500+
end
501+
476502
def util_parser(content = '')
477503
RDoc::Parser::ChangeLog.new @top_level, content, @options, @stats
478504
end

0 commit comments

Comments
 (0)