Merge remote-tracking branch 'upstream/main' into conduwuit-changes
This commit is contained in:
commit
d01b3cc967
59
.github/workflows/docs-preview.yml
vendored
59
.github/workflows/docs-preview.yml
vendored
@ -1,59 +0,0 @@
|
|||||||
name: Docs Preview
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_run:
|
|
||||||
workflows: [CI]
|
|
||||||
types:
|
|
||||||
- completed
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
deploy:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.pull_requests[0] != null
|
|
||||||
steps:
|
|
||||||
- name: Download artifact
|
|
||||||
uses: actions/github-script@v7
|
|
||||||
with:
|
|
||||||
script: |
|
|
||||||
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
run_id: context.payload.workflow_run.id,
|
|
||||||
});
|
|
||||||
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
|
|
||||||
return artifact.name == "docs";
|
|
||||||
})[0];
|
|
||||||
let download = await github.rest.actions.downloadArtifact({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
artifact_id: matchArtifact.id,
|
|
||||||
archive_format: 'zip',
|
|
||||||
});
|
|
||||||
let fs = require('fs');
|
|
||||||
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/docs.zip`, Buffer.from(download.data));
|
|
||||||
|
|
||||||
- name: Unzip artifact
|
|
||||||
run: |
|
|
||||||
unzip docs.zip
|
|
||||||
tar -xf docs.tar.zstd
|
|
||||||
|
|
||||||
- name: Deploy PR preview
|
|
||||||
continue-on-error: true
|
|
||||||
id: deploy_preview
|
|
||||||
uses: dswistowski/surge-sh-action@v.1.0.3
|
|
||||||
with:
|
|
||||||
domain: pr-${{ github.event.workflow_run.pull_requests[0].number }}--ruma-docs.surge.sh
|
|
||||||
project: doc
|
|
||||||
login: ${{ secrets.SURGE_LOGIN }}
|
|
||||||
token: ${{ secrets.SURGE_TOKEN }}
|
|
||||||
|
|
||||||
- name: Comment PR preview URL
|
|
||||||
if: steps.deploy_preview.outcome == 'success'
|
|
||||||
uses: Beakyn/gha-comment-pull-request@v1.0.2
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ github.token }}
|
|
||||||
with:
|
|
||||||
pull-request-number: ${{ github.event.workflow_run.pull_requests[0].number }}
|
|
||||||
description-message: |
|
|
||||||
----
|
|
||||||
Preview: https://pr-${{ github.event.workflow_run.pull_requests[0].number }}--ruma-docs.surge.sh
|
|
54
.github/workflows/docs-remove-preview.yml
vendored
54
.github/workflows/docs-remove-preview.yml
vendored
@ -1,54 +0,0 @@
|
|||||||
name: Docs Remove Preview
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_run:
|
|
||||||
workflows: [PR Closed]
|
|
||||||
types:
|
|
||||||
- completed
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
teardown:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request'
|
|
||||||
steps:
|
|
||||||
- name: Get PR number
|
|
||||||
uses: actions/github-script@v7
|
|
||||||
id: get_pr
|
|
||||||
continue-on-error: true
|
|
||||||
with:
|
|
||||||
script: |
|
|
||||||
let login = context.payload.workflow_run.head_repository.owner.login;
|
|
||||||
let branch = context.payload.workflow_run.head_branch;
|
|
||||||
let head = `${login}:${branch}`;
|
|
||||||
let prs = await github.rest.pulls.list({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
state: "closed",
|
|
||||||
head,
|
|
||||||
});
|
|
||||||
if (prs.data.length > 0) {
|
|
||||||
core.setOutput("prnumber", prs.data[0].number);
|
|
||||||
} else {
|
|
||||||
core.setFailed("Could not find PR");
|
|
||||||
}
|
|
||||||
|
|
||||||
- name: Teardown preview
|
|
||||||
if: steps.get_pr.outcome == 'success'
|
|
||||||
continue-on-error: true
|
|
||||||
uses: adrianjost/actions-surge.sh-teardown@v1.0.3
|
|
||||||
with:
|
|
||||||
regex: pr-${{ steps.get_pr.outputs.prnumber }}--ruma-docs.surge.sh
|
|
||||||
env:
|
|
||||||
SURGE_LOGIN: ${{ secrets.SURGE_LOGIN }}
|
|
||||||
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
|
|
||||||
|
|
||||||
- name: Remove PR preview URL
|
|
||||||
if: steps.get_pr.outcome == 'success'
|
|
||||||
uses: Beakyn/gha-comment-pull-request@v1.0.2
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ github.token }}
|
|
||||||
with:
|
|
||||||
pull-request-number: ${{ steps.get_pr.outputs.prnumber }}
|
|
||||||
description-message: |
|
|
||||||
----
|
|
||||||
Preview Removed
|
|
13
.github/workflows/pr-closed.yml
vendored
13
.github/workflows/pr-closed.yml
vendored
@ -1,13 +0,0 @@
|
|||||||
name: PR Closed
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
branches: [main, next]
|
|
||||||
types: [closed]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
docs:
|
|
||||||
name: Trigger
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- run: 'echo "PR number: ${{ github.event.number }}"'
|
|
@ -13,7 +13,7 @@ assert_matches2 = "0.1.0"
|
|||||||
assign = "1.1.1"
|
assign = "1.1.1"
|
||||||
base64 = "0.21.0"
|
base64 = "0.21.0"
|
||||||
criterion = "0.5.0"
|
criterion = "0.5.0"
|
||||||
http = "0.2.8"
|
http = "1.1.0"
|
||||||
js_int = "0.2.2"
|
js_int = "0.2.2"
|
||||||
maplit = "1.0.2"
|
maplit = "1.0.2"
|
||||||
ruma-appservice-api = { version = "0.9.0", path = "crates/ruma-appservice-api" }
|
ruma-appservice-api = { version = "0.9.0", path = "crates/ruma-appservice-api" }
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
# [unreleased]
|
# [unreleased]
|
||||||
|
|
||||||
|
Breaking changes:
|
||||||
|
|
||||||
|
- Remove `isahc` feature
|
||||||
|
|
||||||
Improvements:
|
Improvements:
|
||||||
|
|
||||||
- Add `error_kind` accessor method to `Error<E, ruma_client_api::Error>`
|
- Add `error_kind` accessor method to `Error<E, ruma_client_api::Error>`
|
||||||
|
@ -19,10 +19,9 @@ rustdoc-args = ["--cfg", "docsrs"]
|
|||||||
client-api = ["dep:as_variant", "dep:ruma-client-api"]
|
client-api = ["dep:as_variant", "dep:ruma-client-api"]
|
||||||
|
|
||||||
# HTTP clients
|
# HTTP clients
|
||||||
hyper = ["dep:hyper"]
|
hyper = ["dep:http-body-util", "dep:hyper", "dep:hyper-util"]
|
||||||
hyper-native-tls = ["hyper", "dep:hyper-tls"]
|
hyper-native-tls = ["hyper", "dep:hyper-tls"]
|
||||||
hyper-rustls = ["hyper", "dep:hyper-rustls"]
|
hyper-rustls = ["hyper", "dep:hyper-rustls"]
|
||||||
isahc = ["dep:isahc", "futures-lite"]
|
|
||||||
reqwest = ["dep:reqwest"]
|
reqwest = ["dep:reqwest"]
|
||||||
reqwest-native-tls = ["reqwest", "reqwest?/native-tls"]
|
reqwest-native-tls = ["reqwest", "reqwest?/native-tls"]
|
||||||
reqwest-native-tls-alpn = ["reqwest", "reqwest?/native-tls-alpn"]
|
reqwest-native-tls-alpn = ["reqwest", "reqwest?/native-tls-alpn"]
|
||||||
@ -37,18 +36,16 @@ assign = { workspace = true }
|
|||||||
async-stream = "0.3.0"
|
async-stream = "0.3.0"
|
||||||
bytes = "1.0.1"
|
bytes = "1.0.1"
|
||||||
futures-core = "0.3.8"
|
futures-core = "0.3.8"
|
||||||
futures-lite = { version = "1.11.3", optional = true }
|
|
||||||
http = { workspace = true }
|
http = { workspace = true }
|
||||||
hyper = { version = "0.14.2", optional = true, features = ["client", "http1", "http2", "tcp"] }
|
http-body-util = { version = "0.1.1", optional = true }
|
||||||
hyper-rustls = { version = "0.24.0", optional = true, default-features = false }
|
hyper = { version = "1.3.1", optional = true, features = ["client", "http1", "http2"] }
|
||||||
hyper-tls = { version = "0.5.0", optional = true }
|
hyper-rustls = { version = "0.27.1", optional = true, default-features = false }
|
||||||
isahc = { version = "1.3.1", optional = true }
|
hyper-tls = { version = "0.6.0", optional = true }
|
||||||
reqwest = { version = "0.11.4", optional = true, default-features = false }
|
hyper-util = { version = "0.1.3", optional = true, features = ["client-legacy", "http1", "http2", "tokio"] }
|
||||||
|
reqwest = { version = "0.12.4", optional = true, default-features = false }
|
||||||
ruma-client-api = { workspace = true, optional = true, features = ["client"] }
|
ruma-client-api = { workspace = true, optional = true, features = ["client"] }
|
||||||
ruma-common = { workspace = true, features = ["api"] }
|
ruma-common = { workspace = true, features = ["api"] }
|
||||||
serde = { workspace = true }
|
|
||||||
serde_html_form = { workspace = true }
|
serde_html_form = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
|
||||||
tracing = { version = "0.1.30", default-features = false, features = ["std"] }
|
tracing = { version = "0.1.30", default-features = false, features = ["std"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
@ -13,8 +13,6 @@ use crate::{add_user_id_to_query, ResponseError, ResponseResult};
|
|||||||
|
|
||||||
#[cfg(feature = "hyper")]
|
#[cfg(feature = "hyper")]
|
||||||
mod hyper;
|
mod hyper;
|
||||||
#[cfg(feature = "isahc")]
|
|
||||||
mod isahc;
|
|
||||||
#[cfg(feature = "reqwest")]
|
#[cfg(feature = "reqwest")]
|
||||||
mod reqwest;
|
mod reqwest;
|
||||||
|
|
||||||
@ -24,8 +22,6 @@ pub use self::hyper::Hyper;
|
|||||||
pub use self::hyper::HyperNativeTls;
|
pub use self::hyper::HyperNativeTls;
|
||||||
#[cfg(feature = "hyper-rustls")]
|
#[cfg(feature = "hyper-rustls")]
|
||||||
pub use self::hyper::HyperRustls;
|
pub use self::hyper::HyperRustls;
|
||||||
#[cfg(feature = "isahc")]
|
|
||||||
pub use self::isahc::Isahc;
|
|
||||||
#[cfg(feature = "reqwest")]
|
#[cfg(feature = "reqwest")]
|
||||||
pub use self::reqwest::Reqwest;
|
pub use self::reqwest::Reqwest;
|
||||||
|
|
||||||
|
@ -1,44 +1,46 @@
|
|||||||
use bytes::{Bytes, BytesMut};
|
use bytes::{Bytes, BytesMut};
|
||||||
use hyper::client::{connect::Connect, HttpConnector};
|
use http_body_util::{BodyExt as _, Full};
|
||||||
|
use hyper_util::{
|
||||||
|
client::legacy::connect::{Connect, HttpConnector},
|
||||||
|
rt::TokioExecutor,
|
||||||
|
};
|
||||||
|
|
||||||
use super::{DefaultConstructibleHttpClient, HttpClient};
|
use super::{DefaultConstructibleHttpClient, HttpClient};
|
||||||
|
|
||||||
/// A basic hyper HTTP client.
|
/// A hyper HTTP client.
|
||||||
///
|
///
|
||||||
/// You basically never want this, since it doesn't support `https`.
|
/// The default connector is rarely useful, since it doesn't support `https`.
|
||||||
pub type Hyper = hyper::Client<HttpConnector>;
|
pub type Hyper<C = HttpConnector> = hyper_util::client::legacy::Client<C, Full<Bytes>>;
|
||||||
|
|
||||||
/// A hyper HTTP client using native-tls for TLS support.
|
/// A hyper HTTP client using native-tls for TLS support.
|
||||||
#[cfg(feature = "hyper-native-tls")]
|
#[cfg(feature = "hyper-native-tls")]
|
||||||
pub type HyperNativeTls = hyper::Client<hyper_tls::HttpsConnector<HttpConnector>>;
|
pub type HyperNativeTls = Hyper<hyper_tls::HttpsConnector<HttpConnector>>;
|
||||||
|
|
||||||
/// A hyper HTTP client using rustls for TLS support.
|
/// A hyper HTTP client using rustls for TLS support.
|
||||||
///
|
///
|
||||||
/// This client does not implement `DefaultConstructibleHttpClient`. To use it, you need to manually
|
/// This client does not implement `DefaultConstructibleHttpClient`.
|
||||||
/// construct
|
/// To use it, you need to manually create an instance.
|
||||||
#[cfg(feature = "hyper-rustls")]
|
#[cfg(feature = "hyper-rustls")]
|
||||||
pub type HyperRustls = hyper::Client<hyper_rustls::HttpsConnector<HttpConnector>>;
|
pub type HyperRustls = Hyper<hyper_rustls::HttpsConnector<HttpConnector>>;
|
||||||
|
|
||||||
impl<C> HttpClient for hyper::Client<C>
|
impl<C> HttpClient for Hyper<C>
|
||||||
where
|
where
|
||||||
C: Connect + Clone + Send + Sync + 'static,
|
C: Connect + Clone + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
type RequestBody = BytesMut;
|
type RequestBody = BytesMut;
|
||||||
type ResponseBody = Bytes;
|
type ResponseBody = Bytes;
|
||||||
type Error = hyper::Error;
|
type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||||
|
|
||||||
async fn send_http_request(
|
async fn send_http_request(
|
||||||
&self,
|
&self,
|
||||||
req: http::Request<BytesMut>,
|
req: http::Request<BytesMut>,
|
||||||
) -> Result<http::Response<Bytes>, hyper::Error> {
|
) -> Result<http::Response<Bytes>, Self::Error> {
|
||||||
let (head, body) = self
|
let (head, body) =
|
||||||
.request(req.map(|body| hyper::body::Body::from(body.freeze())))
|
self.request(req.map(|body| Full::new(body.freeze()))).await?.into_parts();
|
||||||
.await?
|
|
||||||
.into_parts();
|
|
||||||
|
|
||||||
// FIXME: Use aggregate instead of to_bytes once serde_json can parse from a reader at a
|
// FIXME: Use aggregate instead of to_bytes once serde_json can parse from a reader at a
|
||||||
// comparable speed as reading from a slice: https://github.com/serde-rs/json/issues/160
|
// comparable speed as reading from a slice: https://github.com/serde-rs/json/issues/160
|
||||||
let body = hyper::body::to_bytes(body).await?;
|
let body = body.collect().await?.to_bytes();
|
||||||
Ok(http::Response::from_parts(head, body))
|
Ok(http::Response::from_parts(head, body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,13 +48,15 @@ where
|
|||||||
#[cfg(feature = "hyper")]
|
#[cfg(feature = "hyper")]
|
||||||
impl DefaultConstructibleHttpClient for Hyper {
|
impl DefaultConstructibleHttpClient for Hyper {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
hyper::Client::new()
|
hyper_util::client::legacy::Client::builder(TokioExecutor::new())
|
||||||
|
.build(HttpConnector::new())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "hyper-native-tls")]
|
#[cfg(feature = "hyper-native-tls")]
|
||||||
impl DefaultConstructibleHttpClient for HyperNativeTls {
|
impl DefaultConstructibleHttpClient for HyperNativeTls {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
hyper::Client::builder().build(hyper_tls::HttpsConnector::new())
|
hyper_util::client::legacy::Client::builder(TokioExecutor::new())
|
||||||
|
.build(hyper_tls::HttpsConnector::new())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
use futures_lite::AsyncReadExt;
|
|
||||||
|
|
||||||
use super::HttpClient;
|
|
||||||
|
|
||||||
/// The `isahc` crate's `HttpClient`.
|
|
||||||
pub type Isahc = isahc::HttpClient;
|
|
||||||
|
|
||||||
impl HttpClient for Isahc {
|
|
||||||
type RequestBody = Vec<u8>;
|
|
||||||
type ResponseBody = Vec<u8>;
|
|
||||||
type Error = isahc::Error;
|
|
||||||
|
|
||||||
async fn send_http_request(
|
|
||||||
&self,
|
|
||||||
req: http::Request<Vec<u8>>,
|
|
||||||
) -> Result<http::Response<Vec<u8>>, isahc::Error> {
|
|
||||||
let (head, mut body) = self.send_async(req).await?.into_parts();
|
|
||||||
let mut full_body = Vec::new();
|
|
||||||
body.read_to_end(&mut full_body).await?;
|
|
||||||
Ok(http::Response::from_parts(head, full_body))
|
|
||||||
}
|
|
||||||
}
|
|
@ -84,7 +84,6 @@
|
|||||||
//! * `hyper`
|
//! * `hyper`
|
||||||
//! * `hyper-native-tls`
|
//! * `hyper-native-tls`
|
||||||
//! * `hyper-rustls`
|
//! * `hyper-rustls`
|
||||||
//! * `isahc`
|
|
||||||
//! * `reqwest` – if you use the `reqwest` library already, activate this feature and configure the
|
//! * `reqwest` – if you use the `reqwest` library already, activate this feature and configure the
|
||||||
//! TLS backend on `reqwest` directly. If you want to use `reqwest` but don't depend on it
|
//! TLS backend on `reqwest` directly. If you want to use `reqwest` but don't depend on it
|
||||||
//! already, use one of the sub-features instead. For details on the meaning of these, see
|
//! already, use one of the sub-features instead. For details on the meaning of these, see
|
||||||
|
@ -16,7 +16,7 @@ all-features = true
|
|||||||
rustdoc-args = ["--cfg", "docsrs"]
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
headers = "0.3"
|
headers = "0.4.0"
|
||||||
ruma-common = { workspace = true }
|
ruma-common = { workspace = true }
|
||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
yap = "0.11.0"
|
yap = "0.11.0"
|
||||||
|
@ -28,7 +28,6 @@ state-res = ["dep:ruma-state-res"]
|
|||||||
client-ext-client-api = ["client", "ruma-client?/client-api"]
|
client-ext-client-api = ["client", "ruma-client?/client-api"]
|
||||||
client-hyper = ["client", "ruma-client?/hyper"]
|
client-hyper = ["client", "ruma-client?/hyper"]
|
||||||
client-hyper-native-tls = ["client", "ruma-client?/hyper-native-tls"]
|
client-hyper-native-tls = ["client", "ruma-client?/hyper-native-tls"]
|
||||||
client-isahc = ["client", "ruma-client?/isahc"]
|
|
||||||
client-reqwest = ["client", "ruma-client?/reqwest"]
|
client-reqwest = ["client", "ruma-client?/reqwest"]
|
||||||
client-reqwest-native-tls = ["client", "ruma-client?/reqwest-native-tls"]
|
client-reqwest-native-tls = ["client", "ruma-client?/reqwest-native-tls"]
|
||||||
client-reqwest-native-tls-vendored = [
|
client-reqwest-native-tls-vendored = [
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "hello_isahc"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
publish = false
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
ruma = { version = "0.9.4", path = "../../crates/ruma", features = ["client-api-c", "client-ext-client-api", "client-isahc", "rand"] }
|
|
||||||
|
|
||||||
anyhow = "1.0.37"
|
|
||||||
isahc = "1.3.1"
|
|
||||||
tokio = { version = "1.0.1", features = ["macros", "rt"] }
|
|
@ -1,13 +0,0 @@
|
|||||||
Same as the [hello_world](../hello_world) example, but using the
|
|
||||||
[isahc](https://crates.io/crates/isahc) HTTP client (a Rust wrapper around libcurl).
|
|
||||||
|
|
||||||
# Usage
|
|
||||||
|
|
||||||
You will need to use an existing account on a homeserver that allows login with
|
|
||||||
a password.
|
|
||||||
|
|
||||||
In this folder, you can run it with this command:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
cargo run <homeserver_url> <username> <password> <room>
|
|
||||||
```
|
|
@ -1,48 +0,0 @@
|
|||||||
use std::{env, process::exit};
|
|
||||||
|
|
||||||
use ruma::{
|
|
||||||
api::client::{alias::get_alias, membership::join_room_by_id, message::send_message_event},
|
|
||||||
events::room::message::RoomMessageEventContent,
|
|
||||||
OwnedRoomAliasId, TransactionId,
|
|
||||||
};
|
|
||||||
|
|
||||||
async fn hello_world(
|
|
||||||
homeserver_url: String,
|
|
||||||
username: &str,
|
|
||||||
password: &str,
|
|
||||||
room_alias: OwnedRoomAliasId,
|
|
||||||
) -> anyhow::Result<()> {
|
|
||||||
let http_client = isahc::HttpClient::new()?;
|
|
||||||
let client =
|
|
||||||
ruma::Client::builder().homeserver_url(homeserver_url).http_client(http_client).await?;
|
|
||||||
client.log_in(username, password, None, Some("ruma-example-client")).await?;
|
|
||||||
|
|
||||||
let room_id = client.send_request(get_alias::v3::Request::new(room_alias)).await?.room_id;
|
|
||||||
client.send_request(join_room_by_id::v3::Request::new(room_id.clone())).await?;
|
|
||||||
client
|
|
||||||
.send_request(send_message_event::v3::Request::new(
|
|
||||||
room_id,
|
|
||||||
TransactionId::new(),
|
|
||||||
&RoomMessageEventContent::text_plain("Hello World!"),
|
|
||||||
)?)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::main(flavor = "current_thread")]
|
|
||||||
async fn main() -> anyhow::Result<()> {
|
|
||||||
let (homeserver_url, username, password, room) =
|
|
||||||
match (env::args().nth(1), env::args().nth(2), env::args().nth(3), env::args().nth(4)) {
|
|
||||||
(Some(a), Some(b), Some(c), Some(d)) => (a, b, c, d),
|
|
||||||
_ => {
|
|
||||||
eprintln!(
|
|
||||||
"Usage: {} <homeserver_url> <username> <password> <room>",
|
|
||||||
env::args().next().unwrap()
|
|
||||||
);
|
|
||||||
exit(1)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
hello_world(homeserver_url, &username, &password, room.try_into()?).await
|
|
||||||
}
|
|
@ -11,9 +11,11 @@ ruma = { version = "0.9.4", path = "../../crates/ruma", features = ["client-api-
|
|||||||
# ruma = { git = "https://github.com/ruma/ruma", rev = "f161c8117c706fc52089999e1f406cf34276ec9d", features = ["client-api-c", "client", "client-hyper-native-tls", "events"] }
|
# ruma = { git = "https://github.com/ruma/ruma", rev = "f161c8117c706fc52089999e1f406cf34276ec9d", features = ["client-api-c", "client", "client-hyper-native-tls", "events"] }
|
||||||
|
|
||||||
futures-util = { version = "0.3.21", default-features = false, features = ["std"] }
|
futures-util = { version = "0.3.21", default-features = false, features = ["std"] }
|
||||||
http = "0.2.2"
|
http = "1.1.0"
|
||||||
hyper = "0.14.2"
|
http-body-util = "0.1.1"
|
||||||
hyper-tls = "0.5.0"
|
hyper = "1.3.1"
|
||||||
|
hyper-tls = "0.6.0"
|
||||||
|
hyper-util = { version = "0.1.3", features = ["client-legacy", "http1", "http2", "tokio"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
tokio-stream = "0.1.7"
|
tokio-stream = "0.1.7"
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
use std::{error::Error, io, process::exit, time::Duration};
|
use std::{error::Error, io, process::exit, time::Duration};
|
||||||
|
|
||||||
use futures_util::future::{join, join_all};
|
use futures_util::future::{join, join_all};
|
||||||
|
use http_body_util::BodyExt as _;
|
||||||
|
use hyper_util::rt::TokioExecutor;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::{
|
api::client::{
|
||||||
filter::FilterDefinition, membership::join_room_by_id, message::send_message_event,
|
filter::FilterDefinition, membership::join_room_by_id, message::send_message_event,
|
||||||
@ -34,8 +36,8 @@ type MatrixClient = client::Client<client::http_client::HyperNativeTls>;
|
|||||||
async fn run() -> Result<(), Box<dyn Error>> {
|
async fn run() -> Result<(), Box<dyn Error>> {
|
||||||
let config =
|
let config =
|
||||||
read_config().await.map_err(|e| format!("configuration in ./config is invalid: {e}"))?;
|
read_config().await.map_err(|e| format!("configuration in ./config is invalid: {e}"))?;
|
||||||
let http_client =
|
let http_client = hyper_util::client::legacy::Client::builder(TokioExecutor::new())
|
||||||
hyper::Client::builder().build::<_, hyper::Body>(hyper_tls::HttpsConnector::new());
|
.build(hyper_tls::HttpsConnector::new());
|
||||||
let matrix_client = if let Some(state) = read_state().await.ok().flatten() {
|
let matrix_client = if let Some(state) = read_state().await.ok().flatten() {
|
||||||
ruma::Client::builder()
|
ruma::Client::builder()
|
||||||
.homeserver_url(config.homeserver.clone())
|
.homeserver_url(config.homeserver.clone())
|
||||||
@ -204,7 +206,7 @@ async fn get_joke(client: &HttpClient) -> Result<String, Box<dyn Error>> {
|
|||||||
let uri = "https://v2.jokeapi.dev/joke/Programming,Pun,Misc?safe-mode&type=single"
|
let uri = "https://v2.jokeapi.dev/joke/Programming,Pun,Misc?safe-mode&type=single"
|
||||||
.parse::<hyper::Uri>()?;
|
.parse::<hyper::Uri>()?;
|
||||||
let rsp = client.get(uri).await?;
|
let rsp = client.get(uri).await?;
|
||||||
let bytes = hyper::body::to_bytes(rsp).await?;
|
let bytes = rsp.into_body().collect().await?.to_bytes();
|
||||||
let joke_obj = serde_json::from_slice::<JsonValue>(&bytes)
|
let joke_obj = serde_json::from_slice::<JsonValue>(&bytes)
|
||||||
.map_err(|_| "invalid JSON returned from joke API")?;
|
.map_err(|_| "invalid JSON returned from joke API")?;
|
||||||
let joke = joke_obj["joke"].as_str().ok_or("joke field missing from joke API response")?;
|
let joke = joke_obj["joke"].as_str().ok_or("joke field missing from joke API response")?;
|
||||||
|
@ -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