Files
ios-gitea-prs/GiteaPR/Models/PullRequest.swift
T
Hermes 9f3fb95cbe
Build iOS App / Build .ipa and publish source (push) Successful in 21s
Fix commits tab + add CI job logs; bump to 1.7
Commits tab was empty: Gitea PR commits have no 'id' field (only sha), but
PRCommit.id was a non-optional let decoded from 'id', so decoding [PRCommit]
always threw and the tab silently showed nothing. Make PRCommit.id a computed
sha-based identity so the array decodes and renders.

CI: add a Logs button per job that fetches the job's raw log text
(/actions/jobs/{id}/logs) into a viewable, shareable screen. Bump to 1.7.
2026-08-12 21:55:24 +00:00

106 lines
2.7 KiB
Swift

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
}
}