oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1#if DEBUG
2import SwiftUI
3
4/// In-memory fixture through the real session and device wire decoder.
5public enum NeedsViewFixture {
6 @MainActor public static func makeModel() -> EquipoAppModel {
7 let transport = NeedsFixtureTransport()
8 let store = MemorySecretStore()
9 let accounts = DeviceAccounts(store: store)
10 var account = DeviceAccount.new(origin: transport.origin, label: "Fixture")
11 account.credential = DeviceCredential(id: "fixture", token: "fixture", audience: "equipo.person.v1", instanceId: "fixture", expiresAt: .distantFuture)
12 account.teamName = "Oficina"; account.address = "paul@example.com"
13 try! accounts.commit(.save(account), lifetime: accounts.lifetimes.current)
14 let model = EquipoAppModel(store: store, makeTransport: { _ in transport })
15 model.destination = Destination(pane: .needs)
16 return model
17 }
18}
19
20#if os(iOS)
21public struct PhoneNeedsFixture: View {
22 @State private var model = NeedsViewFixture.makeModel()
23 public init() {}
24 public var body: some View {
25 if let session = model.session {
26 PhoneTabs(model: model, session: session)
27 .tint(Palette.accent)
28 .preferredColorScheme(.light)
29 .task { await session.refresh() }
30 }
31 }
32}
33#endif
34
35private struct NeedsFixtureTransport: EquipoTransport {
36 let origin = URL(string: "https://fixture.invalid")!
37 private var scenario: String { ProcessInfo.processInfo.environment["EQUIPO_NEEDS_FIXTURE"] ?? "list" }
38 private var needs: [[String: Any]] { scenario == "empty" || scenario.hasPrefix("today") ? [] : [retry, merge, question] }
39 private var tasks: [[String: Any]] { scenario == "empty" ? [] : needs + [running, finished] }
40 func send(_ request: APIRequest) async throws -> APIResponse {
41 let value: [String: Any]
42 switch request.path {
43 case "/snapshot":
44 value = ["me": ["id": "fixture", "address": "paul@example.com", "role": "owner", "team_id": "fixture", "team_name": "Oficina", "revision": 1], "cursor": 1, "tasks": tasks, "messages": [], "turns": [], "cards": scenario == "empty" ? [] : cards, "projects": []]
45 case "/tasks": value = ["items": tasks]
46 case "/needs-you": value = ["items": needs]
47 default:
48 value = tasks.first { request.path == "/tasks/" + ($0["id"] as! String) } ?? [:]
49 }
50 return APIResponse(status: 200, data: try JSONSerialization.data(withJSONObject: value))
51 }
52 func lines(_ request: APIRequest) async throws -> AsyncThrowingStream<String, Error> { AsyncThrowingStream { $0.finish() } }
53
54 private var at: String {
55 ISO8601DateFormatter().string(from: Calendar.current.startOfDay(for: Date()).addingTimeInterval(20 * 60))
56 }
57 private func task(_ id: String, _ title: String, stage: String, need: String = "", steps: [[String: Any]] = []) -> [String: Any] {
58 ["id": id, "revision": 1, "project_id": "project", "project": "Equipo", "repo": "oficina/equipo", "title": title, "brief": title, "stage": stage, "needs_you": need, "creator": "paul@example.com", "branch": "equipo/" + id, "url": "", "candidate_sha": "3f9c2a167de8", "checks": "", "checks_reason": "", "verdict": "", "review_label": "", "created_at": at, "updated_at": at, "steps": steps]
59 }
60 private func step(_ id: String, specialist: String = "engineering", state: String = "done", reason: String = "", headline: String = "") -> [String: Any] {
61 ["id": id, "specialist": specialist, "state": state, "reason": reason, "headline": headline, "summary": "", "verdict": "", "review_label": "", "checks": "", "gate": "", "terminated": true, "started_at": at, "finished_at": at]
62 }
63 private var retry: [String: Any] {
64 task("retry", "Clear the badge after sign-out", stage: "in_progress", need: "retry", steps: [step("failed", state: "failed", reason: "push_failed")])
65 }
66 private var merge: [String: Any] {
67 var task = task("merge", "Keep the sign-in button visible", stage: "ready_to_merge", need: "merge")
68 task["checks"] = "passed"; task["verdict"] = "approve"; task["review_label"] = "other_family"
69 var review = step("approved", specialist: "review", headline: "Keep the sign-in button visible")
70 review["candidate_sha"] = task["candidate_sha"]; review["verdict"] = "approve"; review["review_label"] = "other_family"
71 task["steps"] = [review]
72 return task
73 }
74 private var question: [String: Any] {
75 task("question", "Name the team in sign-in emails", stage: "in_review", need: "fix_rounds", steps: [step("review", specialist: "review", headline: "The subject still needs a decision")])
76 }
77 private var running: [String: Any] {
78 task("running", "Keep the task list up to date", stage: "in_progress", steps: [step("live", state: "running", headline: "Updating the list after a task finishes")])
79 }
80 private var finished: [String: Any] {
81 var task = task("finished", "Explain why the upload stopped", stage: "done", steps: [step("merged", specialist: "merge", headline: "Merged into main")])
82 task["done_at"] = at
83 task["undo_offered"] = scenario != "today-no-undo"
84 task["merged"] = ["into": "main", "sha": "3f9c2a167de8", "without_checks": true, "at": at]
85 return task
86 }
87 private var cards: [[String: Any]] {
88 [card("merge-card", task: "merge", kind: "merge", question: "Merge this fix?", options: ["merge", "not_now"]),
89 card("question-card", task: "question", kind: "question", question: "Should the subject name the team?", options: ["Yes, name the team", "Keep it short"]),
90 card("receipt", task: "finished", kind: "merge_receipt", question: "Merged", options: ["undo"])]
91 }
92 private func card(_ id: String, task: String, kind: String, question: String, options: [String]) -> [String: Any] {
93 ["aside": scenario == "aside" && kind == "merge", "id": id, "revision": 1, "kind": kind, "state": "open", "turn_id": "", "project_id": "project", "name": "", "question": question, "options": options, "choice": "", "task_id": task, "created_at": at, "updated_at": at]
94 }
95}
96#endif
97