Skip to content

Commit deb04c2

Browse files
committed
fix: join multi-line commit bodies into single body field
Previously `build_commit` split body lines into separate `body` and `footer` fields, losing content beyond the second paragraph. Now all non-header lines are joined into `body`. Also disables GitHub API lookups in release tests to prevent rate-limit-induced timeouts.
1 parent 9a1f2a5 commit deb04c2

3 files changed

Lines changed: 21 additions & 14 deletions

File tree

lib/git_ops/commit.ex

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ defmodule GitOps.Commit do
9696
end
9797

9898
footer_text =
99-
if breaking? && String.starts_with?(body || "", "BREAKING CHANGE:") do
99+
if breaking? && footer && String.starts_with?(body || "", "BREAKING CHANGE:") do
100100
"\n\n" <> footer
101101
end
102102

@@ -221,22 +221,25 @@ defmodule GitOps.Commit do
221221
end
222222

223223
defp build_commit(parsed, body_lines, author_info, hash) do
224-
remaining =
224+
body =
225225
body_lines
226226
|> Enum.map(&String.trim/1)
227227
|> Enum.reject(&(&1 == ""))
228+
|> Enum.join("\n\n")
229+
|> case do
230+
"" -> nil
231+
text -> text
232+
end
228233

229-
body = Enum.at(remaining, 0)
230-
footer = Enum.at(remaining, 1)
231234
{author_name, author_email} = author_info || {nil, nil}
232235

233236
%__MODULE__{
234237
type: Enum.at(parsed[:type], 0),
235238
scope: scopes(parsed[:scope]),
236239
message: Enum.at(parsed[:message], 0),
237240
body: body,
238-
footer: footer,
239-
breaking?: breaking?(parsed[:breaking?], body, footer),
241+
footer: nil,
242+
breaking?: breaking?(parsed[:breaking?], body, nil),
240243
author_name: author_name,
241244
author_email: author_email,
242245
hash: hash
@@ -248,6 +251,5 @@ defmodule GitOps.Commit do
248251

249252
defp breaking?(breaking, _, _) when not is_nil(breaking), do: true
250253
defp breaking?(_, "BREAKING CHANGE:" <> _, _), do: true
251-
defp breaking?(_, _, "BREAKING CHANGE:" <> _), do: true
252254
defp breaking?(_, _, _), do: false
253255
end

test/commit_test.exs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ defmodule GitOps.Test.CommitTest do
105105
assert [
106106
%Commit{
107107
message: "fixed a bug",
108-
body: "some text about it",
109-
footer: "some even more data about it"
108+
body: "some text about it\n\nsome even more data about it",
109+
footer: nil
110110
},
111111
%Commit{
112112
message: "improved a thing",
113-
body: "some other text about it",
114-
footer: "some even more text about it"
113+
body: "some other text about it\n\nsome even more text about it",
114+
footer: nil
115115
}
116116
] = parse_many!(text)
117117
end
@@ -215,8 +215,9 @@ defmodule GitOps.Test.CommitTest do
215215

216216
assert %Commit{
217217
message: "resolve memory leak",
218-
body: "The connection pool was not being drained on shutdown.",
219-
footer: "This caused OOM errors in production."
218+
body:
219+
"The connection pool was not being drained on shutdown.\n\nThis caused OOM errors in production.",
220+
footer: nil
220221
} = parse_one!(text)
221222
end
222223

@@ -231,7 +232,8 @@ defmodule GitOps.Test.CommitTest do
231232

232233
commit = parse_one!(text)
233234
assert commit.breaking?
234-
assert commit.body == "BREAKING CHANGE: The v1 API has been removed."
235+
assert commit.body ==
236+
"BREAKING CHANGE: The v1 API has been removed.\n\nUsers must migrate to v2."
235237
end
236238

237239
test "non-conventional first line returns error" do

test/release_test.exs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ defmodule GitOps.Mix.Tasks.Test.ReleaseTest do
1717
Application.put_env(:git_ops, :manage_readme_version, true)
1818
Application.put_env(:git_ops, :types, custom: [header: "Custom"], docs: [hidden?: false])
1919
Application.put_env(:git_ops, :version_tag_prefix, "v")
20+
Application.put_env(:git_ops, :github_handle_lookup?, false)
2021

2122
on_exit(fn -> File.rm!(changelog) end)
2223

@@ -40,6 +41,7 @@ defmodule GitOps.Mix.Tasks.Test.ReleaseTest do
4041
Application.put_env(:git_ops, :changelog_file, changelog)
4142
Application.put_env(:git_ops, :manage_readme_version, true)
4243
Application.put_env(:git_ops, :types, custom: [header: "Custom"], docs: [hidden?: false])
44+
Application.put_env(:git_ops, :github_handle_lookup?, false)
4345

4446
on_exit(fn -> File.rm!(changelog) end)
4547

@@ -64,6 +66,7 @@ defmodule GitOps.Mix.Tasks.Test.ReleaseTest do
6466
Application.put_env(:git_ops, :manage_readme_version, true)
6567
Application.put_env(:git_ops, :types, custom: [header: "Custom"], docs: [hidden?: false])
6668
Application.put_env(:git_ops, :version_tag_prefix, "")
69+
Application.put_env(:git_ops, :github_handle_lookup?, false)
6770

6871
on_exit(fn -> File.rm!(changelog) end)
6972

0 commit comments

Comments
 (0)