xtask: Migrate from isahc to reqwest
Co-authored-by: Jonas Platte <jplatte+git@posteo.de> Co-authored-by: Kévin Commaille <76261501+zecakeh@users.noreply.github.com>
This commit is contained in:
parent
f1428d138a
commit
7b373b78bb
@ -10,7 +10,7 @@ default = ["dep:semver", "dep:toml_edit"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.1.8", features = ["derive"] }
|
clap = { version = "4.1.8", features = ["derive"] }
|
||||||
html5gum = "0.5.2"
|
html5gum = "0.5.2"
|
||||||
isahc = { version = "1.7.0", features = ["json"] }
|
reqwest = { version = "0.12.4", features = ["blocking", "json"] }
|
||||||
semver = { version = "1.0.6", features = ["serde"], optional = true }
|
semver = { version = "1.0.6", features = ["serde"], optional = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use isahc::{HttpClient, ReadResponseExt};
|
use reqwest::blocking::Client;
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
use serde::{de::IgnoredAny, Deserialize};
|
use serde::{de::IgnoredAny, Deserialize};
|
||||||
use toml_edit::{value, Document};
|
use toml_edit::{value, Document};
|
||||||
@ -153,15 +153,15 @@ impl Package {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Check if the current version of the crate is published on crates.io.
|
/// Check if the current version of the crate is published on crates.io.
|
||||||
pub fn is_published(&self, client: &HttpClient) -> Result<bool> {
|
pub fn is_published(&self, client: &Client) -> Result<bool> {
|
||||||
let response: CratesIoCrate =
|
let response: CratesIoCrate =
|
||||||
client.get(format!("{CRATESIO_API}/{}/{}", self.name, self.version))?.json()?;
|
client.get(format!("{CRATESIO_API}/{}/{}", self.name, self.version)).send()?.json()?;
|
||||||
|
|
||||||
Ok(response.version.is_some())
|
Ok(response.version.is_some())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Publish this package on crates.io.
|
/// Publish this package on crates.io.
|
||||||
pub fn publish(&self, client: &HttpClient, dry_run: bool) -> Result<()> {
|
pub fn publish(&self, client: &Client, dry_run: bool) -> Result<()> {
|
||||||
println!("Publishing {} {} on crates.io…", self.name, self.version);
|
println!("Publishing {} {} on crates.io…", self.name, self.version);
|
||||||
let _dir = pushd(self.manifest_path.parent().unwrap())?;
|
let _dir = pushd(self.manifest_path.parent().unwrap())?;
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use html5gum::{Token, Tokenizer};
|
use html5gum::{Token, Tokenizer};
|
||||||
use isahc::ReadResponseExt;
|
|
||||||
|
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
|
|
||||||
@ -211,7 +210,7 @@ fn check_targets(links: &[SpecLink]) -> Result<()> {
|
|||||||
///
|
///
|
||||||
/// Returns an error if the URL points to an invalid HTML page.
|
/// Returns an error if the URL points to an invalid HTML page.
|
||||||
fn get_page_ids(url: &str) -> Result<HashMap<String, HasDuplicates>> {
|
fn get_page_ids(url: &str) -> Result<HashMap<String, HasDuplicates>> {
|
||||||
let mut page = isahc::get(url)?;
|
let page = reqwest::blocking::get(url)?;
|
||||||
|
|
||||||
let html = page.text()?;
|
let html = page.text()?;
|
||||||
let mut ids = HashMap::new();
|
let mut ids = HashMap::new();
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
use std::io::{stdin, stdout, BufRead, Write};
|
use std::io::{stdin, stdout, BufRead, Write};
|
||||||
|
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
use isahc::{
|
use reqwest::{blocking::Client, StatusCode};
|
||||||
auth::{Authentication, Credentials},
|
|
||||||
config::Configurable,
|
|
||||||
http::StatusCode,
|
|
||||||
HttpClient, ReadResponseExt, Request,
|
|
||||||
};
|
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
@ -40,7 +35,7 @@ pub struct ReleaseTask {
|
|||||||
version: Version,
|
version: Version,
|
||||||
|
|
||||||
/// The http client to use for requests.
|
/// The http client to use for requests.
|
||||||
http_client: HttpClient,
|
http_client: Client,
|
||||||
|
|
||||||
/// The github configuration required to publish a release.
|
/// The github configuration required to publish a release.
|
||||||
config: GithubConfig,
|
config: GithubConfig,
|
||||||
@ -63,7 +58,7 @@ impl ReleaseTask {
|
|||||||
|
|
||||||
let config = crate::Config::load()?.github;
|
let config = crate::Config::load()?.github;
|
||||||
|
|
||||||
let http_client = HttpClient::new()?;
|
let http_client = Client::new();
|
||||||
|
|
||||||
Ok(Self { metadata, package, version, http_client, config, dry_run })
|
Ok(Self { metadata, package, version, http_client, config, dry_run })
|
||||||
}
|
}
|
||||||
@ -163,7 +158,7 @@ impl ReleaseTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
println!("Creating release on GitHub…");
|
println!("Creating release on GitHub…");
|
||||||
let request_body = &json!({
|
let request_body = json!({
|
||||||
"tag_name": tag,
|
"tag_name": tag,
|
||||||
"name": title,
|
"name": title,
|
||||||
"body": changes.trim_softbreaks(),
|
"body": changes.trim_softbreaks(),
|
||||||
@ -260,21 +255,23 @@ impl ReleaseTask {
|
|||||||
|
|
||||||
/// Check if the tag for the current version of the crate has been pushed on GitHub.
|
/// Check if the tag for the current version of the crate has been pushed on GitHub.
|
||||||
fn is_released(&self) -> Result<bool> {
|
fn is_released(&self) -> Result<bool> {
|
||||||
let response =
|
let response = self
|
||||||
self.http_client.get(format!("{GITHUB_API_RUMA}/releases/tags/{}", self.tag_name()))?;
|
.http_client
|
||||||
|
.get(format!("{GITHUB_API_RUMA}/releases/tags/{}", self.tag_name()))
|
||||||
|
.send()?;
|
||||||
|
|
||||||
Ok(response.status() == StatusCode::OK)
|
Ok(response.status() == StatusCode::OK)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create the release on GitHub with the given `config` and `credentials`.
|
/// Create the release on GitHub with the given `config` and `credentials`.
|
||||||
fn release(&self, body: &str) -> Result<()> {
|
fn release(&self, body: String) -> Result<()> {
|
||||||
let request = Request::post(format!("{GITHUB_API_RUMA}/releases"))
|
let response = self
|
||||||
.authentication(Authentication::basic())
|
.http_client
|
||||||
.credentials(Credentials::new(&self.config.user, &self.config.token))
|
.post(format!("{GITHUB_API_RUMA}/releases"))
|
||||||
|
.basic_auth(&self.config.user, Some(&self.config.token))
|
||||||
.header("Accept", "application/vnd.github.v3+json")
|
.header("Accept", "application/vnd.github.v3+json")
|
||||||
.body(body)?;
|
.body(body)
|
||||||
|
.send()?;
|
||||||
let mut response = self.http_client.send(request)?;
|
|
||||||
|
|
||||||
if response.status() == StatusCode::CREATED {
|
if response.status() == StatusCode::CREATED {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user