Struct github_release_check::GitHub
source · [−]pub struct GitHub { /* private fields */ }
Expand description
Struct to communicate with the GitHub REST API.
Implementations
sourceimpl GitHub
impl GitHub
sourcepub fn new() -> Result<Self, LookupError>
pub fn new() -> Result<Self, LookupError>
Create a new instance of the struct suitable for public GitHub.
The struct created by this function does not set an access token and as such can only get information on public GitHub repositories.
If you need to access information for private repositories or any
information from a custom GitHub enterprise instance, use the
from_custom
function.
This function may return an Error
if the HTTP client could
not be constructed or headers initialized. It should be safe
to unwrap the Result
.
Example
use github_release_check::GitHub;
let github = GitHub::new().unwrap();
sourcepub fn from_custom(
api_endpoint: &str,
access_token: &str
) -> Result<Self, LookupError>
pub fn from_custom(
api_endpoint: &str,
access_token: &str
) -> Result<Self, LookupError>
Create a new instance of the struct suitable for accessing any GitHub repository that can be viewed with the access key on the GitHub instance.
This function has to be used to construct the struct instance whenever the repository that you want to get information from is on a custom GitHub enterprise instance and/or is private. The access token passed to this function should be a GitHub personal access token that has the access to view the repository on that GitHub instance.
For the api_endpoint
argument, pass in the REST API root of the GitHub instance. For public
GitHub, this can be found in DEFAULT_API_ROOT
.
Your GitHub enterprise may use a subdomain like "https://api.github.your_domain_root.com/"
, or
perhaps something like "https://github.your_domain_root.com/api/v3/"
. Specify the API root that
you can otherwise send requests to. Note that this URL should end in a trailing slash.
Example
use github_release_check::GitHub;
let github = GitHub::from_custom("https://github.example.com/api/v3/", "abcdef").unwrap();
sourcepub fn get_all_versions(
&self,
repository: &str
) -> Result<Vec<String>, LookupError>
pub fn get_all_versions(
&self,
repository: &str
) -> Result<Vec<String>, LookupError>
Get all release versions from the repository.
Just like get_latest_version
but instead returns
all the versions in case you need them.
Actually called by get_latest_version
under the hood.
Example
use github_release_check::GitHub;
let github = GitHub::new().unwrap();
let versions_result = github.get_all_versions("celeo/github_release_check");
sourcepub fn get_latest_version(
&self,
repository: &str
) -> Result<Version, LookupError>
pub fn get_latest_version(
&self,
repository: &str
) -> Result<Version, LookupError>
Get the latest release version from the repository.
Note that repository
should be in the format “owner/repo”,
like "celeo/github_release_check"
.
As this function needs to select and return the latest release version,
it makes use of the “semver” crate’s Version
parse function. As there’s
no requirement for repositories to use Semantic Versioning, this function may
not suitable for every repository (thus the get_all_versions
function which
just works with String
s).
A leading 'v'
character is stripped from the versions
in order to make more repositories work. For any version string that is not
able to be loaded into a Version
struct, it is skipped. Note that this
may result in no or missing versions.
Effectively, for repositories that are using Semantic Versioning correctly, this will work. For those that are not, it’s a bit of a toss-up.
Since this call can fail for a number of reasons including anything related to
the network at the time of the call, the Result
from this function should
be handled appropriately.
Example
use github_release_check::GitHub;
let github = GitHub::new().unwrap();
let version_result = github.get_latest_version("celeo/github_release_check");
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for GitHub
impl Send for GitHub
impl Sync for GitHub
impl Unpin for GitHub
impl !UnwindSafe for GitHub
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more