Skip to main content

wire/answer/
github.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4// Copyright (c) 2026 2youg1 and the sprawling contributors
5
6//! A candidate user id read from the GitHub CLI on the machine that
7//! serves the city, as a page reads it (`crates/wire/spec/Answer/Github.lean` ยง8-67).
8
9use serde::{Deserialize, Serialize};
10
11/// What one import asked and what came back. Nothing was saved: the
12/// login is a candidate the identity card writes only when the person
13/// saves it, through `PutIdentity`.
14#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
15#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
16pub struct GithubLoginAnswer {
17    /// The host asked, which the page shows beside the candidate and the
18    /// card records as `imported_from` when it is saved.
19    pub host: String,
20    pub reading: GithubReading,
21}
22
23/// What the GitHub CLI said about one host, or the named reason it said
24/// nothing. Every reading but `Found` leaves the card as the person left
25/// it, and each names the way on that the page offers.
26#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
27#[serde(rename_all = "snake_case")]
28#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
29pub enum GithubReading {
30    /// The login the host's current authenticated identity has.
31    Found { login: String },
32    /// No `gh` on the search path of the machine serving the city.
33    NoCli,
34    /// `gh` is there and this host has nobody signed in.
35    NotLoggedIn,
36    /// Any other failure: the network, or `gh`'s own error. `exit` is
37    /// absent when there was no exit code to read: `gh` would not start,
38    /// or was stopped when it outran the wait.
39    Failed { exit: Option<i32> },
40    /// `gh` outran the wait and this city could not stop it: the process
41    /// is still running on the city's machine, and `why` is what went
42    /// wrong while stopping it.
43    Stuck { why: String },
44    /// The host asked for is not a host name, so `gh` was not started.
45    NotAHost,
46}