[前][次][番号順一覧][スレッド一覧]

ruby-changes:65029

From: Nobuyoshi <ko1@a...>
Date: Sun, 24 Jan 2021 16:53:51 +0900 (JST)
Subject: [ruby-changes:65029] bb570ce6d8 (master): [ruby/rdoc] Support ChangeLog generated by `git log`

https://git.ruby-lang.org/ruby.git/commit/?id=bb570ce6d8

From bb570ce6d80d28cfc7131dcb72885eed2f989b30 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 21 Jan 2021 01:25:56 +0900
Subject: [ruby/rdoc] Support ChangeLog generated by `git log`

https://github.com/ruby/rdoc/commit/5e0a123ca1
---
 lib/rdoc/parser/changelog.rb            | 35 +++++++++++++++++++++
 test/rdoc/test_rdoc_parser_changelog.rb | 56 +++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+)

diff --git a/lib/rdoc/parser/changelog.rb b/lib/rdoc/parser/changelog.rb
index 167892f..3634b6a 100644
--- a/lib/rdoc/parser/changelog.rb
+++ b/lib/rdoc/parser/changelog.rb
@@ -131,6 +131,12 @@ class RDoc::Parser::ChangeLog < RDoc::Parser https://github.com/ruby/ruby/blob/trunk/lib/rdoc/parser/changelog.rb#L131
 
   def parse_entries
     @time_cache ||= {}
+
+    if /\A(?:.*\n){,3}commit\s/ =~ @content
+      class << self; prepend Git; end
+      return parse_entries
+    end
+
     entries = []
     entry_name = nil
     entry_body = []
@@ -190,6 +196,7 @@ class RDoc::Parser::ChangeLog < RDoc::Parser https://github.com/ruby/ruby/blob/trunk/lib/rdoc/parser/changelog.rb#L196
 
   def scan
     @time_cache = {}
+
     entries = parse_entries
     grouped_entries = group_entries entries
 
@@ -200,5 +207,33 @@ class RDoc::Parser::ChangeLog < RDoc::Parser https://github.com/ruby/ruby/blob/trunk/lib/rdoc/parser/changelog.rb#L207
     @top_level
   end
 
+  module Git
+    def parse_entries
+      entries = []
+
+      @content.scan(/^commit\s+(\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
+          time = Time.new($1, $2, $3, $4, $5, $6, "#{$7}:#{$8}")
+          @time_cache[entry_name] = time
+          entries << [entry_name, [author, date, entry_body]]
+        end
+      end
+
+      entries
+    end
+
+    def create_entries entries
+      # git log entries have no strictly itemized style like the old
+      # style, just assume Markdown.
+      entries.map do |entry, (author, date, body)|
+        list = RDoc::Markup::List.new(:NOTE)
+        author = RDoc::Markup::Paragraph.new(author)
+        list << RDoc::Markup::ListItem.new(date, author)
+        RDoc::Markdown.parse(body).parts.each {|b| list << b}
+        list
+      end
+    end
+  end
 end
 
diff --git a/test/rdoc/test_rdoc_parser_changelog.rb b/test/rdoc/test_rdoc_parser_changelog.rb
index d93cb7d..33e59ac 100644
--- a/test/rdoc/test_rdoc_parser_changelog.rb
+++ b/test/rdoc/test_rdoc_parser_changelog.rb
@@ -270,6 +270,24 @@ Other note that will be ignored https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_parser_changelog.rb#L270
     assert_equal expected, parser.parse_entries
   end
 
+  def test_parse_entries_git
+    parser = util_parser <<-ChangeLog
+commit\ 709bed2afaee50e2ce803f87bf1ee8291bea41e3
+  Author: git <svn-admin@r...>
+  Date:   2021-01-21 01:03:52 +0900
+
+    * 2021-01-21 [ci skip]
+ChangeLog
+
+    expected = [
+      [ "709bed2afaee50e2ce803f87bf1ee8291bea41e3",
+       [ "git <svn-admin@r...>",
+         "2021-01-21 01:03:52 +0900",
+         "* 2021-01-21 [ci skip]\n"]]]
+
+    assert_equal expected, parser.parse_entries
+  end
+
   def test_scan
     parser = util_parser <<-ChangeLog
 Tue Dec  4 08:32:10 2012  Eric Hodel  <drbrain@s...>
@@ -309,6 +327,44 @@ Mon Dec  3 20:37:22 2012  Koichi Sasada  <ko1@a...> https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_parser_changelog.rb#L327
     assert_equal expected, @top_level.comment
   end
 
+  def test_scan_git
+    parser = util_parser <<-ChangeLog
+commit\ 709bed2afaee50e2ce803f87bf1ee8291bea41e3
+  Author: git <svn-admin@r...>
+  Date:   2021-01-21 01:03:52 +0900
+
+    * 2021-01-21 [ci skip]
+
+commit\ a8dc5156e183489c5121fb1759bda5d9406d9175
+  Author: git <svn-admin@r...>
+  Date:   2021-01-20 01:58:26 +0900
+
+    * 2021-01-20 [ci skip]
+ChangeLog
+
+    parser.scan
+
+    expected = doc(
+      head(1, File.basename(@tempfile.path)),
+      blank_line,
+      head(2, '2021-01-21'),
+      blank_line,
+      list(:NOTE,
+        item('2021-01-21 01:03:52 +0900',
+          para('git <svn-admin@r...>')),
+        list(:BULLET, item(nil, para('2021-01-21 [ci skip]')))),
+      head(2, '2021-01-20'),
+      blank_line,
+      list(:NOTE,
+        item('2021-01-20 01:58:26 +0900',
+          para('git <svn-admin@r...>')),
+        list(:BULLET, item(nil, para('2021-01-20 [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
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]