commit_format 0.1.0 → 0.2.1

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: 6841477fd9879e1b5b5064bad1181090da3f64ff209cb8972b7831dfd9d4c084
4
+ data.tar.gz: 5aaa3c39ec85dac873a052639ed5651fbdae2b165bfb6790f0738b3c0d9bc829
5
5
  SHA512:
6
- metadata.gz: 14701063826fe6467c185353da71aeb2bf7b92fe01fc94e34a1e4aa7f4ef6169e3b6f1f3f78b16113c81928eaf2f263d7183be38cf0d56564da099e84fdcd4b7
7
- data.tar.gz: c6b176440cfc56cab8003151c41bf940f6ce67879ea7298827847c65eb6d5ad9b86eaf55c1a7b5e283571e55ee08c32f6deddd737622c2aa159b5ddb9782b88b
6
+ metadata.gz: 56b78c358da12ba3e1157a6e5e3c3a0f9a4c6f4ed69e4d210fd415e6575f7726aee2b9d0e7f9514230b59464c9b437acdec55b0a851bfae1ac201d358e81e129
7
+ data.tar.gz: aa1e1f983f333951871d861f541f8808f07da8e0f491028819e740bc0b7df97c98752c4d97c06a6760ed4d2a6f2f7b1e3f02da7cd3239c18ac3df2fd22a7074d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # Commit Format
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Fixed
6
+
7
+ - [bd1a3d5](https://github.com/tombruijn/commit-format/commit/bd1a3d5a7466cf8c18634474d009021c034d9b15) patch - Paragraph flag doesn't join link references on multiple lines.
8
+
9
+ ## 0.2.0
10
+
11
+ ### Added
12
+
13
+ - [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.
14
+
15
+ Given a commit with the message body of two lines:
16
+
17
+ ```
18
+ Line 1.
19
+ Line 2.
20
+
21
+ - Item 1.
22
+ - Item 2.
23
+ ```
24
+
25
+ This is output as:
26
+
27
+ ```
28
+ Line 1. Line 2.
29
+
30
+ - Item 1.
31
+ - Item 2.
32
+ ```
33
+
34
+ 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.
35
+
3
36
  ## 0.1.0
4
37
 
5
38
  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,115 @@ 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) # rubocop:disable Metrics/CyclomaticComplexity
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
+ string.start_with?(/\[[^\]]+\]:\s.+/) # Link reference
134
+ end
135
+
136
+ def clear_paragraph!
137
+ @paragraph = []
138
+ end
139
+
140
+ def code_block?
141
+ @code_block
142
+ end
143
+
144
+ def code_block!
145
+ @code_block = !@code_block
146
+ end
147
+
148
+ def code_block_fence?(string)
149
+ string.start_with?("```") || string.start_with?("~~~")
150
+ end
151
+
152
+ def line_break
153
+ lines << LINE_BREAK
154
+ end
155
+ end
28
156
  end
29
157
  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.1"
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,405 @@ 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 link reference formatting" do
260
+ test_dir = "paragraph_flag_link_references"
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
+ [Link label](http://localhost:3000/path1) extra part.
268
+ Third line.
269
+
270
+ [Link name 1]: http://localhost:3000/path1
271
+ [Link name 2]: http://localhost:3000/path2
272
+
273
+ Footer
274
+ MESSAGE
275
+ end
276
+
277
+ output = run(test_dir, ["--paragraph"])
278
+ expect(output).to eql(<<~OUTPUT)
279
+ ## Commit subject 2
280
+
281
+ Commit message body. [Link label](http://localhost:3000/path1) extra part. Third line.
282
+
283
+ [Link name 1]: http://localhost:3000/path1
284
+ [Link name 2]: http://localhost:3000/path2
285
+
286
+ Footer
287
+ OUTPUT
288
+ end
289
+
290
+ it "keeps tables formatting" do
291
+ test_dir = "paragraph_flag_tables"
292
+ prepare_repository test_dir do
293
+ create_commit "Commit subject 1", "Commit message body.\nSecond line."
294
+ checkout_branch "my-branch"
295
+ create_commit "Commit subject 2",
296
+ <<~MESSAGE
297
+ Commit message body.
298
+ Second line.
299
+
300
+ | Heading 1 | Heading 2 |
301
+ | --------- |:---------:|
302
+ | lorem | lorem |
303
+ | lorem | lorem |
304
+ | lorem | lorem |
305
+
306
+ Footer
307
+ MESSAGE
308
+ end
309
+
310
+ output = run(test_dir, ["--paragraph"])
311
+ expect(output).to eql(<<~OUTPUT)
312
+ ## Commit subject 2
313
+
314
+ Commit message body. Second line.
315
+
316
+ | Heading 1 | Heading 2 |
317
+ | --------- |:---------:|
318
+ | lorem | lorem |
319
+ | lorem | lorem |
320
+ | lorem | lorem |
321
+
322
+ Footer
323
+ OUTPUT
324
+ end
325
+
326
+ it "keeps blockquotes formatting" do
327
+ test_dir = "paragraph_flag_blockquotes"
328
+ prepare_repository test_dir do
329
+ create_commit "Commit subject 1", "Commit message body.\nSecond line."
330
+ checkout_branch "my-branch"
331
+ create_commit "Commit subject 2",
332
+ <<~MESSAGE
333
+ Commit message body.
334
+ Second line.
335
+
336
+ > I am a quote
337
+ > I am another quote
338
+
339
+ > Second quote
340
+
341
+ Footer
342
+ MESSAGE
343
+ end
344
+
345
+ output = run(test_dir, ["--paragraph"])
346
+ expect(output).to eql(<<~OUTPUT)
347
+ ## Commit subject 2
348
+
349
+ Commit message body. Second line.
350
+
351
+ > I am a quote
352
+ > I am another quote
353
+
354
+ > Second quote
355
+
356
+ Footer
357
+ OUTPUT
358
+ end
359
+
360
+ it "keeps code blocks formatting" do
361
+ test_dir = "paragraph_flag_code_blocks"
362
+ prepare_repository test_dir do
363
+ create_commit "Commit subject 1", "Commit message body.\nSecond line."
364
+ checkout_branch "my-branch"
365
+ create_commit "Commit subject 2",
366
+ <<~MESSAGE
367
+ Commit message body.
368
+ Second line.
369
+
370
+ ```ruby
371
+ Hello code.
372
+ # Comment line
373
+ Other line.
374
+ ```
375
+
376
+ ~~~ruby
377
+ Hello code.
378
+ Other line.
379
+ ~~~
380
+
381
+ New paragraph.
382
+ With new line.
383
+ MESSAGE
384
+ end
385
+
386
+ output = run(test_dir, ["--paragraph"])
387
+ expect(output).to eql(<<~OUTPUT)
388
+ ## Commit subject 2
389
+
390
+ Commit message body. Second line.
391
+
392
+ ```ruby
393
+ Hello code.
394
+ # Comment line
395
+ Other line.
396
+ ```
397
+
398
+ ~~~ruby
399
+ Hello code.
400
+ Other line.
401
+ ~~~
402
+
403
+ New paragraph. With new line.
404
+ OUTPUT
405
+ end
406
+
407
+ it "keeps horizontal line formatting" do
408
+ test_dir = "paragraph_flag_horizontal_line"
409
+ prepare_repository test_dir do
410
+ create_commit "Commit subject 1", "Commit message body.\nSecond line."
411
+ checkout_branch "my-branch"
412
+ create_commit "Commit subject 2",
413
+ <<~MESSAGE
414
+ Commit message body.
415
+
416
+ ---
417
+
418
+ New paragraph.
419
+ MESSAGE
420
+ end
421
+
422
+ output = run(test_dir, ["--paragraph"])
423
+ expect(output).to eql(<<~OUTPUT)
424
+ ## Commit subject 2
425
+
426
+ Commit message body.
427
+
428
+ ---
429
+
430
+ New paragraph.
431
+ OUTPUT
432
+ end
34
433
  end
35
434
 
36
435
  context "with --base-branch argument" do
@@ -198,8 +597,6 @@ RSpec.describe CommitFormat::Cli do
198
597
  end
199
598
 
200
599
  def run_version
201
- capture_stdout do
202
- CommitFormat::Cli.new(["--version"]).execute
203
- end
600
+ `bin/commit-format --version`
204
601
  end
205
602
  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.1
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-10-01 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.