import Foundation struct Branch: Codable, Hashable { let label: String? let ref: String? let sha: String? } struct PRLabel: Codable, Hashable, Identifiable { let id: Int64? let name: String let color: String? } struct PRUser: Codable, Hashable { let id: Int64? let login: String let fullName: String? } /// A pull request as returned by `/repos/{owner}/{repo}/pulls` and /// `/issues/{index}`. struct PullRequest: Codable, Hashable, Identifiable { let id: Int64 let number: Int let title: String let body: String? let state: String // open | closed | merged let htmlURL: String? let diffURL: String? let patchURL: String? let user: PRUser? let assignees: [PRUser]? let labels: [PRLabel]? let head: Branch? let base: Branch? let createdAt: Date? let updatedAt: Date? let merged: Bool? let mergeable: Bool? let draft: Bool? enum CodingKeys: String, CodingKey { case id, number, title, body, state, user, assignees, labels case htmlURL = "html_url" case diffURL = "diff_url" case patchURL = "patch_url" case head, base case createdAt = "created_at" case updatedAt = "updated_at" case merged, mergeable, draft } } /// A single review submission (approve / request changes / comment). struct PullReview: Codable, Identifiable { let id: Int64 let state: String // APPROVED | REQUEST_CHANGES | COMMENT | PENDING let body: String? let user: PRUser? let submittedAt: Date? enum CodingKeys: String, CodingKey { case id, state, body, user case submittedAt = "submitted_at" } } /// An issue/PR comment. struct IssueComment: Codable, Identifiable { let id: Int64 let body: String? let user: PRUser? let createdAt: Date? let updatedAt: Date? enum CodingKeys: String, CodingKey { case id, body, user case createdAt = "created_at" case updatedAt = "updated_at" } } /// A commit in a pull request. struct PRCommit: Codable, Hashable, Identifiable { struct Meta: Codable, Hashable { let sha: String? let message: String? } struct Author: Codable, Hashable { let name: String? let email: String? let login: String? } let sha: String? let commit: Meta? let author: Author? /// Gitea's PR commits have no `id` field — only `sha`. Use sha as the /// identity so the array decodes and SwiftUI can key rows on it. var id: String { sha ?? commit?.sha ?? "\(author?.name ?? "")-\(commit?.message?.hashValue ?? 0)" } enum CodingKeys: String, CodingKey { case sha, commit, author } }