From 32ad6cab8d58d99ebd8a28e8fa6e6f4e587cb1e5 Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Tue, 17 Mar 2026 23:19:43 -0500 Subject: v1.0 --- Hutch/Models/CommitDetail.swift | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Hutch/Models/CommitDetail.swift (limited to 'Hutch/Models/CommitDetail.swift') diff --git a/Hutch/Models/CommitDetail.swift b/Hutch/Models/CommitDetail.swift new file mode 100644 index 0000000..c95199d --- /dev/null +++ b/Hutch/Models/CommitDetail.swift @@ -0,0 +1,65 @@ +import Foundation + +/// Full commit detail returned by the revparse_single query. +struct CommitDetail: Codable, Sendable, Identifiable { + let id: String + let shortId: String + let author: CommitAuthor + let committer: CommitAuthor + let message: String + let diff: String? + let trailers: [CommitTrailer] + let parents: [ParentCommit] + let tree: CommitTree? + + /// First line of the commit message. + var title: String { + message.prefix(while: { $0 != "\n" }).trimmingCharacters(in: .whitespaces) + } + + /// The commit message body (everything after the first line), if any. + var body: String? { + guard let newlineIndex = message.firstIndex(of: "\n") else { return nil } + let body = message[message.index(after: newlineIndex)...] + .trimmingCharacters(in: .whitespacesAndNewlines) + return body.isEmpty ? nil : body + } +} + +struct CommitTrailer: Codable, Sendable, Identifiable { + var id: String { "\(name):\(value)" } + let name: String + let value: String +} + +struct ParentCommit: Codable, Sendable, Identifiable, Hashable { + let id: String + let shortId: String + let author: ParentAuthor +} + +struct ParentAuthor: Codable, Sendable, Hashable { + let name: String +} + +struct CommitTree: Codable, Sendable { + let entries: CommitTreeEntries +} + +struct CommitTreeEntries: Codable, Sendable { + let results: [CommitTreeEntry] + let cursor: String? +} + +struct CommitTreeEntry: Codable, Sendable, Identifiable { + let id: String + let name: String + let mode: Int + let object: CommitTreeObject? +} + +struct CommitTreeObject: Codable, Sendable { + let type: String? + let id: String? + let shortId: String? +} -- cgit v1.2.3