Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse Github Asset Based on Accessibility #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/backends/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ impl ReleaseAsset {
///
/// Errors:
/// * Missing required name & download-url keys
fn from_asset(asset: &serde_json::Value) -> Result<ReleaseAsset> {
let download_url = asset["url"]
fn from_asset(asset: &serde_json::Value, is_private: bool) -> Result<ReleaseAsset> {
let download_url_field = if is_private {
"url"
} else {
"browser_download_url"
};
let download_url = asset[&download_url_field]
.as_str()
.ok_or_else(|| format_err!(Error::Release, "Asset missing `url`"))?;
let name = asset["name"]
Expand All @@ -34,7 +39,7 @@ impl ReleaseAsset {
}

impl Release {
fn from_release(release: &serde_json::Value) -> Result<Release> {
fn from_release(release: &serde_json::Value, is_private: bool) -> Result<Release> {
let tag = release["tag_name"]
.as_str()
.ok_or_else(|| format_err!(Error::Release, "Release missing `tag_name`"))?;
Expand All @@ -48,7 +53,7 @@ impl Release {
let body = release["body"].as_str().map(String::from);
let assets = assets
.iter()
.map(ReleaseAsset::from_asset)
.map(|x| ReleaseAsset::from_asset(x, is_private))
.collect::<Result<Vec<ReleaseAsset>>>()?;
Ok(Release {
name: name.to_owned(),
Expand Down Expand Up @@ -193,7 +198,7 @@ impl ReleaseList {
.ok_or_else(|| format_err!(Error::Release, "No releases found"))?;
let mut releases = releases
.iter()
.map(Release::from_release)
.map(|x| Release::from_release(x, self.auth_token.is_some()))
.collect::<Result<Vec<Release>>>()?;

// handle paged responses containing `Link` header:
Expand Down Expand Up @@ -477,7 +482,7 @@ impl ReleaseUpdate for Update {
)
}
let json = resp.json::<serde_json::Value>()?;
Release::from_release(&json)
Release::from_release(&json, self.auth_token.is_some())
}

fn get_release_version(&self, ver: &str) -> Result<Release> {
Expand All @@ -504,7 +509,7 @@ impl ReleaseUpdate for Update {
)
}
let json = resp.json::<serde_json::Value>()?;
Release::from_release(&json)
Release::from_release(&json, self.auth_token.is_some())
}

fn current_version(&self) -> String {
Expand Down