krz/hutch
an ios client for sourcehut
clone: git clone https://gitbay.org/krz/hutch.git
v3.0.4: Hutch/Models/CommitDetail.swift · raw
1import Foundation
2
3/// Full commit detail returned by the revparse_single query.
4struct CommitDetail: Codable, Sendable, Identifiable {
5 let id: String
6 let shortId: String
7 let author: CommitAuthor
8 let committer: CommitAuthor
9 let message: String
10 let diff: String?
11 let trailers: [CommitTrailer]
12 let parents: [ParentCommit]
13 let tree: CommitTree?
14
15 /// First line of the commit message.
16 var title: String {
17 message.prefix(while: { $0 != "\n" }).trimmingCharacters(in: .whitespaces)
18 }
19
20 /// The commit message body (everything after the first line), if any.
21 var body: String? {
22 guard let newlineIndex = message.firstIndex(of: "\n") else { return nil }
23 let body = message[message.index(after: newlineIndex)...]
24 .trimmingCharacters(in: .whitespacesAndNewlines)
25 return body.isEmpty ? nil : body
26 }
27}
28
29struct CommitTrailer: Codable, Sendable, Identifiable {
30 var id: String { "\(name):\(value)" }
31 let name: String
32 let value: String
33}
34
35struct ParentCommit: Codable, Sendable, Identifiable, Hashable {
36 let id: String
37 let shortId: String
38 let author: ParentAuthor
39}
40
41struct ParentAuthor: Codable, Sendable, Hashable {
42 let name: String
43}
44
45struct CommitTree: Codable, Sendable {
46 let entries: CommitTreeEntries
47}
48
49struct CommitTreeEntries: Codable, Sendable {
50 let results: [CommitTreeEntry]
51 let cursor: String?
52}
53
54struct CommitTreeEntry: Codable, Sendable, Identifiable {
55 let id: String
56 let name: String
57 let mode: Int
58 let object: CommitTreeObject?
59}
60
61struct CommitTreeObject: Codable, Sendable {
62 let type: String?
63 let id: String?
64 let shortId: String?
65}