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]
|
||||
clap = { version = "4.1.8", features = ["derive"] }
|
||||
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 }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use isahc::{HttpClient, ReadResponseExt};
|
||||
use reqwest::blocking::Client;
|
||||
use semver::Version;
|
||||
use serde::{de::IgnoredAny, Deserialize};
|
||||
use toml_edit::{value, Document};
|
||||
@ -153,15 +153,15 @@ impl Package {
|
||||
}
|
||||
|
||||
/// 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 =
|
||||
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())
|
||||
}
|
||||
|
||||
/// 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);
|
||||
let _dir = pushd(self.manifest_path.parent().unwrap())?;
|
||||
|
||||
|
@ -8,7 +8,6 @@ use std::{
|
||||
};
|
||||
|
||||
use html5gum::{Token, Tokenizer};
|
||||
use isahc::ReadResponseExt;
|
||||
|
||||
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.
|
||||
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 mut ids = HashMap::new();
|
||||
|
@ -1,12 +1,7 @@
|
||||
use std::io::{stdin, stdout, BufRead, Write};
|
||||
|
||||
use clap::Args;
|
||||
use isahc::{
|
||||
auth::{Authentication, Credentials},
|
||||
config::Configurable,
|
||||
http::StatusCode,
|
||||
HttpClient, ReadResponseExt, Request,
|
||||
};
|
||||
use reqwest::{blocking::Client, StatusCode};
|
||||
use semver::Version;
|
||||
use serde_json::json;
|
||||
|
||||
@ -40,7 +35,7 @@ pub struct ReleaseTask {
|
||||
version: Version,
|
||||
|
||||
/// The http client to use for requests.
|
||||
http_client: HttpClient,
|
||||
http_client: Client,
|
||||
|
||||
/// The github configuration required to publish a release.
|
||||
config: GithubConfig,
|
||||
@ -63,7 +58,7 @@ impl ReleaseTask {
|
||||
|
||||
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 })
|
||||
}
|
||||
@ -163,7 +158,7 @@ impl ReleaseTask {
|
||||
}
|
||||
|
||||
println!("Creating release on GitHub…");
|
||||
let request_body = &json!({
|
||||
let request_body = json!({
|
||||
"tag_name": tag,
|
||||
"name": title,
|
||||
"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.
|
||||
fn is_released(&self) -> Result<bool> {
|
||||
let response =
|
||||
self.http_client.get(format!("{GITHUB_API_RUMA}/releases/tags/{}", self.tag_name()))?;
|
||||
let response = self
|
||||
.http_client
|
||||
.get(format!("{GITHUB_API_RUMA}/releases/tags/{}", self.tag_name()))
|
||||
.send()?;
|
||||
|
||||
Ok(response.status() == StatusCode::OK)
|
||||
}
|
||||
|
||||
/// Create the release on GitHub with the given `config` and `credentials`.
|
||||
fn release(&self, body: &str) -> Result<()> {
|
||||
let request = Request::post(format!("{GITHUB_API_RUMA}/releases"))
|
||||
.authentication(Authentication::basic())
|
||||
.credentials(Credentials::new(&self.config.user, &self.config.token))
|
||||
fn release(&self, body: String) -> Result<()> {
|
||||
let response = self
|
||||
.http_client
|
||||
.post(format!("{GITHUB_API_RUMA}/releases"))
|
||||
.basic_auth(&self.config.user, Some(&self.config.token))
|
||||
.header("Accept", "application/vnd.github.v3+json")
|
||||
.body(body)?;
|
||||
|
||||
let mut response = self.http_client.send(request)?;
|
||||
.body(body)
|
||||
.send()?;
|
||||
|
||||
if response.status() == StatusCode::CREATED {
|
||||
Ok(())
|
||||
|
Loading…
x
Reference in New Issue
Block a user