Skip to content

Commit

Permalink
Fix glacier command (#949)
Browse files Browse the repository at this point in the history
* Fix glacier command

It was fetching the HTML rather than the raw source;
see rust-lang/glacier#530 for an example.

* Refactor raw gist fetching into utility function

* Add docs
  • Loading branch information
camelid authored Nov 22, 2020
1 parent 023b544 commit fe16faf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,21 @@ impl GithubClient {
}
}

/// Get the raw gist content from the URL of the HTML version of the gist:
///
/// `html_url` looks like `https://gist.github.com/rust-play/7e80ca3b1ec7abe08f60c41aff91f060`.
///
/// `filename` is the name of the file you want the content of.
pub async fn raw_gist_from_url(
&self,
html_url: &str,
filename: &str,
) -> anyhow::Result<String> {
let url = html_url.replace("github.com", "githubusercontent.com") + "/raw/" + filename;
let response = self.raw().get(&url).send().await?;
response.text().await.context("raw gist from url")
}

fn get(&self, url: &str) -> RequestBuilder {
log::trace!("get {:?}", url);
self.client.get(url).configure(self)
Expand Down
6 changes: 4 additions & 2 deletions src/handlers/glacier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ pub(super) async fn handle_command(
return Ok(());
};

let response = ctx.github.raw().get(&cmd.source).send().await?;
let body = response.text().await?;
let body = ctx
.github
.raw_gist_from_url(&cmd.source, "playground.rs")
.await?;

let number = event.issue().unwrap().number;
let user = event.user();
Expand Down

0 comments on commit fe16faf

Please sign in to comment.