diff --git a/lib/rdoc/parser/changelog.rb b/lib/rdoc/parser/changelog.rb index b393805040..dcc8464990 100644 --- a/lib/rdoc/parser/changelog.rb +++ b/lib/rdoc/parser/changelog.rb @@ -217,9 +217,14 @@ class RDoc::Parser::ChangeLog < RDoc::Parser def parse_entries entries = [] - @content.scan(/^commit\s+(\h{20})\h*\n *Author: *(.+)\n *Date: *(.+)\n\n((?: {4}.*\n+)*)/) do - entry_name, author, date, entry_body = $1, $2, $3, $4.gsub(/^ {4}/, '') - if /(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+) *([-+]\d\d)(\d\d)/ =~ date + @content.scan(/^commit\s+(\h{20})\h*\n((?:.+\n)*)\n((?: {4}.*\n+)*)/) do + entry_name, header, entry_body = $1, $2, $3.gsub(/^ {4}/, '') + # header = header.scan(/^ *(\S+?): +(.*)/).to_h + # date = header["CommitDate"] || header["Date"] + date = header[/^ *(?:Author)?Date: +(.*)/, 1] + author = header[/^ *Author: +(.*)/, 1] + if /(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+) *([-+]\d\d)(\d\d)/ =~ + (header[/^ *CommitDate: +(.*)/, 1] || date) time = Time.new($1, $2, $3, $4, $5, $6, "#{$7}:#{$8}") @time_cache[entry_name] = time author.sub!(/\s*<(.*)>/, '') diff --git a/test/rdoc/test_rdoc_parser_changelog.rb b/test/rdoc/test_rdoc_parser_changelog.rb index fd19566064..6a14b61ca2 100644 --- a/test/rdoc/test_rdoc_parser_changelog.rb +++ b/test/rdoc/test_rdoc_parser_changelog.rb @@ -398,6 +398,46 @@ ChangeLog assert_equal expected, @top_level.comment end + def test_scan_git_commit_date + parser = util_parser <<-ChangeLog +commit\ ee1e690a2df901adb279d7a63fbd92c64e0a5ae6 + Author: Igor Zubkov + AuthorDate: 2016-10-25 03:56:11 +0900 + Commit: Nobuyoshi Nakada + CommitDate: 2021-01-07 13:40:42 +0900 + + We don't need "require 'uri'" after "require 'net/http'". + +commit\ 4d0985a7bd8f591dff4b430e288bfd83af782e51 + Author: git + AuthorDate: 2021-01-07 10:21:34 +0900 + Commit: git + CommitDate: 2021-01-07 10:21:34 +0900 + + * 2021-01-07 [ci skip] +ChangeLog + + parser.scan + + expected = doc( + head(1, File.basename(@tempfile.path)), + blank_line, + head(2, "2021-01-07"), + blank_line, + log_entry(nil, 'ee1e690a2df901adb279', + 'Igor Zubkov', 'igor.zubkov@gmail.com', + '2016-10-25 03:56:11 +0900', + [head(4, %[We don't need "require 'uri'" after "require 'net/http'".])]), + log_entry(nil, '4d0985a7bd8f591dff4b', + 'git', 'svn-admin@ruby-lang.org', + '2021-01-07 10:21:34 +0900', + [list(:BULLET, item(nil, para("2021-01-07 [ci skip]")))])) + + expected.file = @top_level + + assert_equal expected, @top_level.comment + end + def util_parser content = '' RDoc::Parser::ChangeLog.new \ @top_level, @tempfile.path, content, @options, @stats