6 Commits

Author SHA1 Message Date
967d561911 Add docker release info to readme
Some checks failed
CI / CI (push) Has been cancelled
Release / Publish to crates.io (push) Successful in 4m36s
Release / Publish to Docker Hub (push) Failing after 4s
2023-09-19 23:40:29 -07:00
2f32c7b415 Update dependencies 2023-09-19 23:40:29 -07:00
07915f5e54 Add gitea release workflow 2023-09-19 23:40:29 -07:00
f86c774965 Fill in requires Cargo.toml package metadata 2023-09-19 23:14:25 -07:00
74aa5d724d Add gitea CI workflow
All checks were successful
CI / CI (push) Successful in 8m17s
2023-09-19 22:39:52 -07:00
bfd146de95 Fix clippy warnings 2023-09-19 21:37:30 -07:00
7 changed files with 127 additions and 93 deletions

View File

@ -1,9 +1,12 @@
name: CI name: CI
on: on:
- push push:
branches:
- main
pull_request: {}
jobs: jobs:
janitorial: ci:
name: janitorial name: CI
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@ -11,38 +14,10 @@ jobs:
with: with:
toolchain: stable toolchain: stable
profile: minimal profile: minimal
components: clippy components: clippy, rustfmt
override: true - name: clippy
- uses: https://github.com/actions-rs/clippy-check@v1 run: cargo clippy --all-targets --all-features -- -D warnings
with: - name: formatting
toolchain: stable run: cargo fmt --check
token: ${{ secrets.GITHUB_TOKEN }} - name: test
args: --all-targets --all-features -- -D warnings run: cargo test --release
- uses: https://github.com/actions-rs/cargo@v1
with:
command: fmt
args: --check
test:
name: test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
rust:
- stable
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
steps:
- uses: actions/checkout@v3
- uses: https://github.com/actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
override: true
- uses: https://github.com/actions-rs/cargo@v1
with:
use-cross: true
command: test
args: --release --target=${{ matrix.target }}

View File

@ -0,0 +1,44 @@
name: Release
on:
push:
tags:
- "v*.*.*"
jobs:
release-crate:
name: Publish to crates.io
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: https://github.com/actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
- name: Publish release
run: cargo publish --token ${{ secrets.CRATES_IO_TOKEN }}
release-docker:
name: Publish to Docker Hub
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: docker meta
id: meta
uses: https://github.com/docker/metadata-action@v5
with:
images: |
kelnos/bebot
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.output.labels }}

48
Cargo.lock generated
View File

@ -30,9 +30,9 @@ dependencies = [
[[package]] [[package]]
name = "aho-corasick" name = "aho-corasick"
version = "1.0.5" version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c378d78423fdad8089616f827526ee33c19f2fddbd5de1629152c9593ba4783" checksum = "0f2135563fb5c609d2b2b87c1e8ce7bc41b0b45430fa9661f457981503dd5bf0"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]
@ -89,7 +89,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.33", "syn 2.0.37",
] ]
[[package]] [[package]]
@ -100,7 +100,7 @@ checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.33", "syn 2.0.37",
] ]
[[package]] [[package]]
@ -469,7 +469,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.33", "syn 2.0.37",
] ]
[[package]] [[package]]
@ -534,7 +534,7 @@ checksum = "913dce4c5f06c2ea40fc178c06f777ac89fc6b1383e90c254fafb1abe4ba3c82"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.33", "syn 2.0.37",
"uuid", "uuid",
] ]
@ -615,9 +615,9 @@ dependencies = [
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.3.2" version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
[[package]] [[package]]
name = "http" name = "http"
@ -1057,7 +1057,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.33", "syn 2.0.37",
] ]
[[package]] [[package]]
@ -1441,7 +1441,7 @@ checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.33", "syn 2.0.37",
] ]
[[package]] [[package]]
@ -1567,9 +1567,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.33" version = "2.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9caece70c63bfba29ec2fed841a09851b14a235c60010fa4de58089b6c025668" checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1578,9 +1578,9 @@ dependencies = [
[[package]] [[package]]
name = "termcolor" name = "termcolor"
version = "1.2.0" version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64"
dependencies = [ dependencies = [
"winapi-util", "winapi-util",
] ]
@ -1602,7 +1602,7 @@ checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.33", "syn 2.0.37",
] ]
[[package]] [[package]]
@ -1645,7 +1645,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.33", "syn 2.0.37",
] ]
[[package]] [[package]]
@ -1748,7 +1748,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.33", "syn 2.0.37",
] ]
[[package]] [[package]]
@ -1787,9 +1787,9 @@ dependencies = [
[[package]] [[package]]
name = "typenum" name = "typenum"
version = "1.16.0" version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]] [[package]]
name = "unicase" name = "unicase"
@ -1932,7 +1932,7 @@ dependencies = [
"once_cell", "once_cell",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.33", "syn 2.0.37",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -1966,7 +1966,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.33", "syn 2.0.37",
"wasm-bindgen-backend", "wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -2132,9 +2132,9 @@ dependencies = [
[[package]] [[package]]
name = "zeroize" name = "zeroize"
version = "1.3.0" version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9"
dependencies = [ dependencies = [
"zeroize_derive", "zeroize_derive",
] ]
@ -2147,5 +2147,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.33", "syn 2.0.37",
] ]

View File

@ -1,9 +1,26 @@
[package] [package]
name = "bebot" name = "bebot"
version = "0.1.0" version = "0.1.0"
description = "Gitlab webhook bot that publishes events to Matrix"
license = "GPL-3.0"
authors = [
"Brian J. Tarricone <brian@tarricone.org>",
]
homepage = "https://git.spurint.org/kelnos/bebot"
repository = "https://git.spurint.org/kelnos/bebot"
edition = "2021" edition = "2021"
categories = [
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html "development-tools",
]
keywords = [
"gitlab",
"matrix",
"bot",
"webhook",
]
exclude = [
".gitea/*",
]
[dependencies] [dependencies]
anyhow = "1" anyhow = "1"

View File

@ -58,3 +58,6 @@ logging verbosity. (Try `debug`, `info`, `warn` `error`, or `off`.)
A `Dockerfile` is also provided. When running the container it builds, A `Dockerfile` is also provided. When running the container it builds,
mount the configuration file so it appears inside the container as mount the configuration file so it appears inside the container as
`/bebot/config/bebot.yaml`. `/bebot/config/bebot.yaml`.
Release images are [published to Docker
Hub](https://hub.docker.com/r/kelnos/bebot).

View File

@ -19,7 +19,7 @@ use core::fmt;
use crate::config::PublishEvent; use crate::config::PublishEvent;
pub trait GitlabEventExt { pub trait GitlabEventExt {
fn should_publish(&self, publish_events: &Vec<PublishEvent>) -> bool; fn should_publish(&self, publish_events: &[PublishEvent]) -> bool;
fn project(&self) -> &Project; fn project(&self) -> &Project;
fn r#ref(&self) -> Option<&str>; fn r#ref(&self) -> Option<&str>;
fn user(&self) -> &str; fn user(&self) -> &str;
@ -264,7 +264,7 @@ macro_rules! find_publish_event {
} }
impl GitlabEventExt for GitlabEvent { impl GitlabEventExt for GitlabEvent {
fn should_publish(&self, publish_events: &Vec<PublishEvent>) -> bool { fn should_publish(&self, publish_events: &[PublishEvent]) -> bool {
match self { match self {
GitlabEvent::Push { r#ref, .. } => { GitlabEvent::Push { r#ref, .. } => {
if let Some(PublishEvent::Push { branches }) = if let Some(PublishEvent::Push { branches }) =
@ -274,7 +274,7 @@ impl GitlabEventExt for GitlabEvent {
None => true, None => true,
Some(branches) => { Some(branches) => {
let refname = parse_ref(r#ref); let refname = parse_ref(r#ref);
branches.iter().find(|branch| branch.find(&refname).is_some()).is_some() branches.iter().any(|branch| branch.find(&refname).is_some())
} }
} }
} else { } else {
@ -324,19 +324,19 @@ impl GitlabEventExt for GitlabEvent {
fn project(&self) -> &Project { fn project(&self) -> &Project {
match self { match self {
GitlabEvent::Push { project, .. } => &project, GitlabEvent::Push { project, .. } => project,
GitlabEvent::TagPush { project, .. } => &project, GitlabEvent::TagPush { project, .. } => project,
GitlabEvent::Issue { project, .. } => project, GitlabEvent::Issue { project, .. } => project,
GitlabEvent::MergeRequest { project, .. } => &project, GitlabEvent::MergeRequest { project, .. } => project,
GitlabEvent::Pipeline { project, .. } => &project, GitlabEvent::Pipeline { project, .. } => project,
GitlabEvent::Other => unreachable!("Unsupported event type"), GitlabEvent::Other => unreachable!("Unsupported event type"),
} }
} }
fn r#ref(&self) -> Option<&str> { fn r#ref(&self) -> Option<&str> {
match self { match self {
GitlabEvent::Push { r#ref, .. } => Some(&r#ref), GitlabEvent::Push { r#ref, .. } => Some(r#ref),
GitlabEvent::TagPush { r#ref, .. } => Some(&r#ref), GitlabEvent::TagPush { r#ref, .. } => Some(r#ref),
GitlabEvent::Issue { .. } => None, GitlabEvent::Issue { .. } => None,
GitlabEvent::MergeRequest { object_attributes, .. } => Some(&object_attributes.target_branch), GitlabEvent::MergeRequest { object_attributes, .. } => Some(&object_attributes.target_branch),
GitlabEvent::Pipeline { object_attributes, .. } => Some(&object_attributes.r#ref), GitlabEvent::Pipeline { object_attributes, .. } => Some(&object_attributes.r#ref),
@ -346,8 +346,8 @@ impl GitlabEventExt for GitlabEvent {
fn user(&self) -> &str { fn user(&self) -> &str {
match self { match self {
GitlabEvent::Push { user_name, .. } => &user_name, GitlabEvent::Push { user_name, .. } => user_name,
GitlabEvent::TagPush { user_name, .. } => &user_name, GitlabEvent::TagPush { user_name, .. } => user_name,
GitlabEvent::Issue { user, .. } => &user.name, GitlabEvent::Issue { user, .. } => &user.name,
GitlabEvent::MergeRequest { user, .. } => &user.name, GitlabEvent::MergeRequest { user, .. } => &user.name,
GitlabEvent::Pipeline { user, .. } => &user.name, GitlabEvent::Pipeline { user, .. } => &user.name,
@ -356,7 +356,7 @@ impl GitlabEventExt for GitlabEvent {
} }
fn titles(&self) -> Vec<String> { fn titles(&self) -> Vec<String> {
fn find_commit<'a>(commits: &'a Vec<Commit>, sha: &str) -> Option<&'a Commit> { fn find_commit<'a>(commits: &'a [Commit], sha: &str) -> Option<&'a Commit> {
commits.iter().find(|commit| commit.id == sha) commits.iter().find(|commit| commit.id == sha)
} }
@ -395,7 +395,7 @@ impl GitlabEventExt for GitlabEvent {
} => { } => {
let title = format!( let title = format!(
"**tagged** {}", "**tagged** {}",
find_commit(commits, &checkout_sha) find_commit(commits, checkout_sha)
.map(|commit| &commit.title) .map(|commit| &commit.title)
.unwrap_or(checkout_sha) .unwrap_or(checkout_sha)
); );
@ -433,7 +433,7 @@ impl GitlabEventExt for GitlabEvent {
let title = object_attributes let title = object_attributes
.name .name
.as_ref() .as_ref()
.map(|n| n.clone()) .cloned()
.or(merge_request.as_ref().map(|mr| mr.title.clone())) .or(merge_request.as_ref().map(|mr| mr.title.clone()))
.iter() .iter()
.fold(format!("Pipeline **{}**", object_attributes.status), |accum, title| { .fold(format!("Pipeline **{}**", object_attributes.status), |accum, title| {
@ -474,7 +474,7 @@ mod test {
use std::{fs::File, io::BufReader}; use std::{fs::File, io::BufReader};
fn load_test_data(name: &str) -> anyhow::Result<GitlabEvent> { fn load_test_data(name: &str) -> anyhow::Result<GitlabEvent> {
let f = File::open(&format!("{}/test-data/{}.json", env!("CARGO_MANIFEST_DIR"), name))?; let f = File::open(format!("{}/test-data/{}.json", env!("CARGO_MANIFEST_DIR"), name))?;
let r = BufReader::new(f); let r = BufReader::new(f);
let event: GitlabEvent = serde_json::from_reader(r)?; let event: GitlabEvent = serde_json::from_reader(r)?;
Ok(event) Ok(event)

View File

@ -83,37 +83,32 @@ async fn ensure_matrix_room_joined(matrix_client: &Client, room_id: &OwnedRoomOr
|| a_room || a_room
.canonical_alias() .canonical_alias()
.iter() .iter()
.find(|alias| alias.as_str() == our_room_str) .any(|alias| alias.as_str() == our_room_str)
.is_some() || a_room.alt_aliases().iter().any(|alias| alias.as_str() == our_room_str)
|| a_room
.alt_aliases()
.iter()
.find(|alias| alias.as_str() == our_room_str)
.is_some()
} }
let mut room = matrix_client let mut room = matrix_client
.joined_rooms() .joined_rooms()
.iter() .iter()
.find(|a_room| room_matches(*a_room, room_id)) .find(|a_room| room_matches(a_room, room_id))
.map(|room| room.clone()); .cloned();
if room.is_none() { if room.is_none() {
if let Some(invited) = matrix_client if let Some(invited) = matrix_client
.invited_rooms() .invited_rooms()
.iter() .iter()
.find(|a_room| room_matches(*a_room, room_id)) .find(|a_room| room_matches(a_room, room_id))
{ {
invited.accept_invitation().await?; invited.accept_invitation().await?;
} else { } else {
matrix_client.join_room_by_id_or_alias(room_id, &[]).await?; matrix_client.join_room_by_id_or_alias(room_id, &[]).await?;
} }
let settings = build_sync_settings(&matrix_client).await; let settings = build_sync_settings(matrix_client).await;
matrix_client.sync_once(settings).await?; matrix_client.sync_once(settings).await?;
room = matrix_client room = matrix_client
.joined_rooms() .joined_rooms()
.iter() .iter()
.find(|a_room| room_matches(*a_room, room_id)) .find(|a_room| room_matches(a_room, room_id))
.map(|room| room.clone()); .cloned();
} }
room.ok_or_else(|| anyhow!("Unable to join room {}", room_id)) room.ok_or_else(|| anyhow!("Unable to join room {}", room_id))
@ -162,7 +157,7 @@ async fn run() -> anyhow::Result<()> {
let addr = config let addr = config
.bind_address .bind_address
.as_ref() .as_ref()
.map(|ba| ba.clone()) .cloned()
.unwrap_or_else(|| "127.0.0.1".to_string()) .unwrap_or_else(|| "127.0.0.1".to_string())
.parse::<IpAddr>() .parse::<IpAddr>()
.context("Failed to parse bind_address")?; .context("Failed to parse bind_address")?;