gitbay/Repos/RepoSettings.swift
53 lines · 2163 bytes
1import Foundation
2
3/// `repo settings show` — admin-only view of the repo's control knobs.
4/// Every field is omitted at its zero value, so absent means default.
5nonisolated struct RepoSettings: Decodable, Sendable, Hashable {
6 let protectedBranches: [String]?
7 /// `path.Match` globs; a matching tag is created once and then
8 /// refuses moves and deletion (v1.16.0).
9 let protectedTags: [String]?
10 let requireSignedCommits: Bool?
11 let requireChecks: Bool?
12 /// The checks the checks gate waits on by name; with none, every
13 /// check reported on the head must pass (v1.37.0).
14 let requiredContexts: [String]?
15 let requireApprovals: Int?
16 let requireResolved: Bool?
17 let requireCodeowners: Bool?
18 /// Protected branches take changes through merge requests only (v1.16.0).
19 let requireMR: Bool?
20 let gitDaemon: Bool?
21 let archived: Bool?
22 let website: String?
23
24 enum CodingKeys: String, CodingKey {
25 case protectedBranches = "protected_branches"
26 case protectedTags = "protected_tags"
27 case requireMR = "require_mr"
28 case requireSignedCommits = "require_signed_commits"
29 case requireChecks = "require_checks"
30 case requiredContexts = "required_contexts"
31 case requireApprovals = "require_approvals"
32 case requireResolved = "require_resolved"
33 case requireCodeowners = "require_codeowners"
34 case gitDaemon = "git_daemon"
35 case archived, website
36 }
37
38 var branches: [String] { protectedBranches ?? [] }
39 var tags: [String] { protectedTags ?? [] }
40 var contexts: [String] { requiredContexts ?? [] }
41}
42
43/// One row of `repo access list`: an account and its effective role.
44/// Since v1.16.0 the row says where the access comes from — owner,
45/// direct, org admin, org member, or team; only a direct grant can be
46/// revoked here. An older server lists direct grants and says nothing.
47nonisolated struct AccessGrant: Decodable, Sendable, Hashable, Identifiable {
48 let user: String
49 let role: String
50 let source: String?
51 var id: String { user }
52 var isDirect: Bool { source == nil || source == "direct" }
53}