Skip to main content

GitHubHost

Struct GitHubHost 

Source
pub struct GitHubHost { /* private fields */ }
Expand description

The GitHub host an operation targets: SaaS github.com or a GitHub Enterprise Server (GHES) host. gh picks the credential environment variable it reads per hostGH_TOKEN for github.com, GH_ENTERPRISE_TOKEN for a GHES host — and its auth status can be scoped to a single host, so this type carries that host so the client (1) injects a supplied credential into the variable gh actually reads for it (see GitHub::with_host) and (2) can probe auth for exactly that host (see GitHubApi::auth_status_for).

Build it for github.com (github_com), from a bare hostname (new), or from a repository’s remote URL (from_remote_url). A hostname that cannot be determined is an error, never a silent fall back to github.com — so an ambiguous or unknown host is a diagnosable result at the call site rather than a quiet authentication against the wrong host with the github.com token.

let saas = GitHubHost::github_com();
assert!(saas.is_github_com() && !saas.is_enterprise());

let ghes = GitHubHost::new("ghe.example.com").unwrap();
assert!(ghes.is_enterprise());
assert_eq!(ghes.as_str(), "ghe.example.com");

// github.com (any case) classifies as SaaS; every other valid host is GHES.
assert!(GitHubHost::new("GitHub.com").unwrap().is_github_com());
// An unparseable / hostless remote is an error, not a github.com guess.
assert!(GitHubHost::from_remote_url("not-a-url").is_err());

Implementations§

Source§

impl GitHubHost

Source

pub const SAAS_HOST: &'static str = "github.com"

The SaaS GitHub hostname (github.com).

Source

pub fn github_com() -> Self

The SaaS github.com host — a supplied credential is injected as GH_TOKEN.

Source

pub fn new(host: impl AsRef<str>) -> Result<Self>

Classify a bare host: github.com (case-insensitive) is SaaS; any other valid hostname is treated as a GitHub Enterprise Server host (its credential goes to GH_ENTERPRISE_TOKEN). Returns an error for an empty, flag-like, or otherwise malformed hostname (a scheme, path, port, userinfo, or whitespace) rather than guessing — the value must be a bare DNS-style host.

Source

pub fn from_remote_url(url: &str) -> Result<Self>

Derive the host from a repository remote URL and classify it. Handles scheme://[user@]host[:port]/… (HTTPS/SSH/…) and the scp-like [user@]host:path SSH form; any userinfo and port are dropped. A remote whose host can’t be determined (unparseable, hostless, or ambiguous — an IPv6 literal, a bare single-label scp authority, a local path) is an error, not a silent github.com fallback, so the caller can surface an ambiguous remote as a diagnosable result.

Source

pub fn as_str(&self) -> &str

The canonical hostname (github.com, ghe.example.com).

Source

pub fn is_enterprise(&self) -> bool

Whether this is a GitHub Enterprise Server host (anything but github.com).

Source

pub fn is_github_com(&self) -> bool

Whether this is SaaS github.com.

Trait Implementations§

Source§

impl Clone for GitHubHost

Source§

fn clone(&self) -> GitHubHost

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GitHubHost

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for GitHubHost

Source§

impl PartialEq for GitHubHost

Source§

fn eq(&self, other: &GitHubHost) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for GitHubHost

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Any for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Source§

fn type_name(&self) -> &'static str

Source§

impl<T> AnySync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more