Skip to content
Open
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
16 changes: 16 additions & 0 deletions lib/rdoc/parser/changelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,22 @@ def create_entries(entries)
def initialize(base, commit, author, email, date, contents)
case contents
when String
if base&.match(%r[\A([^:/]+:/+[^/]+/)[^/]+/[^/]+/])
repo, host = $&, $1
contents = contents.dup
# base: https://github.com/ruby/ruby/
# Fix #15791 -> Fix [#15791](https://github.com/ruby/ruby/pull/15791)
# GH-15791 -> [GH-15791](https://github.com/ruby/ruby/pull/15791)
# (#15791) -> ([#15791](https://github.com/ruby/ruby/pull/15791))
contents.gsub!(/\b(?:(?i:fix(?:e[sd])?) +)\K\#(\d+\b)|\bGH-(\d+)\b|\(\K\#(\d+)(?=\))/) do
"[#{$&}](#{repo}pull/#{$1 || $2 || $3})"
end
contents.gsub!(%r[(?<![-\w#/@]|\]\[)([-\w]+/[-\w]+)(?:@(\h{8,40})|\#(\d+))(?![-\w#/@]|\]\[)]) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add an example comment here too?

path = defined?($2) ? "commit/#{$2}" : "pull/#{$3}"
"[#{$&}](#{host}#{$1}/#{path})"
end
end

contents = RDoc::Markdown.parse(contents).parts.each do |body|
case body
when RDoc::Markup::Heading
Expand Down
26 changes: 26 additions & 0 deletions test/rdoc/parser/changelog_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,32 @@ def test_scan_git_commit_date
assert_equal expected, @top_level.comment.parse
end

def test_scan_git_reference
ruby = "https://github.com/ruby/"
repo = "#{ruby}ruby/"
entry = log_entry("#{repo}commit/",
"a8a989b6f651b878c690f5fd0a728e19a54dd2b9",
"Nobuyoshi Nakada", "[email protected]",
"2026-01-03 13:28:58 +0900",
<<~LOG)
Test net-imap with ruby/net-imap#593

Fix #15791

GH-15791

(#15791)

Fix up [ruby/net-imap#543].
LOG
head, *bodies = entry.contents
assert_include head.text, "{ruby/net-imap#593}[#{ruby}net-imap/pull/593]"
assert_include bodies.shift.text, "Fix {#15791}[#{repo}pull/15791]"
assert_include bodies.shift.text, "{GH-15791}[#{repo}pull/15791]"
assert_include bodies.shift.text, "({#15791}[#{repo}pull/15791])"
assert_include bodies.shift.text, "{ruby/net-imap#543}[#{ruby}net-imap/pull/543]"
end

def util_parser(content = '')
RDoc::Parser::ChangeLog.new @top_level, content, @options, @stats
end
Expand Down