Rename webhook to hook where appropriate
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
1301275788
commit
1cf93d1ba8
4 changed files with 16 additions and 16 deletions
10
src/bot.rs
10
src/bot.rs
|
@ -13,7 +13,7 @@
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::webhook::{format_webhook, GitlabHook};
|
use crate::hook::{format_hook, GitlabHook};
|
||||||
|
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use xmpp::parsers::message::MessageType;
|
use xmpp::parsers::message::MessageType;
|
||||||
|
@ -74,10 +74,10 @@ impl XmppClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn webhook(&mut self, wh: GitlabHook) {
|
pub async fn hook(&mut self, wh: GitlabHook) {
|
||||||
debug!("Received Webhook");
|
debug!("Received Hook");
|
||||||
if let Some(display) = format_webhook(&wh) {
|
if let Some(display) = format_hook(&wh) {
|
||||||
debug!("Webhook: {}", display);
|
debug!("Hook: {}", display);
|
||||||
for room in &self.rooms {
|
for room in &self.rooms {
|
||||||
self.agent
|
self.agent
|
||||||
.send_message(
|
.send_message(
|
||||||
|
|
|
@ -31,7 +31,7 @@ impl From<GitlabHook> for Hook {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format_webhook(glh: &GitlabHook) -> Option<String> {
|
pub fn format_hook(glh: &GitlabHook) -> Option<String> {
|
||||||
Some(match glh {
|
Some(match glh {
|
||||||
GitlabHook::Push(push) => {
|
GitlabHook::Push(push) => {
|
||||||
if push.ref_ != "refs/heads/main" {
|
if push.ref_ != "refs/heads/main" {
|
||||||
|
@ -154,7 +154,7 @@ pub fn format_webhook(glh: &GitlabHook) -> Option<String> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
_glh => {
|
_glh => {
|
||||||
debug!("Webhook not supported");
|
debug!("Hook not supported");
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
})
|
})
|
10
src/main.rs
10
src/main.rs
|
@ -18,13 +18,13 @@
|
||||||
|
|
||||||
mod bot;
|
mod bot;
|
||||||
mod error;
|
mod error;
|
||||||
|
mod hook;
|
||||||
mod web;
|
mod web;
|
||||||
mod webhook;
|
|
||||||
|
|
||||||
use crate::bot::XmppClient;
|
use crate::bot::XmppClient;
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::web::webhooks;
|
use crate::hook::Hook;
|
||||||
use crate::webhook::Hook;
|
use crate::web::hooks;
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Error as IoError, ErrorKind as IoErrorKind, Read};
|
use std::io::{Error as IoError, ErrorKind as IoErrorKind, Read};
|
||||||
|
@ -158,7 +158,7 @@ async fn main() -> Result<!, Error> {
|
||||||
.serve_connection(io, service_fn(|request| {
|
.serve_connection(io, service_fn(|request| {
|
||||||
let value_tx = value_tx.clone();
|
let value_tx = value_tx.clone();
|
||||||
async move {
|
async move {
|
||||||
webhooks(request, token, value_tx).await
|
hooks(request, token, value_tx).await
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
.await
|
.await
|
||||||
|
@ -170,7 +170,7 @@ async fn main() -> Result<!, Error> {
|
||||||
}
|
}
|
||||||
wh = value_rx.recv() => {
|
wh = value_rx.recv() => {
|
||||||
if let Some(Hook::Gitlab(hook)) = wh {
|
if let Some(Hook::Gitlab(hook)) = wh {
|
||||||
client.webhook(hook).await
|
client.hook(hook).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::webhook::{ForgejoHook, GitlabHook, Hook};
|
use crate::hook::{ForgejoHook, GitlabHook, Hook};
|
||||||
|
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
@ -41,7 +41,7 @@ fn error_res<E: std::fmt::Debug>(e: E) -> Result<Response<Full<Bytes>>, Infallib
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn webhooks_inner(req: Request<Incoming>, token: &str) -> Result<Hook, Error> {
|
async fn hooks_inner(req: Request<Incoming>, token: &str) -> Result<Hook, Error> {
|
||||||
match req.method() {
|
match req.method() {
|
||||||
&Method::POST => (),
|
&Method::POST => (),
|
||||||
_ => return Err(Error::MethodMismatch),
|
_ => return Err(Error::MethodMismatch),
|
||||||
|
@ -96,12 +96,12 @@ async fn webhooks_inner(req: Request<Incoming>, token: &str) -> Result<Hook, Err
|
||||||
Err(Error::InvalidRequest)
|
Err(Error::InvalidRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn webhooks(
|
pub async fn hooks(
|
||||||
req: Request<Incoming>,
|
req: Request<Incoming>,
|
||||||
token: &str,
|
token: &str,
|
||||||
value_tx: Arc<Mutex<UnboundedSender<Hook>>>,
|
value_tx: Arc<Mutex<UnboundedSender<Hook>>>,
|
||||||
) -> Result<Response<Full<Bytes>>, Infallible> {
|
) -> Result<Response<Full<Bytes>>, Infallible> {
|
||||||
match webhooks_inner(req, token).await {
|
match hooks_inner(req, token).await {
|
||||||
Ok(wh) => {
|
Ok(wh) => {
|
||||||
debug!("Passed: {:?}", wh);
|
debug!("Passed: {:?}", wh);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue