Commit c88e4da270

c88e4da270a522888e0d7215d47b9ed21f138836

parent: 53ba11d5e1

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-14 06:03 UTC

Summarize changes: keep what is typed while the lines load

The lines are appended to the notes as they are when the read returns,
not as they were when it started.

Ref #26

Layout: unified · split

gitbay/Releases/ReleaseViewModels.swift +14 −8
@@ -43,9 +43,10 @@ final class ReleaseListViewModel {
4343 }
4444
4545 /// `release notes <owner/name> <tag>`: one line per merge request
46 /// landed since the previous release, appended to `notes` the way the
47 /// web's Summarize changes appends them. The lines are the CLI's.
48 func summarize(tag: String, into notes: String) async -> String {
46 /// landed since the previous release, in the CLI's form. nil when
47 /// there are none or the server refused, with `summaryNote` saying
48 /// which.
49 func summary(tag: String) async -> String? {
4950 summaryNote = nil
5051 working = true
5152 defer { working = false }
@@ -55,17 +56,22 @@ final class ReleaseListViewModel {
5556 summaryNote = summary.since.isEmpty
5657 ? "No merge requests landed on \(tag)."
5758 : "No merge requests landed since \(summary.since)."
58 return notes
59 return nil
5960 }
60 let lines = summary.items.map { "- \($0.title) (!\($0.number)) by @\($0.author)\n" }.joined()
61 let typed = notes.trimmingCharacters(in: .whitespacesAndNewlines)
62 return typed.isEmpty ? lines : typed + "\n\n" + lines
61 return summary.items.map { "- \($0.title) (!\($0.number)) by @\($0.author)\n" }.joined()
6362 } catch let error as GitbayError {
6463 summaryNote = error.userFacingMessage
6564 } catch {
6665 summaryNote = GitbayError.transport(error).userFacingMessage
6766 }
68 return notes
67 return nil
68 }
69
70 /// The notes with `lines` after them, as the web's Summarize changes
71 /// appends them.
72 nonisolated static func appending(_ lines: String, to notes: String) -> String {
73 let typed = notes.trimmingCharacters(in: .whitespacesAndNewlines)
74 return typed.isEmpty ? lines : typed + "\n\n" + lines
6975 }
7076
7177 /// `release create <owner/name> <tag> [--title <t>] [--file -]` —
gitbay/Views/Releases/ReleaseListView.swift +5 −2
@@ -111,8 +111,11 @@ private struct ReleaseCreateSheet: View {
111111 .autocorrectionDisabled()
112112 Button("Summarize changes") {
113113 Task {
114 notes = await model.summarize(
115 tag: tag.trimmingCharacters(in: .whitespaces), into: notes)
114 // Appended to the notes as they are when the lines
115 // arrive, so typing meanwhile is kept.
116 if let lines = await model.summary(tag: tag.trimmingCharacters(in: .whitespaces)) {
117 notes = ReleaseListViewModel.appending(lines, to: notes)
118 }
116119 }
117120 }
118121 .disabled(tag.trimmingCharacters(in: .whitespaces).isEmpty || model.working)
gitbayTests/ReleaseTests.swift +9 −11
@@ -173,7 +173,7 @@ struct FeedReleaseDestinationTests {
173173@MainActor
174174struct ReleaseSummaryTests {
175175
176 @Test func summarizingAppendsOneLinePerMergeRequestAfterWhatWasTyped() async throws {
176 @Test func theSummaryIsOneLinePerMergeRequestAppendedAfterWhatWasTyped() async throws {
177177 let (client, stub) = try makeClient()
178178 stub.enqueue(.init(status: 200, json: """
179179 {"protocol_version":1,"data":{"since":"v1.0.0","items":[\
@@ -182,32 +182,30 @@ struct ReleaseSummaryTests {
182182 """))
183183 let model = ReleaseListViewModel(client: client, repoPath: "krz/gitbay")
184184
185 let notes = await model.summarize(tag: "v1.1.0", into: "Second cut.")
185 let lines = try #require(await model.summary(tag: "v1.1.0"))
186186
187 #expect(notes == "Second cut.\n\n- Add a thing (!12) by @cmc\n- Fix it (!14) by @dee\n")
187 #expect(ReleaseListViewModel.appending(lines, to: "Second cut.\n")
188 == "Second cut.\n\n- Add a thing (!12) by @cmc\n- Fix it (!14) by @dee\n")
189 #expect(ReleaseListViewModel.appending(lines, to: " ") == lines)
188190 #expect(stub.seen.first?.url.query() == "argv=release&argv=notes&argv=krz/gitbay&argv=v1.1.0")
189191 #expect(model.summaryNote == nil)
190192 }
191193
192 @Test func anEmptyRangeLeavesTheNotesAndSaysWhy() async throws {
194 @Test func anEmptyRangeGivesNoLinesAndSaysWhy() async throws {
193195 let (client, stub) = try makeClient()
194196 stub.enqueue(.init(status: 200, json: #"{"protocol_version":1,"data":{"since":"v1.0.0","items":[]},"exit_code":0}"#))
195197 let model = ReleaseListViewModel(client: client, repoPath: "krz/gitbay")
196198
197 let notes = await model.summarize(tag: "v1.1.0", into: "typed")
198
199 #expect(notes == "typed")
199 #expect(await model.summary(tag: "v1.1.0") == nil)
200200 #expect(model.summaryNote == "No merge requests landed since v1.0.0.")
201201 }
202202
203 @Test func aRefusalLeavesTheNotesAndShowsIt() async throws {
203 @Test func aRefusalGivesNoLinesAndShowsIt() async throws {
204204 let (client, stub) = try makeClient()
205205 stub.enqueue(.init(status: 404, json: #"{"protocol_version":1,"error":"no ref \"v9\" in krz/gitbay","exit_code":3}"#))
206206 let model = ReleaseListViewModel(client: client, repoPath: "krz/gitbay")
207207
208 let notes = await model.summarize(tag: "v9", into: "")
209
210 #expect(notes == "")
208 #expect(await model.summary(tag: "v9") == nil)
211209 #expect(model.summaryNote == #"no ref "v9" in krz/gitbay"#)
212210 }
213211}