krz/hutch
an ios client for sourcehut
clone: git clone https://gitbay.org/krz/hutch.git
v2.9.0: Hutch/Models/RepositorySummary.swift · raw
1import Foundation
2
3/// Lightweight repository model matching the fields returned by the
4/// repositories list query. Avoids optionalizing all fields on the full
5/// `Repository` model.
6struct RepositorySummary: Codable, Sendable, Identifiable, Hashable {
7 let id: Int
8 /// GraphQL resource identifier used by `repository(rid:)` queries.
9 let rid: String
10 let service: SRHTService
11 let name: String
12 let description: String?
13 let visibility: Visibility
14 let updated: Date
15 let owner: Entity
16 let head: Reference?
17
18 enum CodingKeys: String, CodingKey {
19 case id, rid, service, name, description, visibility, updated, owner
20 case head = "HEAD"
21 }
22
23 init(
24 id: Int,
25 rid: String,
26 service: SRHTService,
27 name: String,
28 description: String?,
29 visibility: Visibility,
30 updated: Date,
31 owner: Entity,
32 head: Reference?
33 ) {
34 self.id = id
35 self.rid = rid
36 self.service = service
37 self.name = name
38 self.description = description
39 self.visibility = visibility
40 self.updated = updated
41 self.owner = owner
42 self.head = head
43 }
44
45 init(from decoder: any Decoder) throws {
46 let container = try decoder.container(keyedBy: CodingKeys.self)
47 self.id = try container.decode(Int.self, forKey: .id)
48 self.rid = try container.decode(String.self, forKey: .rid)
49 self.service = try container.decodeIfPresent(SRHTService.self, forKey: .service) ?? .git
50 self.name = try container.decode(String.self, forKey: .name)
51 self.description = try container.decodeIfPresent(String.self, forKey: .description)
52 self.visibility = try container.decode(Visibility.self, forKey: .visibility)
53 self.updated = try container.decode(Date.self, forKey: .updated)
54 self.owner = try container.decode(Entity.self, forKey: .owner)
55 self.head = try container.decodeIfPresent(Reference.self, forKey: .head)
56 }
57}