generated from lucas/rust-template
Implement CI #25
3 changed files with 36 additions and 9 deletions
27
.forgejo/workflows/check.yaml
Normal file
27
.forgejo/workflows/check.yaml
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
name: check
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [master]
|
||||||
|
pull_request_target:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: docker
|
||||||
|
steps:
|
||||||
|
- uses: https://code.forgejo.org/actions/checkout@v4
|
||||||
|
- uses: https://github.com/actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48
|
||||||
|
- name: clippy
|
||||||
|
run: cargo build
|
||||||
|
|
||||||
|
check:
|
||||||
|
runs-on: docker
|
||||||
|
steps:
|
||||||
|
- uses: https://code.forgejo.org/actions/checkout@v4
|
||||||
|
- uses: https://github.com/actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48
|
||||||
|
with:
|
||||||
|
components: clippy, rustfmt
|
||||||
|
- name: clippy
|
||||||
|
run: cargo clippy -- -D warnings
|
||||||
|
- name: rustfmt
|
||||||
|
run: cargo fmt --all -- --check
|
|
@ -4,14 +4,14 @@ use mlua::IntoLua;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// Converts a `serde_json::Value` to a `mlua::Value`.
|
/// Converts a `serde_json::Value` to a `mlua::Value`.
|
||||||
fn json_to_lua(value: serde_json::Value, lua: &mlua::Lua) -> mlua::Result<mlua::Value<'_>> {
|
fn json_to_lua(value: serde_json::Value, lua: &mlua::Lua) -> mlua::Result<mlua::Value> {
|
||||||
match value {
|
match value {
|
||||||
serde_json::Value::Null => Ok(mlua::Value::Nil),
|
serde_json::Value::Null => Ok(mlua::Value::Nil),
|
||||||
serde_json::Value::Bool(value) => Ok(mlua::Value::Boolean(value)),
|
serde_json::Value::Bool(value) => Ok(mlua::Value::Boolean(value)),
|
||||||
serde_json::Value::Number(value) => match value.as_f64() {
|
serde_json::Value::Number(value) => match value.as_f64() {
|
||||||
Some(number) => Ok(mlua::Value::Number(number)),
|
Some(number) => Ok(mlua::Value::Number(number)),
|
||||||
None => Err(mlua::Error::ToLuaConversionError {
|
None => Err(mlua::Error::ToLuaConversionError {
|
||||||
from: "serde_json::Value::Number",
|
from: String::from("serde_json::Value::Number"),
|
||||||
to: "Number",
|
to: "Number",
|
||||||
message: Some("Number cannot be represented by a floating-point type".into()),
|
message: Some("Number cannot be represented by a floating-point type".into()),
|
||||||
}),
|
}),
|
||||||
|
@ -52,8 +52,8 @@ pub(crate) struct ApiEvent {
|
||||||
pub status: u16,
|
pub status: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'lua> IntoLua<'lua> for ApiEvent {
|
impl IntoLua for ApiEvent {
|
||||||
fn into_lua(self, lua: &'lua mlua::Lua) -> mlua::Result<mlua::Value<'lua>> {
|
fn into_lua(self, lua: &mlua::Lua) -> mlua::Result<mlua::Value> {
|
||||||
let headers = lua.create_table_with_capacity(0, self.headers.len())?;
|
let headers = lua.create_table_with_capacity(0, self.headers.len())?;
|
||||||
for (k, v) in self.headers {
|
for (k, v) in self.headers {
|
||||||
let k = lua.create_string(k)?;
|
let k = lua.create_string(k)?;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::sync::mpsc::Receiver;
|
use std::sync::mpsc::Receiver;
|
||||||
|
|
||||||
use color_eyre::Result;
|
use color_eyre::{eyre, Result};
|
||||||
use mlua::{Function, IntoLua as _, Lua, LuaSerdeExt};
|
use mlua::{Function, IntoLua as _, Lua, LuaSerdeExt};
|
||||||
use tokio::sync::mpsc::UnboundedSender;
|
use tokio::sync::mpsc::UnboundedSender;
|
||||||
|
|
||||||
|
@ -96,23 +96,23 @@ pub fn worker(
|
||||||
Event::Webhook(data) => {
|
Event::Webhook(data) => {
|
||||||
tracing::trace!(id = data.topic, "Received webhook event");
|
tracing::trace!(id = data.topic, "Received webhook event");
|
||||||
let data = lua.to_value(&data)?;
|
let data = lua.to_value(&data)?;
|
||||||
event_fn.call::<_, ()>(("webhook", data))?
|
event_fn.call(("webhook", data))?
|
||||||
}
|
}
|
||||||
Event::Api(data) => {
|
Event::Api(data) => {
|
||||||
tracing::trace!(id = data.id, status = data.status, "Received api event");
|
tracing::trace!(id = data.id, status = data.status, "Received api event");
|
||||||
let data = data.into_lua(&lua)?;
|
let data = data.into_lua(&lua)?;
|
||||||
event_fn.call::<_, ()>(("api", data))?
|
event_fn.call(("api", data))?
|
||||||
}
|
}
|
||||||
Event::Error(data) => {
|
Event::Error(data) => {
|
||||||
tracing::trace!(id = data.id, message = data.message, "Received error event");
|
tracing::trace!(id = data.id, message = data.message, "Received error event");
|
||||||
let data = lua.to_value(&data)?;
|
let data = lua.to_value(&data)?;
|
||||||
event_fn.call::<_, ()>(("error", data))?
|
event_fn.call(("error", data))?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
}).map_err(|e| eyre::eyre!("{:?}", e))?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue