Implement gitea hook support instead

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2024-04-21 17:41:47 +02:00
parent fd85de951c
commit 991474e4ad
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2
3 changed files with 18 additions and 6 deletions

View file

@ -9,7 +9,7 @@ license = "AGPL-3.0+"
[dependencies]
clap = { version = "4.3", features = [ "cargo" ] }
gitlab = "0.1610"
forgejo-api-types = "0.1"
gitea-rs = "1.19"
hyper = { version = "0.14", features = [ "full" ] }
jid = { version = "*", features = [ "serde" ] }
log = "0.4"

View file

@ -14,7 +14,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::error::Error;
use crate::webhook::{Hook, ForgejoHook, GitlabHook};
use crate::webhook::{Hook, GiteaHook, GitlabHook};
use std::convert::Infallible;
use std::str::from_utf8;
@ -79,9 +79,9 @@ async fn webhooks_inner(req: Request<Body>, token: &str) -> Result<Hook, Error>
let tmp = body::to_bytes(req.into_body()).await?;
let text: &str = from_utf8(&tmp)?;
debug!("FOO3 text: {:?}", text);
let hook: ForgejoHook = serde_json::from_str(text)?;
let hook: GiteaHook = serde_json::from_str(text)?;
debug!("FOO3 json: {:?}", hook);
Ok(Hook::Forgejo(hook))
Ok(Hook::Gitea(hook))
}
} else {
debug!("FOO3: else");

View file

@ -14,15 +14,27 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
pub use gitlab::webhooks::{IssueAction, MergeRequestAction, WebHook as GitlabHook, WikiPageAction};
pub use forgejo_api_types::types::api::hook::Hook as ForgejoHook;
pub use gitea_rs::models::hook::Hook as GiteaHook;
use log::debug;
#[derive(Debug)]
pub enum Hook {
Forgejo(ForgejoHook),
Gitea(GiteaHook),
Gitlab(GitlabHook),
}
impl From<GiteaHook> for Hook {
fn from(hook: GiteaHook) -> Hook {
Hook::Gitea(hook)
}
}
impl From<GitlabHook> for Hook {
fn from(hook: GitlabHook) -> Hook {
Hook::Gitlab(hook)
}
}
pub fn format_webhook(glh: &GitlabHook) -> Option<String> {
Some(match glh {
GitlabHook::Push(push) => {