pub struct GitHubAuthProvider<R: CommandRunner = RealCommandRunner, E: EnvSource = RealEnv> { /* private fields */ }Expand description
GitHub 认证提供者,通过 gh CLI 操作认证。
命令执行通过 CommandRunner 抽象,生产环境默认使用
RealCommandRunner,测试可注入自定义 runner 以模拟成功或失败场景。
环境变量读取通过 EnvSource 参数抽象,生产环境默认使用 RealEnv,
测试可通过 with_runner_and_env 注入自定义实现。
§Examples
use gitflow_github::GitHubAuthProvider;
let provider = GitHubAuthProvider::new();Implementations§
Source§impl GitHubAuthProvider<RealCommandRunner, RealEnv>
impl GitHubAuthProvider<RealCommandRunner, RealEnv>
Sourcepub fn with_session(_session: &Session) -> Self
pub fn with_session(_session: &Session) -> Self
Create a new provider from a shared [Session].
This enables state reuse across multiple operations in workflow chains.
Note: AuthProvider doesn’t use repo, so session.repo is ignored.
Source§impl<R: CommandRunner> GitHubAuthProvider<R, RealEnv>
impl<R: CommandRunner> GitHubAuthProvider<R, RealEnv>
Sourcepub fn with_runner(runner: R) -> Self
pub fn with_runner(runner: R) -> Self
使用自定义 CommandRunner 创建提供者,环境变量仍取自进程环境。
主要用于测试,可注入模拟 runner 以控制 gh CLI 的输出。
Source§impl<R: CommandRunner, E: EnvSource> GitHubAuthProvider<R, E>
impl<R: CommandRunner, E: EnvSource> GitHubAuthProvider<R, E>
Sourcepub fn with_runner_and_env(runner: R, env: E) -> Self
pub fn with_runner_and_env(runner: R, env: E) -> Self
同时注入自定义 CommandRunner 与 EnvSource。
测试应优先使用本构造函数:注入的环境变量来源使测试不依赖进程环境。
Trait Implementations§
Source§impl<R: CommandRunner, E: EnvSource> AuthChecker for GitHubAuthProvider<R, E>
impl<R: CommandRunner, E: EnvSource> AuthChecker for GitHubAuthProvider<R, E>
Source§fn is_authenticated(&self) -> bool
fn is_authenticated(&self) -> bool
Source§fn check_status(&self) -> AuthCheckResult
fn check_status(&self) -> AuthCheckResult
Source§impl<R: CommandRunner + 'static, E: EnvSource + 'static> AuthProvider for GitHubAuthProvider<R, E>
impl<R: CommandRunner + 'static, E: EnvSource + 'static> AuthProvider for GitHubAuthProvider<R, E>
Source§fn login<'life0, 'life1, 'async_trait>(
&'life0 self,
token: Option<&'life1 str>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn login<'life0, 'life1, 'async_trait>(
&'life0 self,
token: Option<&'life1 str>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
执行交互式登录。
调用 gh auth login,将子进程的 stdout/stderr 透传给终端。
如果提供了 token,则通过 --with-token 参数进行非交互式登录,
并将 token 写入子进程的标准输入,避免其出现在进程参数中。
§Errors
当认证失败或 gh 调用失败时返回错误。
Source§fn logout<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn logout<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn status<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<AuthStatus>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn status<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<AuthStatus>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
查询当前认证状态。
调用 gh auth status 并解析输出来构造 AuthStatus。
当 gh 命令执行失败或用户未登录时,返回 AuthStatus { logged_in: false }
而非传播错误。
§Errors
仅在 gh 返回非零退出码且无法识别为“未登录“模式时返回错误。
Source§impl<R: Clone + CommandRunner, E: Clone + EnvSource> Clone for GitHubAuthProvider<R, E>
impl<R: Clone + CommandRunner, E: Clone + EnvSource> Clone for GitHubAuthProvider<R, E>
Source§impl<R: Debug + CommandRunner, E: Debug + EnvSource> Debug for GitHubAuthProvider<R, E>
impl<R: Debug + CommandRunner, E: Debug + EnvSource> Debug for GitHubAuthProvider<R, E>
Source§impl Default for GitHubAuthProvider<RealCommandRunner, RealEnv>
impl Default for GitHubAuthProvider<RealCommandRunner, RealEnv>
Auto Trait Implementations§
impl<R, E> Forget for GitHubAuthProvider<R, E>
impl<R, E> Freeze for GitHubAuthProvider<R, E>
impl<R, E> Move for GitHubAuthProvider<R, E>
impl<R, E> RefUnwindSafe for GitHubAuthProvider<R, E>where
R: RefUnwindSafe,
E: RefUnwindSafe,
impl<R, E> Send for GitHubAuthProvider<R, E>
impl<R, E> Sync for GitHubAuthProvider<R, E>
impl<R, E> Unpin for GitHubAuthProvider<R, E>
impl<R, E> UnsafeUnpin for GitHubAuthProvider<R, E>where
R: UnsafeUnpin,
E: UnsafeUnpin,
impl<R, E> UnwindSafe for GitHubAuthProvider<R, E>where
R: UnwindSafe,
E: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more