commit_format 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef4ace94c6a11e7172e7013ce1eebbccd4ab41e26d3e926b109f10af2e69bf39
4
- data.tar.gz: b314bbcc2b661def7c107cf3ea2ea6d0d129695348618fefb9af79b1a20b3224
3
+ metadata.gz: 68d7c9f7d1e0c01f028da842d66ccce4fb35b24e867cd6a813d31d6bf2146503
4
+ data.tar.gz: 901660bfa3f3794ae6f58a7d17f552a2e5e07386dbd5cf9ba9c425b60d77a83c
5
5
  SHA512:
6
- metadata.gz: 14701063826fe6467c185353da71aeb2bf7b92fe01fc94e34a1e4aa7f4ef6169e3b6f1f3f78b16113c81928eaf2f263d7183be38cf0d56564da099e84fdcd4b7
7
- data.tar.gz: c6b176440cfc56cab8003151c41bf940f6ce67879ea7298827847c65eb6d5ad9b86eaf55c1a7b5e283571e55ee08c32f6deddd737622c2aa159b5ddb9782b88b
6
+ metadata.gz: b142b8f0a27079b93a7a2c8621a755d948120d06099bc3c1f514a157633bd6eabedc66751b67d205bf3761899d61b042461497c22169e0178a930c79a9404dc0
7
+ data.tar.gz: c2aaa0b482a4e97c6741a8d9f12b5ca779d3b26c135f4f7a2352d9c1f4cc07997157102a6eae1c63d77ff786e116513b9c39017fab6aa750b99d87d9e755c068
data/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Commit Format
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Added
6
+
7
+ - [5c3aed6](https://github.com/tombruijn/commit-format/commit/5c3aed6b4d4610842fbf57e7b4fede06283c6bba) minor - Add paragraph flag to format message body output to join paragraph lines. This is similar to how GitHub now formats Pull Requests with a single commit. Use `-p`/`--paragraph` to use this feature.
8
+
9
+ Given a commit with the message body of two lines:
10
+
11
+ ```
12
+ Line 1.
13
+ Line 2.
14
+
15
+ - Item 1.
16
+ - Item 2.
17
+ ```
18
+
19
+ This is output as:
20
+
21
+ ```
22
+ Line 1. Line 2.
23
+
24
+ - Item 1.
25
+ - Item 2.
26
+ ```
27
+
28
+ Other Markdown syntax, like tables, lists, code blocks, etc. are all kept in their original format in the output. Their lines are not joined into one line.
29
+
3
30
  ## 0.1.0
4
31
 
5
32
  Initial release.
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [tom@tomdebruijn.com](mailto:tom@tomdebruijn.com).
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/README.md CHANGED
@@ -29,6 +29,10 @@ commit-format -n 5
29
29
  # Print all new commits since selected base branch
30
30
  commit-format -b main
31
31
  commit-format -b feature-branch
32
+
33
+ # Print all commits with text lines joined into a paragraph
34
+ commit-format --paragraph
35
+ commit-format -p
32
36
  ```
33
37
 
34
38
  ## Features
@@ -36,6 +40,17 @@ commit-format -b feature-branch
36
40
  - Turns each commit subject into a markdown heading.
37
41
  - Indents all headings in the message body on level lower. Heading level 2
38
42
  becomes heading level 3, etc.
43
+ - Join text lines together as continuous paragraphs for easier reading in Pull
44
+ Requests. Markdown syntax like code block, blockquotes, lists, tables, etc.
45
+ are all kept in their original format.
46
+ ```
47
+ # For example:
48
+ A commit message with multiple text lines
49
+ across multiple lines.
50
+
51
+ # Becomes
52
+ A commit message with multiple text lines across multiple line.
53
+ ```
39
54
 
40
55
  ## Development
41
56
 
@@ -28,7 +28,7 @@ Gem::Specification.new do |gem|
28
28
  "source_code_uri" => "https://github.com/tombruijn/commit-format"
29
29
  }
30
30
 
31
- gem.add_development_dependency "pry", "0.14.1"
31
+ gem.add_development_dependency "debug", "1.6.2"
32
32
  gem.add_development_dependency "rspec", "3.10.0"
33
33
  gem.add_development_dependency "rubocop", "1.25.0"
34
34
  end
@@ -12,7 +12,11 @@ module CommitFormat
12
12
  parser = Parser.new(@args)
13
13
  commits = parser.commits
14
14
 
15
- formatter = Formatter.new(commits)
15
+ formatter =
16
+ Formatter.new(
17
+ commits,
18
+ :paragraph => @args.fetch(:paragraph, false)
19
+ )
16
20
  formatted_commits = formatter.formatted_commits
17
21
  print_formatted_commits(formatted_commits)
18
22
  end
@@ -31,10 +35,17 @@ module CommitFormat
31
35
 
32
36
  def parse_args(args) # rubocop:disable Metrics/MethodLength
33
37
  options = {}
34
- OptionParser.new do |parser|
38
+ OptionParser.new do |parser| # rubocop:disable Metrics/BlockLength
35
39
  document_cli(parser)
36
40
 
37
41
  parser.separator "Options:"
42
+ parser.on(
43
+ "-p",
44
+ "--paragraph",
45
+ "Join paragraph lines into one line"
46
+ ) do |paragraph|
47
+ options[:paragraph] = paragraph
48
+ end
38
49
  parser.on(
39
50
  "-n",
40
51
  "--max-count <number>",
@@ -2,16 +2,34 @@
2
2
 
3
3
  module CommitFormat
4
4
  class Formatter
5
- def initialize(commits)
5
+ def initialize(commits, options = {})
6
6
  @commits = commits
7
+ @paragraph = options[:paragraph]
7
8
  end
8
9
 
9
10
  def formatted_commits
10
- @commits.map { |commit| format_commit(commit) }
11
+ @commits.map do |commit|
12
+ if @paragraph
13
+ format_commit_as_paragraphs(commit)
14
+ else
15
+ format_commit(commit)
16
+ end
17
+ end
11
18
  end
12
19
 
13
20
  private
14
21
 
22
+ def format_commit_as_paragraphs(commit)
23
+ message = Message.new
24
+ lines = commit.split("\n")
25
+ subject = "## #{lines.shift}\n"
26
+ lines.each do |line|
27
+ message.line line
28
+ end
29
+ message.end!
30
+ "#{subject}#{message}"
31
+ end
32
+
15
33
  def format_commit(commit)
16
34
  formatted_commit =
17
35
  commit.lines.map do |line|
@@ -25,5 +43,114 @@ module CommitFormat
25
43
  # Start subject with a heading
26
44
  "## #{formatted_commit}"
27
45
  end
46
+
47
+ class Message
48
+ def initialize
49
+ @lines = []
50
+ @paragraph = []
51
+ @code_block = false
52
+ end
53
+
54
+ def line(string) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
55
+ if code_block_fence?(string)
56
+ new_paragraph
57
+ code_block!
58
+ lines << string
59
+ return
60
+ elsif code_block?
61
+ lines << string
62
+ return
63
+ elsif string.empty? # Line break
64
+ new_paragraph
65
+ line_break
66
+ return
67
+ elsif string.start_with? "#"
68
+ write_paragraph
69
+ heading string
70
+ return
71
+ elsif fixed_line?(string)
72
+ new_paragraph
73
+ lines << string
74
+ return
75
+ elsif heading_line?(string)
76
+ write_paragraph
77
+ lines << string
78
+ return
79
+ end
80
+
81
+ paragraph << string
82
+ # Line with line break and the end
83
+ write_paragraph if string.end_with? " "
84
+ end
85
+
86
+ def end!
87
+ write_paragraph
88
+ end
89
+
90
+ def to_s
91
+ @lines.join("\n")
92
+ end
93
+
94
+ private
95
+
96
+ LINE_BREAK = ""
97
+
98
+ attr_reader :lines, :paragraph
99
+
100
+ def new_paragraph
101
+ write_paragraph if paragraph.any?
102
+ end
103
+
104
+ def write_paragraph
105
+ return unless paragraph.any?
106
+
107
+ lines << paragraph.join(" ")
108
+ clear_paragraph!
109
+ end
110
+
111
+ def heading(string)
112
+ lines << "##{string}"
113
+ end
114
+
115
+ HEADING_LINE_CHARS = ["=", "-"].freeze
116
+
117
+ def heading_line?(string)
118
+ line = string.strip
119
+ uniq_chars = line.chars.uniq
120
+ return false if uniq_chars.length > 1
121
+
122
+ HEADING_LINE_CHARS.include?(uniq_chars.first)
123
+ end
124
+
125
+ def fixed_line?(string)
126
+ string.start_with?(" ") || # Indented line
127
+ string.start_with?("\t") || # Indented line
128
+ string.start_with?("- ") || # Unordered list item
129
+ string.start_with?("* ") || # Unordered list item
130
+ string.start_with?("|") || # Table
131
+ string.start_with?("> ") || # Blockquote
132
+ string.start_with?(/\d+\. /) # Numbered list item
133
+ end
134
+
135
+ def clear_paragraph!
136
+ @paragraph = []
137
+ end
138
+
139
+ def code_block?
140
+ @code_block
141
+ end
142
+
143
+ def code_block!
144
+ @code_block = !@code_block
145
+ end
146
+
147
+ def code_block_fence?(string)
148
+ string.start_with?("```") || string.start_with?("~~~")
149
+ end
150
+
151
+ def line_break
152
+ lines << LINE_BREAK
153
+ end
154
+ end
28
155
  end
29
156
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CommitFormat
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -4,7 +4,7 @@ RSpec.describe CommitFormat::Cli do
4
4
  describe "with --version flag" do
5
5
  it "prints the version number" do
6
6
  output = run_version
7
- expect(output).to eql(CommitFormat::VERSION)
7
+ expect(output.strip).to eql(CommitFormat::VERSION)
8
8
  end
9
9
  end
10
10
 
@@ -31,6 +31,374 @@ RSpec.describe CommitFormat::Cli do
31
31
  Second line.
32
32
  OUTPUT
33
33
  end
34
+
35
+ it "indents headings by one level" do
36
+ test_dir = "indent_headings"
37
+ prepare_repository test_dir do
38
+ create_commit "Commit subject 1", "Commit message body.\nSecond line."
39
+ checkout_branch "my-branch"
40
+ create_commit "Commit subject 2", <<~MESSAGE
41
+ Commit message body.
42
+ Second line.
43
+
44
+ ## Heading 2
45
+
46
+ Hello heading.
47
+ Other line.
48
+ MESSAGE
49
+ end
50
+
51
+ output = run(test_dir)
52
+ expect(output).to eql(<<~OUTPUT)
53
+ ## Commit subject 2
54
+
55
+ Commit message body.
56
+ Second line.
57
+
58
+ ### Heading 2
59
+
60
+ Hello heading.
61
+ Other line.
62
+ OUTPUT
63
+ end
64
+ end
65
+
66
+ describe "with --paragraph flag" do
67
+ it "formats all commits to main branch as paragraphs" do
68
+ test_dir = "paragraph_flag"
69
+ prepare_repository test_dir do
70
+ create_commit "Commit subject 1", "Commit message body.\nSecond line."
71
+ checkout_branch "my-branch"
72
+ create_commit "Commit subject 2",
73
+ <<~MESSAGE
74
+ Commit message body.
75
+ Second line.
76
+ MESSAGE
77
+ end
78
+
79
+ output = run(test_dir, ["--paragraph"])
80
+ expect(output).to eql(<<~OUTPUT)
81
+ ## Commit subject 2
82
+
83
+ Commit message body. Second line.
84
+ OUTPUT
85
+ end
86
+
87
+ it "indents headings by one level" do
88
+ test_dir = "paragraph_flag_headings"
89
+ prepare_repository test_dir do
90
+ create_commit "Commit subject 1", "Commit message body.\nSecond line."
91
+ checkout_branch "my-branch"
92
+ create_commit "Commit subject 2",
93
+ <<~MESSAGE
94
+ Commit message body.
95
+ Second line.
96
+
97
+ ## Heading 2
98
+
99
+ Hello heading.
100
+ ## Heading 2
101
+ Other line.
102
+ MESSAGE
103
+ end
104
+
105
+ output = run(test_dir, ["--paragraph"])
106
+ expect(output).to eql(<<~OUTPUT)
107
+ ## Commit subject 2
108
+
109
+ Commit message body. Second line.
110
+
111
+ ### Heading 2
112
+
113
+ Hello heading.
114
+ ### Heading 2
115
+ Other line.
116
+ OUTPUT
117
+ end
118
+
119
+ it "keeps underline heading formatting" do
120
+ test_dir = "paragraph_flag_headings_underline"
121
+ prepare_repository test_dir do
122
+ create_commit "Commit subject 1", "Commit message body.\nSecond line."
123
+ checkout_branch "my-branch"
124
+ create_commit "Commit subject 2",
125
+ <<~MESSAGE
126
+ Commit message body.
127
+
128
+ Heading 2
129
+ ---
130
+
131
+ End of message.
132
+ MESSAGE
133
+ end
134
+
135
+ output = run(test_dir, ["--paragraph"])
136
+ expect(output).to eql(<<~OUTPUT)
137
+ ## Commit subject 2
138
+
139
+ Commit message body.
140
+
141
+ Heading 2
142
+ ---
143
+
144
+ End of message.
145
+ OUTPUT
146
+ end
147
+
148
+ it "keeps indented lines" do
149
+ test_dir = "paragraph_flag_indented"
150
+ prepare_repository test_dir do
151
+ create_commit "Commit subject 1", "Commit message body.\nSecond line."
152
+ checkout_branch "my-branch"
153
+ create_commit "Commit subject 2",
154
+ <<~MESSAGE
155
+ Commit message body.
156
+
157
+ Hello code.
158
+ Other line.
159
+
160
+ Paragraph line.
161
+
162
+ \tNew indented
163
+ \tblock.
164
+ MESSAGE
165
+ end
166
+
167
+ output = run(test_dir, ["--paragraph"])
168
+ expect(output).to eql(<<~OUTPUT)
169
+ ## Commit subject 2
170
+
171
+ Commit message body.
172
+
173
+ Hello code.
174
+ Other line.
175
+
176
+ Paragraph line.
177
+
178
+ \tNew indented
179
+ \tblock.
180
+ OUTPUT
181
+ end
182
+
183
+ it "starts a new line after a line ending with two spaces" do
184
+ test_dir = "paragraph_flag_end_spaces"
185
+ prepare_repository test_dir do
186
+ create_commit "Commit subject 1", "Commit message body.\nSecond line."
187
+ checkout_branch "my-branch"
188
+ create_commit "Commit subject 2", <<~MESSAGE, :verbatim => true
189
+ Commit message body.
190
+ Second line.
191
+
192
+ Start line.
193
+ Hello line.\x20\x20
194
+ Next line.
195
+
196
+ Footer
197
+ MESSAGE
198
+ end
199
+
200
+ output = run(test_dir, ["--paragraph"])
201
+ expect(output).to eql(<<~OUTPUT)
202
+ ## Commit subject 2
203
+
204
+ Commit message body. Second line.
205
+
206
+ Start line. Hello line.\x20\x20
207
+ Next line.
208
+
209
+ Footer
210
+ OUTPUT
211
+ end
212
+
213
+ it "keeps list formatting" do
214
+ test_dir = "paragraph_flag_lists"
215
+ prepare_repository test_dir do
216
+ create_commit "Commit subject 1", "Commit message body.\nSecond line."
217
+ checkout_branch "my-branch"
218
+ create_commit "Commit subject 2",
219
+ <<~MESSAGE
220
+ Commit message body.
221
+ Second line.
222
+
223
+ - Hello list.
224
+ Other line.
225
+ - Test
226
+ * Second item.
227
+ * Third item.
228
+
229
+ 1. First item.
230
+ 2. Second item.
231
+ 1. Third item.
232
+ - End list
233
+
234
+ Footer
235
+ MESSAGE
236
+ end
237
+
238
+ output = run(test_dir, ["--paragraph"])
239
+ expect(output).to eql(<<~OUTPUT)
240
+ ## Commit subject 2
241
+
242
+ Commit message body. Second line.
243
+
244
+ - Hello list.
245
+ Other line.
246
+ - Test
247
+ * Second item.
248
+ * Third item.
249
+
250
+ 1. First item.
251
+ 2. Second item.
252
+ 1. Third item.
253
+ - End list
254
+
255
+ Footer
256
+ OUTPUT
257
+ end
258
+
259
+ it "keeps tables formatting" do
260
+ test_dir = "paragraph_flag_tables"
261
+ prepare_repository test_dir do
262
+ create_commit "Commit subject 1", "Commit message body.\nSecond line."
263
+ checkout_branch "my-branch"
264
+ create_commit "Commit subject 2",
265
+ <<~MESSAGE
266
+ Commit message body.
267
+ Second line.
268
+
269
+ | Heading 1 | Heading 2 |
270
+ | --------- |:---------:|
271
+ | lorem | lorem |
272
+ | lorem | lorem |
273
+ | lorem | lorem |
274
+
275
+ Footer
276
+ MESSAGE
277
+ end
278
+
279
+ output = run(test_dir, ["--paragraph"])
280
+ expect(output).to eql(<<~OUTPUT)
281
+ ## Commit subject 2
282
+
283
+ Commit message body. Second line.
284
+
285
+ | Heading 1 | Heading 2 |
286
+ | --------- |:---------:|
287
+ | lorem | lorem |
288
+ | lorem | lorem |
289
+ | lorem | lorem |
290
+
291
+ Footer
292
+ OUTPUT
293
+ end
294
+
295
+ it "keeps blockquotes formatting" do
296
+ test_dir = "paragraph_flag_blockquotes"
297
+ prepare_repository test_dir do
298
+ create_commit "Commit subject 1", "Commit message body.\nSecond line."
299
+ checkout_branch "my-branch"
300
+ create_commit "Commit subject 2",
301
+ <<~MESSAGE
302
+ Commit message body.
303
+ Second line.
304
+
305
+ > I am a quote
306
+ > I am another quote
307
+
308
+ > Second quote
309
+
310
+ Footer
311
+ MESSAGE
312
+ end
313
+
314
+ output = run(test_dir, ["--paragraph"])
315
+ expect(output).to eql(<<~OUTPUT)
316
+ ## Commit subject 2
317
+
318
+ Commit message body. Second line.
319
+
320
+ > I am a quote
321
+ > I am another quote
322
+
323
+ > Second quote
324
+
325
+ Footer
326
+ OUTPUT
327
+ end
328
+
329
+ it "keeps code blocks formatting" do
330
+ test_dir = "paragraph_flag_code_blocks"
331
+ prepare_repository test_dir do
332
+ create_commit "Commit subject 1", "Commit message body.\nSecond line."
333
+ checkout_branch "my-branch"
334
+ create_commit "Commit subject 2",
335
+ <<~MESSAGE
336
+ Commit message body.
337
+ Second line.
338
+
339
+ ```ruby
340
+ Hello code.
341
+ # Comment line
342
+ Other line.
343
+ ```
344
+
345
+ ~~~ruby
346
+ Hello code.
347
+ Other line.
348
+ ~~~
349
+
350
+ New paragraph.
351
+ With new line.
352
+ MESSAGE
353
+ end
354
+
355
+ output = run(test_dir, ["--paragraph"])
356
+ expect(output).to eql(<<~OUTPUT)
357
+ ## Commit subject 2
358
+
359
+ Commit message body. Second line.
360
+
361
+ ```ruby
362
+ Hello code.
363
+ # Comment line
364
+ Other line.
365
+ ```
366
+
367
+ ~~~ruby
368
+ Hello code.
369
+ Other line.
370
+ ~~~
371
+
372
+ New paragraph. With new line.
373
+ OUTPUT
374
+ end
375
+
376
+ it "keeps horizontal line formatting" do
377
+ test_dir = "paragraph_flag_horizontal_line"
378
+ prepare_repository test_dir do
379
+ create_commit "Commit subject 1", "Commit message body.\nSecond line."
380
+ checkout_branch "my-branch"
381
+ create_commit "Commit subject 2",
382
+ <<~MESSAGE
383
+ Commit message body.
384
+
385
+ ---
386
+
387
+ New paragraph.
388
+ MESSAGE
389
+ end
390
+
391
+ output = run(test_dir, ["--paragraph"])
392
+ expect(output).to eql(<<~OUTPUT)
393
+ ## Commit subject 2
394
+
395
+ Commit message body.
396
+
397
+ ---
398
+
399
+ New paragraph.
400
+ OUTPUT
401
+ end
34
402
  end
35
403
 
36
404
  context "with --base-branch argument" do
@@ -198,8 +566,6 @@ RSpec.describe CommitFormat::Cli do
198
566
  end
199
567
 
200
568
  def run_version
201
- capture_stdout do
202
- CommitFormat::Cli.new(["--version"]).execute
203
- end
569
+ `bin/commit-format --version`
204
570
  end
205
571
  end
@@ -28,7 +28,9 @@ module RepositoryHelper
28
28
  `git checkout -b "#{name}"`
29
29
  end
30
30
 
31
- def create_commit(subject, message)
32
- `git commit --allow-empty -m "#{subject}" -m "#{message}"`
31
+ def create_commit(subject, message, verbatim: false)
32
+ options = []
33
+ options << "--cleanup verbatim" if verbatim
34
+ `git commit --allow-empty -m "#{subject}" -m '#{message}' #{options.join(" ")}`
33
35
  end
34
36
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commit_format
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom de Bruijn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-23 00:00:00.000000000 Z
11
+ date: 2022-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: pry
14
+ name: debug
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.14.1
19
+ version: 1.6.2
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.14.1
26
+ version: 1.6.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -67,6 +67,7 @@ files:
67
67
  - ".rubocop.yml"
68
68
  - ".semaphore/semaphore.yml"
69
69
  - CHANGELOG.md
70
+ - CODE_OF_CONDUCT.md
70
71
  - Gemfile
71
72
  - LICENSE
72
73
  - README.md
@@ -107,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
108
  - !ruby/object:Gem::Version
108
109
  version: '0'
109
110
  requirements: []
110
- rubygems_version: 3.3.4
111
+ rubygems_version: 3.3.22
111
112
  signing_key:
112
113
  specification_version: 4
113
114
  summary: Git commit formatter utility.