git-next/crates/forge-forgejo/src/webhook/mod.rs
Paul Campbell 067296ffab
Some checks are pending
Rust / build (push) Successful in 1m21s
Release Please / Release-plz (push) Waiting to run
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
refactor: cleanup pedantic clippy in forge-forgejo crate
2024-08-06 16:15:56 +01:00

51 lines
1.1 KiB
Rust

//
use git_next_core::{git, webhook, BranchName, WebhookId};
use std::collections::HashMap;
mod list;
mod parser;
mod register;
mod unregister;
pub use list::list;
pub use parser::parse_body;
pub use register::register;
pub use unregister::unregister;
#[derive(Debug, serde::Deserialize)]
struct Hook {
id: i64,
config: HashMap<String, String>,
}
impl Hook {
fn id(&self) -> WebhookId {
WebhookId::new(format!("{}", self.id))
}
}
#[derive(Debug, serde::Deserialize)]
pub struct Push {
#[serde(rename = "ref")]
reference: String,
after: String,
head_commit: HeadCommit,
}
impl TryFrom<Push> for webhook::Push {
type Error = git::forge::webhook::Error;
fn try_from(push: Push) -> Result<Self, Self::Error> {
let branch = push
.reference
.splitn(3, '/') // should be of the form 'refs/heads/branchname'
.nth(2)
.map(BranchName::new)
.ok_or(git::forge::webhook::Error::UnknownBranch(push.reference))?;
Ok(Self::new(branch, push.after, push.head_commit.message))
}
}
#[derive(Debug, serde::Deserialize)]
struct HeadCommit {
message: String,
}