newsman 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0166813d55623364efd38ff1f3bc83ff3ae76ee9d793b1b5ac52924477122135'
4
- data.tar.gz: 48d3c00284b0973851b95c2b144fe50972f801deeb826b400ab31e87102b7cfc
3
+ metadata.gz: 8bff52319f7db052d667bb38fa31764a4204ddab745eeaaa1daf090d36a73789
4
+ data.tar.gz: a7ccce39053631d627d210fea0897988b29ac24a62d9a17f98d83055777fbe40
5
5
  SHA512:
6
- metadata.gz: 193cf28ea41b994cab278212cc255dcf0d1f7b78570e631f68e17003d489d505fd0e12a8b3244d576fa1e0826d992ead7af9c1febefd80074dc8260174294dae
7
- data.tar.gz: 4e3a9c5920d471c3c5a1dcabe16692a6154ea50d44adaf775d263ce04186e814068391555d3e90682b043dbb2b3c4fb0372da2f8fa7e91abf331a594bfefe4e7
6
+ metadata.gz: 638afa442dd92022d7966ea99405fea3838a6a92edd12c71f32d9a7cb8392c59287e647d8376524e9a97f61ea9ce3b74b5160b85b27940627d478528d76d3eef
7
+ data.tar.gz: c8ee4f4a28435a66132f865046f222a2370361884d81d29536e1748778429cfd1a60581e6027448c0bbf5a491d55fda13e0d3f45af293e25b5fbe9d9fff5d5c2
@@ -45,7 +45,8 @@ class Assistant
45
45
  example = "repository-name:\n
46
46
  - To publish ABC package draft [#27]\n
47
47
  - To review first draft of the report [#56]\n
48
- - To implement optimization for the class X [#125]"
48
+ - To implement optimization for the class X [#125]\n
49
+ - Updated dependencies: rubocop, ruby [#197, #199, #204]"
49
50
  prompt = <<~PROMPT
50
51
  Please compile a summary of the plans for the next week using the GitHub Issues.
51
52
  Each issue should be summarized in a single sentence.
@@ -53,6 +54,8 @@ class Assistant
53
54
  Pay attention, that you didn't loose any issue.
54
55
  Ensure that each sentence includes the corresponding issue number as an integer value. If an issue doesn't mention an issue number, just print [#chore].
55
56
  If several issues have the same number, combine them into a single sentence.
57
+ Dependency version-bump issues (e.g. titles like "chore(deps): update dependency X to vY" or similar renovate/dependabot style bumps) must all be grouped into a single combined bullet listing the dependency names and all associated issue numbers, instead of one bullet per issue.
58
+ Other substantive issues should keep their own individual bullet as usual.
56
59
  Please strictly adhere to the example template provided: "#{example}".
57
60
  List of GitHub Issues in JSON format: ```json #{issues}```.
58
61
  PROMPT
@@ -65,13 +68,16 @@ class Assistant
65
68
  example = "repository-name:\n
66
69
  - Added 100 new files to the Dataset [#168]\n
67
70
  - Fixed the deployment of XYZ [#169]\n
68
- - Refined the requirements [#177]\n"
71
+ - Refined the requirements [#177]\n
72
+ - Updated dependencies: rubocop, ruby, nokogiri [#197, #199, #200, #202, #203, #204]\n"
69
73
  prompt = <<~PROMPT
70
74
  Please compile a summary of the work completed in the following Pull Requests (PRs).
71
75
  Each PR should be summarized in a single sentence, focusing on the PR title rather than the implementation details.
72
76
  Ensure no PR is omitted.
73
77
  Each sentence must include the corresponding issue number as an integer value. If a PR does not mention an issue number, use [#chore].
74
78
  If several PRs have the same number, combine them into a single sentence.
79
+ Dependency version-bump PRs (e.g. titles like "chore(deps): update dependency X to vY" or similar renovate/dependabot style bumps) must all be grouped into a single combined bullet listing the dependency names and all associated PR numbers, instead of one bullet per PR.
80
+ Other substantive PRs should keep their own individual bullet as usual.
75
81
  Combine the information from each PR into a concise and fluent sentence.
76
82
  Follow the provided example template strictly: "#{example}".
77
83
  List of Pull Requests in JSON format: ```json #{prs}```.
@@ -30,7 +30,7 @@ class Docxout
30
30
  # Content types part, required by every OOXML package.
31
31
  CONTENT_TYPES = <<~XML
32
32
  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
33
- <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/></Types>
33
+ <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/><Override PartName="/word/numbering.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"/></Types>
34
34
  XML
35
35
 
36
36
  # Package-level relationships, pointing at the main document part.
@@ -39,6 +39,25 @@ class Docxout
39
39
  <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/></Relationships>
40
40
  XML
41
41
 
42
+ # Document-level relationships, pointing at the numbering part used by lists.
43
+ DOCUMENT_RELS = <<~XML
44
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
45
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" Target="numbering.xml"/></Relationships>
46
+ XML
47
+
48
+ # Numbering definitions: numId 1 is a bulleted list, numId 2 is a decimal (numbered) list.
49
+ NUMBERING = <<~XML
50
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
51
+ <w:numbering xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:abstractNum w:abstractNumId="0"><w:lvl w:ilvl="0"><w:numFmt w:val="bullet"/><w:lvlText w:val="&#8226;"/><w:pPr><w:ind w:left="720" w:hanging="360"/></w:pPr></w:lvl></w:abstractNum><w:abstractNum w:abstractNumId="1"><w:lvl w:ilvl="0"><w:numFmt w:val="decimal"/><w:lvlText w:val="%1."/><w:pPr><w:ind w:left="720" w:hanging="360"/></w:pPr></w:lvl></w:abstractNum><w:num w:numId="1"><w:abstractNumId w:val="0"/></w:num><w:num w:numId="2"><w:abstractNumId w:val="1"/></w:num></w:numbering>
52
+ XML
53
+
54
+ # Matches markdown headers, e.g. "## Title" (levels 1-6).
55
+ HEADING = /^\s{0,3}(\#{1,6})\s+(.+?)\s*$/
56
+ # Matches markdown bullet list items, e.g. "- item" or "* item".
57
+ BULLET = /^\s{0,3}[-*]\s+(.+?)\s*$/
58
+ # Matches markdown numbered list items, e.g. "1. item".
59
+ NUMBERED = /^\s{0,3}\d+\.\s+(.+?)\s*$/
60
+
42
61
  FONT = 'Times New Roman'
43
62
  # Word expresses font size in half-points, so 12pt is 24.
44
63
  SIZE = '24'
@@ -50,11 +69,7 @@ class Docxout
50
69
  def print(report, reporter, model)
51
70
  puts "Create a docx file in a directory #{@root}"
52
71
  path = File.join(@root, filename(reporter, model))
53
- Zip::File.open(path, create: true) do |zip|
54
- zip.get_output_stream('[Content_Types].xml') { |f| f.write(CONTENT_TYPES) }
55
- zip.get_output_stream('_rels/.rels') { |f| f.write(RELS) }
56
- zip.get_output_stream('word/document.xml') { |f| f.write(document_xml(report)) }
57
- end
72
+ write_package(path, report)
58
73
  puts "Report was successfully printed to a #{path}"
59
74
  File.basename(path)
60
75
  end
@@ -67,16 +82,63 @@ class Docxout
67
82
 
68
83
  private
69
84
 
85
+ def write_package(path, report)
86
+ Zip::File.open(path, create: true) do |zip|
87
+ zip.get_output_stream('[Content_Types].xml') { |f| f.write(CONTENT_TYPES) }
88
+ zip.get_output_stream('_rels/.rels') { |f| f.write(RELS) }
89
+ zip.get_output_stream('word/_rels/document.xml.rels') { |f| f.write(DOCUMENT_RELS) }
90
+ zip.get_output_stream('word/numbering.xml') { |f| f.write(NUMBERING) }
91
+ zip.get_output_stream('word/document.xml') { |f| f.write(document_xml(report)) }
92
+ end
93
+ end
94
+
70
95
  def document_xml(report)
71
- body = paragraphs(report).map { |lines| paragraph_xml(lines) }.join
96
+ body = blocks(report).map { |block| block_xml(block) }.join
72
97
  <<~XML
73
98
  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
74
99
  <w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body>#{body}<w:sectPr/></w:body></w:document>
75
100
  XML
76
101
  end
77
102
 
78
- def paragraphs(report)
79
- report.to_s.split(/\n{2,}/).map { |paragraph| paragraph.split("\n") }
103
+ # Splits the report into blocks: markdown headers and list items each become
104
+ # their own block, and consecutive plain-text lines are grouped together.
105
+ def blocks(report)
106
+ classified = report.to_s.split("\n", -1).map { |line| classify(line) }
107
+ classified.chunk_while { |prev, curr| prev[:type] == :text && curr[:type] == :text }
108
+ .reject { |group| group.first[:type] == :blank }
109
+ .map { |group| merge_text(group) }
110
+ end
111
+
112
+ def merge_text(group)
113
+ return group.first unless group.first[:type] == :text
114
+
115
+ { type: :text, lines: group.map { |block| block[:line] } }
116
+ end
117
+
118
+ def classify(line)
119
+ return { type: :blank } if line.strip.empty?
120
+ return { type: :heading, level: ::Regexp.last_match(1).length, text: ::Regexp.last_match(2) } if line =~ HEADING
121
+ return { type: :bullet, text: ::Regexp.last_match(1) } if line =~ BULLET
122
+ return { type: :numbered, text: ::Regexp.last_match(1) } if line =~ NUMBERED
123
+
124
+ { type: :text, line: line }
125
+ end
126
+
127
+ def block_xml(block)
128
+ case block[:type]
129
+ when :heading
130
+ "<w:p><w:pPr><w:pStyle w:val=\"Heading#{block[:level]}\"/></w:pPr>#{run_xml(block[:text])}</w:p>"
131
+ when :bullet
132
+ list_item_xml(block[:text], '1')
133
+ when :numbered
134
+ list_item_xml(block[:text], '2')
135
+ else
136
+ paragraph_xml(block[:lines])
137
+ end
138
+ end
139
+
140
+ def list_item_xml(text, num_id)
141
+ "<w:p><w:pPr><w:numPr><w:ilvl w:val=\"0\"/><w:numId w:val=\"#{num_id}\"/></w:numPr></w:pPr>#{run_xml(text)}</w:p>"
80
142
  end
81
143
 
82
144
  def paragraph_xml(lines)
data/test/test_docxout.rb CHANGED
@@ -50,4 +50,50 @@ class TestDocxout < Minitest::Test
50
50
  assert_includes(document_xml, 'Issue description')
51
51
  end
52
52
  end
53
+
54
+ def test_renders_markdown_headers_as_word_headings
55
+ Dir.mktmpdir do |temp_dir|
56
+ output = Docxout.new(temp_dir)
57
+ report = "# Title\n\n## Subtitle\n\n### Section"
58
+ path = File.join(temp_dir, output.print(report, 'volodya-lombrozo', 'gpt-3.5-turbo'))
59
+ document_xml = Zip::File.open(path) { |zip| zip.read('word/document.xml') }
60
+ %w[Heading1 Heading2 Heading3].each { |style| assert_includes(document_xml, %(<w:pStyle w:val="#{style}"/>)) }
61
+ assert_includes(document_xml, '>Title<')
62
+ refute_includes(document_xml, '# Title')
63
+ end
64
+ end
65
+
66
+ def test_renders_markdown_bullet_lists_as_word_lists
67
+ Dir.mktmpdir do |temp_dir|
68
+ output = Docxout.new(temp_dir)
69
+ report = "List is here:\n\n- one\n- two\n* three"
70
+ path = File.join(temp_dir, output.print(report, 'volodya-lombrozo', 'gpt-3.5-turbo'))
71
+ document_xml = Zip::File.open(path) { |zip| zip.read('word/document.xml') }
72
+ assert_includes(document_xml, '<w:numId w:val="1"/>')
73
+ assert_includes(document_xml, '>one<')
74
+ refute_includes(document_xml, '>- one<')
75
+ end
76
+ end
77
+
78
+ def test_renders_markdown_numbered_lists_as_word_lists
79
+ Dir.mktmpdir do |temp_dir|
80
+ output = Docxout.new(temp_dir)
81
+ report = "1. first\n2. second"
82
+ path = File.join(temp_dir, output.print(report, 'volodya-lombrozo', 'gpt-3.5-turbo'))
83
+ document_xml = Zip::File.open(path) { |zip| zip.read('word/document.xml') }
84
+ assert_includes(document_xml, '<w:numId w:val="2"/>')
85
+ assert_includes(document_xml, '>first<')
86
+ end
87
+ end
88
+
89
+ def test_docx_package_includes_a_valid_numbering_part
90
+ Dir.mktmpdir do |temp_dir|
91
+ output = Docxout.new(temp_dir)
92
+ path = File.join(temp_dir, output.print("- one\n- two", 'volodya-lombrozo', 'gpt-3.5-turbo'))
93
+ Zip::File.open(path) do |zip|
94
+ assert(zip.find_entry('word/numbering.xml'))
95
+ assert(zip.find_entry('word/_rels/document.xml.rels'))
96
+ end
97
+ end
98
+ end
53
99
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newsman
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Volodya Lombrozo