pub struct GitHub { /* private fields */ }Expand description
Struct to communicate with the GitHub REST API.
Implementations§
Source§impl 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();§Errors
This function fails if the headers cannot be constructed.
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();§Errors
This function fails if the headers cannot be constructed.
Sourcepub fn query(
&self,
repository: &str,
) -> Result<Vec<GitHubReleaseItem>, LookupError>
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.
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 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.
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 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.