GitHub

Struct GitHub 

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

Struct to communicate with the GitHub REST API.

Implementations§

Source§

impl GitHub

Source

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();
§Errors

This function fails if the headers cannot be constructed.

Source

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();
§Errors

This function fails if the headers cannot be constructed.

Source

pub fn query( &self, repository: &str, ) -> Result<Vec<GitHubReleaseItem>, LookupError>

Get all release versions from the repository.

Note that repository should be in the format “owner/repo”, like "celeo/github_release_check".

§Example
use github_release_check::GitHub;
let github = GitHub::new().unwrap();
let versions_result = github.get_all_versions("celeo/github_release_check");
§Errors

This function fails if the HTTP request cannot be sent, the API returns a status code indicating something other than a success (outside of the 2xx range), of if the returned data does not match the expected model.

Source

pub fn get_all_versions( &self, repository: &str, ) -> Result<Vec<String>, LookupError>

Get all release version strings from the repository.

Note that repository should be in the format “owner/repo”, like "celeo/github_release_check".

§Example
use github_release_check::GitHub;
let github = GitHub::new().unwrap();
let versions_result = github.get_all_versions("celeo/github_release_check");
§Errors

This function fails if the HTTP request cannot be sent, the API returns a status code indicating something other than a success (outside of the 2xx range), of if the returned data does not match the expected model.

Source

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 Strings).

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");
§Errors

This function fails for any of the reasons in get_all_versions, or if no versions are returned from the API.

Trait Implementations§

Source§

impl Debug for GitHub

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for GitHub

§

impl !RefUnwindSafe for GitHub

§

impl Send for GitHub

§

impl Sync for GitHub

§

impl Unpin for GitHub

§

impl !UnwindSafe for GitHub

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> 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> 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, 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
Source§

impl<T> ErasedDestructor for T
where T: 'static,