wtg_cli/notice.rs
1//! Notices emitted during backend/git operations.
2//!
3//! All notices are delivered via callback - the CLI layer decides how to display them.
4
5use std::sync::Arc;
6
7use crate::remote::{RemoteHost, RemoteInfo};
8
9/// Notices emitted during backend/git operations.
10/// All notices are delivered via callback - the CLI layer decides how to display them.
11#[derive(Debug, Clone)]
12#[non_exhaustive]
13pub enum Notice {
14 // --- Backend capability notices ---
15 /// No remotes configured at all
16 NoRemotes,
17 /// Single host type detected but it's not GitHub
18 UnsupportedHost {
19 /// The best remote we found (by priority: upstream > origin > other)
20 best_remote: RemoteInfo,
21 },
22 /// Multiple different hosts detected, none of them GitHub
23 MixedRemotes {
24 /// All the unique hosts we found
25 hosts: Vec<RemoteHost>,
26 /// Total remote count
27 count: usize,
28 },
29 /// GitHub remote found but API client couldn't be created
30 UnreachableGitHub {
31 /// The GitHub remote we found
32 remote: RemoteInfo,
33 },
34 /// Local git repo couldn't be opened, using pure API
35 ApiOnly,
36
37 // --- Operational notices ---
38 /// Failed to update a cached repository
39 CacheUpdateFailed { error: String },
40 /// Repository is shallow, falling back to API
41 ShallowRepoDetected,
42 /// Starting to clone a remote repository
43 CloningRepo { url: String },
44 /// Clone succeeded
45 CloneSucceeded { used_filter: bool },
46 /// Filter clone failed, falling back to bare clone
47 CloneFallbackToBare { error: String },
48 /// Starting to update a cached repository
49 UpdatingCache,
50 /// Cache update completed
51 CacheUpdated,
52 /// Cross-project reference falling back to API-only
53 CrossProjectFallbackToApi {
54 owner: String,
55 repo: String,
56 error: String,
57 },
58 /// GitHub API rate limit was hit
59 GhRateLimitHit {
60 /// Whether the client was authenticated or anonymous
61 authenticated: bool,
62 },
63 /// Anonymous fallback was attempted but failed with a non-rate-limit error
64 GhAnonymousFallbackFailed {
65 /// The error message from the failed anonymous request
66 error: String,
67 },
68 /// Cross-project PR commit fetch failed (e.g., due to rate limits or auth issues)
69 CrossProjectPrFetchFailed {
70 /// Owner of the cross-project repo
71 owner: String,
72 /// Repo name of the cross-project repo
73 repo: String,
74 /// PR number
75 pr_number: u64,
76 /// Error message
77 error: String,
78 },
79}
80
81/// Callback for emitting notices during operations.
82pub type NoticeCallback = Arc<dyn Fn(Notice) + Send + Sync>;
83
84/// Create a no-op callback for when notices should be ignored.
85#[must_use]
86pub fn no_notices() -> NoticeCallback {
87 Arc::new(|_| {})
88}