diff --git a/Cargo.lock b/Cargo.lock index fdbd9a9e0e..87f720fa7e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2073,6 +2073,35 @@ dependencies = [ "const_soft_float", ] +[[package]] +name = "cookie" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ddef33a339a91ea89fb53151bd0a4689cfce27055c291dfa69945475d22c747" +dependencies = [ + "percent-encoding", + "time", + "version_check", +] + +[[package]] +name = "cookie_store" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fc4bff745c9b4c7fb1e97b25d13153da2bc7796260141df62378998d070207f" +dependencies = [ + "cookie", + "document-features", + "idna", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "time", + "url", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -3113,7 +3142,7 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", + "http 0.2.12", "indexmap", "slab", "tokio", @@ -3238,6 +3267,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http-body" version = "0.4.6" @@ -3245,7 +3285,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", - "http", + "http 0.2.12", "pin-project-lite", ] @@ -3272,7 +3312,7 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http", + "http 0.2.12", "http-body", "httparse", "httpdate", @@ -4928,7 +4968,7 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http", + "http 0.2.12", "http-body", "hyper", "hyper-tls", @@ -5662,10 +5702,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91e7d9e3bb61134e77bde20dd4825b97c010155709965fedf0f49bb138e52a9d" dependencies = [ "deranged", + "itoa", "num-conv", "powerfmt", "serde", "time-core", + "time-macros", ] [[package]] @@ -6027,20 +6069,34 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "ureq" -version = "2.12.1" +version = "3.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d" +checksum = "d39cb1dbab692d82a977c0392ffac19e188bd9186a9f32806f0aaa859d75585a" dependencies = [ "base64 0.22.1", + "cookie_store", "flate2", "log", - "once_cell", + "percent-encoding", "rustls", "rustls-pki-types", "serde", "serde_json", - "url", - "webpki-roots 0.26.11", + "ureq-proto", + "utf-8", + "webpki-roots", +] + +[[package]] +name = "ureq-proto" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b4531c118335662134346048ddb0e54cc86bd7e81866757873055f0e38f5d2" +dependencies = [ + "base64 0.22.1", + "http 1.3.1", + "httparse", + "log", ] [[package]] @@ -6055,6 +6111,12 @@ dependencies = [ "serde", ] +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + [[package]] name = "utf8_iter" version = "1.0.4" @@ -6357,15 +6419,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webpki-roots" -version = "0.26.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" -dependencies = [ - "webpki-roots 1.0.2", -] - [[package]] name = "webpki-roots" version = "1.0.2" diff --git a/generate-assets/Cargo.toml b/generate-assets/Cargo.toml index caaff3a753..4c4379f9b8 100644 --- a/generate-assets/Cargo.toml +++ b/generate-assets/Cargo.toml @@ -18,7 +18,7 @@ url = "2.2.2" anyhow = "1.0.58" base64 = "0.22.1" cratesio-dbdump-csvtab = "0.2.2" -ureq = { version = "2.5.0", features = ["json"] } +ureq = { version = "3.1.4", features = ["json"] } dotenv = "0.15.0" semver = "1.0.23" diff --git a/generate-assets/src/github_client.rs b/generate-assets/src/github_client.rs index d7c7c0dd51..bb344144be 100644 --- a/generate-assets/src/github_client.rs +++ b/generate-assets/src/github_client.rs @@ -38,10 +38,12 @@ pub struct GithubClient { impl GithubClient { pub fn new(token: String) -> Self { - let agent: ureq::Agent = ureq::AgentBuilder::new() + let config = ureq::Agent::config_builder() .user_agent("bevy-website-generate-assets") .build(); + let agent: ureq::Agent = config.into(); + Self { agent, token } } @@ -57,10 +59,11 @@ impl GithubClient { .get(&format!( "{BASE_URL}/repos/{username}/{repository_name}/contents/{content_path}" )) - .set("Accept", "application/json") - .set("Authorization", &format!("Bearer {}", self.token)) + .header("Accept", "application/json") + .header("Authorization", &format!("Bearer {}", self.token)) .call()? - .into_json()?; + .body_mut() + .read_json()?; if response.encoding == "base64" { use base64::Engine; @@ -82,10 +85,11 @@ impl GithubClient { .get(&format!( "{BASE_URL}/repos/{username}/{repository_name}/license" )) - .set("Accept", "application/json") - .set("Authorization", &format!("Bearer {}", self.token)) + .header("Accept", "application/json") + .header("Authorization", &format!("Bearer {}", self.token)) .call()? - .into_json()?; + .body_mut() + .read_json()?; let license = response.license.spdx_id; @@ -108,10 +112,11 @@ impl GithubClient { .get(&format!( "{BASE_URL}/search/code?q=repo:{username}/{repository_name}+filename:{file_name}" )) - .set("Accept", "application/json") - .set("Authorization", &format!("Bearer {}", self.token)) + .header("Accept", "application/json") + .header("Authorization", &format!("Bearer {}", self.token)) .call()? - .into_json()?; + .body_mut() + .read_json()?; if response.incomplete_results { println!( diff --git a/generate-assets/src/gitlab_client.rs b/generate-assets/src/gitlab_client.rs index 7535718b5d..aa1c236514 100644 --- a/generate-assets/src/gitlab_client.rs +++ b/generate-assets/src/gitlab_client.rs @@ -23,10 +23,12 @@ pub struct GitlabClient { impl GitlabClient { pub fn new(token: String) -> Self { - let agent: ureq::Agent = ureq::AgentBuilder::new() + let config = ureq::Agent::config_builder() .user_agent("bevy-website-generate-assets") .build(); + let agent: ureq::Agent = config.into(); + Self { agent, _token: token, @@ -42,10 +44,11 @@ impl GitlabClient { let response: Vec = self .agent .get(&format!("{BASE_URL}?search={repository_name}")) - .set("Accept", "application/json") - // .set("Authorization", &format!("Bearer {}", self.token)) + .header("Accept", "application/json") + // .header("Authorization", &format!("Bearer {}", self.token)) .call()? - .into_json()?; + .body_mut() + .read_json()?; Ok(response) } @@ -61,10 +64,11 @@ impl GitlabClient { .get(&format!( "{BASE_URL}/{id}/repository/files/{content_path}?ref={default_branch}" )) - .set("Accept", "application/json") + .header("Accept", "application/json") // .set("Authorization", &format!("Bearer {}", self.token)) .call()? - .into_json()?; + .body_mut() + .read_json()?; if response.encoding == "base64" { use base64::Engine; diff --git a/generate-release/Cargo.toml b/generate-release/Cargo.toml index c7dd368238..95447eb2e0 100644 --- a/generate-release/Cargo.toml +++ b/generate-release/Cargo.toml @@ -4,7 +4,7 @@ edition = "2021" publish = false [dependencies] -ureq = { version = "2.5.0", features = ["json"] } +ureq = { version = "3.1.4", features = ["json"] } serde = { version = "1", features = ["derive"] } anyhow = "1.0.58" pulldown-cmark = "0.9.2" diff --git a/generate-release/src/github_client.rs b/generate-release/src/github_client.rs index 4be4c76341..013f873170 100644 --- a/generate-release/src/github_client.rs +++ b/generate-release/src/github_client.rs @@ -5,9 +5,8 @@ use std::{ use anyhow::bail; use chrono::{DateTime, NaiveDate, TimeZone, Utc}; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; use thiserror::Error; -use ureq::Response; /// A GitHub repository in the `bevyengine` organization. #[derive(Debug, Clone, Copy)] @@ -76,6 +75,23 @@ pub struct GithubIssuesResponsePullRequest { pub merged_at: Option, } +#[derive(Serialize)] +struct Query { + query: String, +} + +#[derive(Serialize)] +struct RequestBody { + body: String, +} + +#[derive(Serialize)] +struct GithubIssueRequest { + title: String, + body: String, + labels: Vec, +} + #[derive(Deserialize, Clone, Debug)] pub struct GithubIssuesResponse { pub title: String, @@ -104,28 +120,34 @@ pub struct GithubClient { impl GithubClient { pub fn new(token: String, repo: BevyRepo) -> Self { - let agent: ureq::Agent = ureq::AgentBuilder::new() + let config = ureq::Agent::config_builder() .user_agent("bevy-website-generate-release") .build(); + let agent: ureq::Agent = config.into(); + Self { agent, token, repo } } /// Submits a GET request to `bevyengine/{repo}` - fn get(&self, path: &str, repo: BevyRepo) -> ureq::Request { + fn get( + &self, + path: &str, + repo: BevyRepo, + ) -> ureq::RequestBuilder { self.agent .get(&format!( "https://api.github.com/repos/bevyengine/{repo}/{path}", )) - .set("Accept", "application/json") - .set("Authorization", &format!("Bearer {}", self.token)) + .header("Accept", "application/json") + .header("Authorization", &format!("Bearer {}", self.token)) } - fn post_graphql(&self) -> ureq::Request { + fn post_graphql(&self) -> ureq::RequestBuilder { self.agent // WARN if this path ends with a / it will break .post("https://api.github.com/graphql") - .set("Authorization", &format!("bearer {}", self.token)) + .header("Authorization", &format!("bearer {}", self.token)) } /// Gets the list of all commits between two git ref @@ -161,8 +183,8 @@ impl GithubClient { let request = self .get(&format!("compare/{from}...{to}"), BevyRepo::Bevy) .query("per_page", "250") - .query("page", &page.to_string()); - Ok(request.call()?.into_json()?) + .query("page", page.to_string()); + Ok(request.call()?.into_body().read_json()?) } /// Gets a filtered list of issues and PRs from `bevyengine/{repo}`. @@ -227,16 +249,16 @@ impl GithubClient { .query("state", state.as_github_str()) .query("base", "main") .query("per_page", "100") - .query("page", &page.to_string()); + .query("page", page.to_string()); if let Some(date) = date { - request = request.query("since", &format!("{date}T00:00:00Z")); + request = request.query("since", format!("{date}T00:00:00Z")); } if let Some(label) = label { request = request.query("labels", label); } - let mut responses: Vec = request.call()?.into_json()?; + let mut responses: Vec = request.call()?.into_body().read_json()?; // Filter the PRs based on the requested state match state { @@ -274,10 +296,9 @@ query {{ ); // for whatever reasons, github doesn't accept newlines in graphql queries let query = query.replace('\n', ""); - let resp = self - .post_graphql() - .send_json(ureq::json!({ "query": query }))?; - let json: serde_json::Value = resp.into_json()?; + let json = Query { query }; + let resp = self.post_graphql().send_json(json)?; + let json: serde_json::Value = resp.into_body().read_json()?; let mut name_login_map = HashMap::new(); @@ -323,7 +344,7 @@ query {{ repo: BevyRepo, ) -> anyhow::Result { let request = self.get(&format!("commits/{git_ref}"), repo); - Ok(request.call()?.into_json()?) + Ok(request.call()?.into_body().read_json()?) } /// Opens a new issue on the specified repo. @@ -337,27 +358,28 @@ query {{ issue_body: &str, labels: Vec<&str>, ) -> Result { + let json = GithubIssueRequest { + title: issue_title.to_string(), + body: issue_body.to_string(), + // TODO: add the milestone. Tracked in https://github.com/bevyengine/bevy-website/issues/1269 + // Note that this must be provided as an integer, so we'll have to look up the milestone ID. + labels: labels.iter().map(|s| s.to_string()).collect(), + }; let response = self .agent .post(&format!( "https://api.github.com/repos/bevyengine/{repo}/issues" )) - .set("Authorization", &format!("Bearer {}", self.token)) - .set("Accept", "application/vnd.github+json") - .set("X-GitHub-Api-Version", "2022-11-28") - .send_json(ureq::json!({ - "title": issue_title, - "body": issue_body, - // TODO: add the milestone. Tracked in https://github.com/bevyengine/bevy-website/issues/1269 - // Note that this must be provided as an integer, so we'll have to look up the milestone ID. - "labels": labels, - }))?; + .header("Authorization", &format!("Bearer {}", self.token)) + .header("Accept", "application/vnd.github+json") + .header("X-GitHub-Api-Version", "2022-11-28") + .send_json(json)?; // Make sure the issue was created successfully if response.status() != 201 { Err(IssueError::FailedToCreateIssue(response)) } else { - let parsed_response: GithubIssueOpenedResponse = response.into_json()?; + let parsed_response: GithubIssueOpenedResponse = response.into_body().read_json()?; Ok(parsed_response) } @@ -372,18 +394,19 @@ query {{ repo: BevyRepo, issue_number: u64, comment: &str, - ) -> Result { + ) -> Result, ureq::Error> { + let json = RequestBody { + body: comment.to_string(), + }; let response = self .agent .post(&format!( "https://api.github.com/repos/bevyengine/{repo}/issues/{issue_number}/comments", )) - .set("Authorization", &format!("Bearer {}", self.token)) - .set("Accept", "application/vnd.github+json") - .set("X-GitHub-Api-Version", "2022-11-28") - .send_json(ureq::json!({ - "body": comment, - }))?; + .header("Authorization", &format!("Bearer {}", self.token)) + .header("Accept", "application/vnd.github+json") + .header("X-GitHub-Api-Version", "2022-11-28") + .send_json(json)?; Ok(response) } @@ -395,7 +418,7 @@ pub enum IssueError { #[error("error making request")] Ureq(#[from] ureq::Error), #[error("failed to create issue")] - FailedToCreateIssue(Response), + FailedToCreateIssue(ureq::http::Response), #[error("failed to parse response")] FailedToParseResponse(#[from] std::io::Error), }