Skip to content

Commit fe16faf

Browse files
authored
Fix glacier command (#949)
* 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
1 parent 023b544 commit fe16faf

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/github.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,21 @@ impl GithubClient {
10561056
}
10571057
}
10581058

1059+
/// Get the raw gist content from the URL of the HTML version of the gist:
1060+
///
1061+
/// `html_url` looks like `https://gist.github.com/rust-play/7e80ca3b1ec7abe08f60c41aff91f060`.
1062+
///
1063+
/// `filename` is the name of the file you want the content of.
1064+
pub async fn raw_gist_from_url(
1065+
&self,
1066+
html_url: &str,
1067+
filename: &str,
1068+
) -> anyhow::Result<String> {
1069+
let url = html_url.replace("github.com", "githubusercontent.com") + "/raw/" + filename;
1070+
let response = self.raw().get(&url).send().await?;
1071+
response.text().await.context("raw gist from url")
1072+
}
1073+
10591074
fn get(&self, url: &str) -> RequestBuilder {
10601075
log::trace!("get {:?}", url);
10611076
self.client.get(url).configure(self)

src/handlers/glacier.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ pub(super) async fn handle_command(
2222
return Ok(());
2323
};
2424

25-
let response = ctx.github.raw().get(&cmd.source).send().await?;
26-
let body = response.text().await?;
25+
let body = ctx
26+
.github
27+
.raw_gist_from_url(&cmd.source, "playground.rs")
28+
.await?;
2729

2830
let number = event.issue().unwrap().number;
2931
let user = event.user();

0 commit comments

Comments
 (0)