ForgejoKit/Sources/ForgejoKit/Models/Repository.swift
Stefan Hausotte 897a8ebedd feat: initial commit
Intitial commit for ForgejoKit, a native Swift library to interact with
the Frogejo API
2026-02-28 20:25:57 +01:00

229 lines
7.1 KiB
Swift

import Foundation
public struct Repository: Codable, Identifiable, Equatable, Hashable, Sendable {
public let id: Int
public let name: String
public let fullName: String
public let description: String?
public let empty: Bool?
public let `private`: Bool?
public let fork: Bool?
public let parent: ParentRepository?
public let mirror: Bool?
public let size: Int?
public let language: String?
public let languagesUrl: String?
public let htmlUrl: String?
public let sshUrl: String?
public let cloneUrl: String?
public let website: String?
public let starsCount: Int?
public let forksCount: Int?
public let watchersCount: Int?
public let openIssuesCount: Int?
public let openPrCounter: Int?
public let releaseCounter: Int?
public let defaultBranch: String?
public let archived: Bool?
public let createdAt: Date?
public let updatedAt: Date?
public let permissions: RepositoryPermissions?
public let hasIssues: Bool?
public let internalTracker: InternalTracker?
public let hasWiki: Bool?
public let hasPullRequests: Bool?
public let hasProjects: Bool?
public let hasReleases: Bool?
public let hasPackages: Bool?
public let hasActions: Bool?
public let template: Bool?
public let avatarUrl: String?
public init(
id: Int,
name: String,
fullName: String,
description: String? = nil,
empty: Bool? = nil,
private: Bool? = nil,
fork: Bool? = nil,
parent: ParentRepository? = nil,
mirror: Bool? = nil,
size: Int? = nil,
language: String? = nil,
languagesUrl: String? = nil,
htmlUrl: String? = nil,
sshUrl: String? = nil,
cloneUrl: String? = nil,
website: String? = nil,
starsCount: Int? = nil,
forksCount: Int? = nil,
watchersCount: Int? = nil,
openIssuesCount: Int? = nil,
openPrCounter: Int? = nil,
releaseCounter: Int? = nil,
defaultBranch: String? = nil,
archived: Bool? = nil,
createdAt: Date? = nil,
updatedAt: Date? = nil,
permissions: RepositoryPermissions? = nil,
hasIssues: Bool? = nil,
internalTracker: InternalTracker? = nil,
hasWiki: Bool? = nil,
hasPullRequests: Bool? = nil,
hasProjects: Bool? = nil,
hasReleases: Bool? = nil,
hasPackages: Bool? = nil,
hasActions: Bool? = nil,
template: Bool? = nil,
avatarUrl: String? = nil,
) {
self.id = id
self.name = name
self.fullName = fullName
self.description = description
self.empty = empty
self.private = `private`
self.fork = fork
self.parent = parent
self.mirror = mirror
self.size = size
self.language = language
self.languagesUrl = languagesUrl
self.htmlUrl = htmlUrl
self.sshUrl = sshUrl
self.cloneUrl = cloneUrl
self.website = website
self.starsCount = starsCount
self.forksCount = forksCount
self.watchersCount = watchersCount
self.openIssuesCount = openIssuesCount
self.openPrCounter = openPrCounter
self.releaseCounter = releaseCounter
self.defaultBranch = defaultBranch
self.archived = archived
self.createdAt = createdAt
self.updatedAt = updatedAt
self.permissions = permissions
self.hasIssues = hasIssues
self.internalTracker = internalTracker
self.hasWiki = hasWiki
self.hasPullRequests = hasPullRequests
self.hasProjects = hasProjects
self.hasReleases = hasReleases
self.hasPackages = hasPackages
self.hasActions = hasActions
self.template = template
self.avatarUrl = avatarUrl
}
public var owner: String {
String(fullName.split(separator: "/").first ?? "")
}
public var repoName: String {
name
}
enum CodingKeys: String, CodingKey {
case id
case name
case fullName = "full_name"
case description
case empty
case `private`
case fork
case parent
case mirror
case size
case language
case languagesUrl = "languages_url"
case htmlUrl = "html_url"
case sshUrl = "ssh_url"
case cloneUrl = "clone_url"
case website
case starsCount = "stars_count"
case forksCount = "forks_count"
case watchersCount = "watchers_count"
case openIssuesCount = "open_issues_count"
case openPrCounter = "open_pr_counter"
case releaseCounter = "release_counter"
case defaultBranch = "default_branch"
case archived
case createdAt = "created_at"
case updatedAt = "updated_at"
case permissions
case hasIssues = "has_issues"
case internalTracker = "internal_tracker"
case hasWiki = "has_wiki"
case hasPullRequests = "has_pull_requests"
case hasProjects = "has_projects"
case hasReleases = "has_releases"
case hasPackages = "has_packages"
case hasActions = "has_actions"
case template
case avatarUrl = "avatar_url"
}
public static func == (lhs: Repository, rhs: Repository) -> Bool {
lhs.id == rhs.id
}
public func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}
public struct RepositoryPermissions: Codable, Hashable, Sendable {
public let admin: Bool
public let push: Bool
public let pull: Bool
public init(admin: Bool, push: Bool, pull: Bool) {
self.admin = admin
self.push = push
self.pull = pull
}
}
public struct InternalTracker: Codable, Hashable, Sendable {
public let enableTimeTracker: Bool
public let allowOnlyContributorsToTrackTime: Bool
public let enableIssueDependencies: Bool
public init(enableTimeTracker: Bool, allowOnlyContributorsToTrackTime: Bool, enableIssueDependencies: Bool) {
self.enableTimeTracker = enableTimeTracker
self.allowOnlyContributorsToTrackTime = allowOnlyContributorsToTrackTime
self.enableIssueDependencies = enableIssueDependencies
}
enum CodingKeys: String, CodingKey {
case enableTimeTracker = "enable_time_tracker"
case allowOnlyContributorsToTrackTime = "allow_only_contributors_to_track_time"
case enableIssueDependencies = "enable_issue_dependencies"
}
}
public struct ParentRepository: Codable, Hashable, Sendable {
public let id: Int
public let name: String
public let fullName: String
public let description: String?
public let htmlUrl: String
public init(id: Int, name: String, fullName: String, description: String? = nil, htmlUrl: String) {
self.id = id
self.name = name
self.fullName = fullName
self.description = description
self.htmlUrl = htmlUrl
}
enum CodingKeys: String, CodingKey {
case id
case name
case fullName = "full_name"
case description
case htmlUrl = "html_url"
}
}