newsman 1.2.1 → 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: 28993b9f11754759d159a42a76b5979bec9c12980098de771abd5442fc124ccd
4
- data.tar.gz: 1e98570b8d3b0cb9b0694472e5fefa7fe780ce6434efa12cd231dfa86a31c885
3
+ metadata.gz: 8bff52319f7db052d667bb38fa31764a4204ddab745eeaaa1daf090d36a73789
4
+ data.tar.gz: a7ccce39053631d627d210fea0897988b29ac24a62d9a17f98d83055777fbe40
5
5
  SHA512:
6
- metadata.gz: a807c540f352124e1a89d485cccfb2f0cf6ff36300b42d57ebb591b5e3e4b03d12413325f69a75d7f99e309c0813d336b1c3e32bb71012e22dd1093129cee5a6
7
- data.tar.gz: 81a635a5caba68596e9c3acd7a242fbf597da0cb06ce87c2103cdab84c1e2e89ef59ec9812e997ff970a0484a16ace406415a83b8c642f6db8ff0f82e571c111
6
+ metadata.gz: 638afa442dd92022d7966ea99405fea3838a6a92edd12c71f32d9a7cb8392c59287e647d8376524e9a97f61ea9ce3b74b5160b85b27940627d478528d76d3eef
7
+ data.tar.gz: c8ee4f4a28435a66132f865046f222a2370361884d81d29536e1748778429cfd1a60581e6027448c0bbf5a491d55fda13e0d3f45af293e25b5fbe9d9fff5d5c2
data/README.md CHANGED
@@ -98,6 +98,25 @@ newsman --help
98
98
  ```
99
99
  And you should see a welcome message from newsman.
100
100
 
101
+ ## Releases
102
+
103
+ Releases are handled by the [`release.yaml`](.github/workflows/release.yaml) GitHub Actions workflow. It runs whenever a tag matching `v*.*.*` (e.g. `v1.2.1`) is pushed, or manually via `workflow_dispatch`. On trigger it:
104
+
105
+ 1. Runs the test suite (`rake test`) and RuboCop (`rake rubocop`).
106
+ 2. Builds and installs the gem (`rake install`).
107
+ 3. Publishes the gem to [RubyGems.org](https://rubygems.org/gems/newsman) (`rake publish`), using the `RUBYGEMS_API_KEY` secret.
108
+ 4. Creates a GitHub Release for the pushed tag, using the `RELEASE_GITHUB_TOKEN` secret.
109
+
110
+ ### How to cut a release
111
+
112
+ 1. **Bump the version** in `newsman.gemspec` (`spec.version`) and commit it to `main`. RubyGems refuses to publish a version that's already live, so this step is mandatory - the workflow's `gem push` will silently fail otherwise (the publish step is `continue-on-error: true`, so the run can still show green even though nothing was actually published).
113
+ 2. **Tag the commit** with the same version, prefixed with `v`, and push the tag:
114
+ ```shell
115
+ git tag v1.2.1
116
+ git push origin v1.2.1
117
+ ```
118
+ 3. Watch the `Release Ruby Gem` workflow run in the Actions tab, and confirm the new version shows up on [RubyGems.org](https://rubygems.org/gems/newsman) and as a [GitHub Release](https://github.com/volodya-lombrozo/newsman/releases).
119
+
101
120
  ## Examples
102
121
 
103
122
  You can find examples of generated reports [here](https://volodya-lombrozo.github.io/newsman/)
@@ -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}```.
@@ -112,32 +118,32 @@ class Assistant
112
118
  send(prompt)
113
119
  end
114
120
 
115
- # rubocop:disable Metrics/MethodLength
121
+ # OpenAI's reasoning-family models (o1, o3, o4-mini, gpt-5, ...) only accept
122
+ # the default temperature (1) and reject any explicit value with a 400.
123
+ # Their "-chat" flavors (e.g. gpt-5-chat-latest) are non-reasoning and
124
+ # support a custom temperature just like gpt-4o, gpt-3.5-turbo, etc.
125
+ FIXED_TEMPERATURE_MODELS = /\A(o[1-9]|gpt-5)/
126
+
116
127
  def send(request)
128
+ parameters = { model: @model, messages: messages(request) }
129
+ parameters[:temperature] = @temperature unless fixed_temperature?
130
+ @client.chat(parameters: parameters).dig('choices', 0, 'message', 'content')
131
+ end
132
+
133
+ def fixed_temperature?
134
+ @model.match?(FIXED_TEMPERATURE_MODELS) && !@model.include?('chat')
135
+ end
136
+
137
+ SYSTEM_PROMPT = 'You are a developer tasked with composing a concise report detailing'\
138
+ ' your activities and progress for the previous week, intended for submission to your supervisor.'
139
+
140
+ def messages(request)
117
141
  if @model == 'o1-preview'
118
- @client.chat(
119
- parameters: {
120
- model: @model,
121
- messages: [{ role: 'user', content: request.to_s }]
122
- }
123
- ).dig('choices', 0, 'message', 'content')
142
+ [{ role: 'user', content: request.to_s }]
124
143
  else
125
- @client.chat(
126
- parameters: {
127
- model: @model,
128
- messages: [
129
- { role: 'system', content: 'You are a developer tasked'\
130
- ' with composing a concise report detailing your activities'\
131
- ' and progress for the previous week,'\
132
- ' intended for submission to your supervisor.' },
133
- { role: 'user', content: request.to_s }
134
- ],
135
- temperature: @temperature
136
- }
137
- ).dig('choices', 0, 'message', 'content')
144
+ [{ role: 'system', content: SYSTEM_PROMPT }, { role: 'user', content: request.to_s }]
138
145
  end
139
146
  end
140
- # rubocop:enable Metrics/MethodLength
141
147
 
142
148
  def deprecated(method)
143
149
  warn "Warning! '#{method}' is deprecated and will be removed in future versions."
@@ -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)
@@ -35,4 +35,31 @@ class TestAssistant < Minitest::Test
35
35
  assert_equal expected,
36
36
  assistant.say_hello
37
37
  end
38
+
39
+ def test_fixed_temperature_for_reasoning_models
40
+ %w[o1 o1-preview o1-mini o3 o3-mini o4-mini gpt-5 gpt-5-mini gpt-5.6].each do |model|
41
+ assistant = Assistant.new('test-token', model: model)
42
+ assert(assistant.fixed_temperature?, "expected #{model} to have a fixed temperature")
43
+ end
44
+ end
45
+
46
+ def test_custom_temperature_for_chat_models
47
+ %w[gpt-3.5-turbo gpt-4o gpt-4.1 gpt-5-chat-latest].each do |model|
48
+ assistant = Assistant.new('test-token', model: model)
49
+ refute(assistant.fixed_temperature?, "expected #{model} to allow a custom temperature")
50
+ end
51
+ end
52
+
53
+ def test_o1_preview_skips_system_message
54
+ assistant = Assistant.new('test-token', model: 'o1-preview')
55
+ messages = assistant.messages('do something')
56
+ assert_equal([{ role: 'user', content: 'do something' }], messages)
57
+ end
58
+
59
+ def test_other_models_keep_system_message
60
+ assistant = Assistant.new('test-token', model: 'gpt-5.6')
61
+ messages = assistant.messages('do something')
62
+ assert_equal(2, messages.size)
63
+ assert_equal('system', messages.first[:role])
64
+ end
38
65
  end
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.1
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Volodya Lombrozo