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