52 lines
1.2 KiB
Rust
52 lines
1.2 KiB
Rust
|
//
|
||
|
use git_next_config as config;
|
||
|
use git_next_git as git;
|
||
|
use std::collections::HashMap;
|
||
|
|
||
|
mod list;
|
||
|
mod parse;
|
||
|
mod register;
|
||
|
mod unregister;
|
||
|
|
||
|
pub use list::list;
|
||
|
pub use parse::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) -> config::WebhookId {
|
||
|
config::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 config::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(config::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,
|
||
|
}
|