Connect to XMPP, join room, send message
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
36673bd5bf
commit
0cba90dd68
5 changed files with 257 additions and 19 deletions
114
src/webhook.rs
Normal file
114
src/webhook.rs
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
// Copyright (C) 2023-2099 The crate authors.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Affero General Public License as published by the
|
||||
// Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||
// for more details.
|
||||
//
|
||||
// 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/>.
|
||||
|
||||
pub use gitlab::webhooks::{IssueAction, MergeRequestAction, WebHook, WikiPageAction};
|
||||
use log::debug;
|
||||
|
||||
pub fn format_webhook(wh: &WebHook) -> Option<String> {
|
||||
Some(match wh {
|
||||
WebHook::Push(push) => {
|
||||
let mut text = format!(
|
||||
"{} pushed {} commits to {} branch {}",
|
||||
push.user_name,
|
||||
push.commits.len(),
|
||||
push.project.name,
|
||||
push.ref_
|
||||
);
|
||||
for commit in &push.commits {
|
||||
match commit.message.lines().nth(0) {
|
||||
Some(subject) => {
|
||||
text = format!("{}\n• {} <{}>", text, subject, commit.url);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
text
|
||||
}
|
||||
WebHook::Issue(issue) => {
|
||||
let action = match issue.object_attributes.action {
|
||||
Some(IssueAction::Update) => "updated",
|
||||
Some(IssueAction::Open) => "opened",
|
||||
Some(IssueAction::Close) => "closed",
|
||||
Some(IssueAction::Reopen) => "reopened",
|
||||
None => return None,
|
||||
};
|
||||
format!(
|
||||
"{} {} issue {} in {}: {}{}",
|
||||
issue.user.name,
|
||||
action,
|
||||
issue.object_attributes.iid,
|
||||
issue.project.name,
|
||||
issue.object_attributes.title,
|
||||
issue
|
||||
.object_attributes
|
||||
.url
|
||||
.as_ref()
|
||||
.map(|url| format!(" <{}>", url))
|
||||
.unwrap_or("".to_owned())
|
||||
)
|
||||
}
|
||||
WebHook::MergeRequest(merge_req) => {
|
||||
let action = match merge_req.object_attributes.action {
|
||||
Some(MergeRequestAction::Update) => "updated",
|
||||
Some(MergeRequestAction::Open) => "opened",
|
||||
Some(MergeRequestAction::Close) => "closed",
|
||||
Some(MergeRequestAction::Reopen) => "reopened",
|
||||
Some(MergeRequestAction::Merge) => "merged",
|
||||
None => return None,
|
||||
_ => todo!(),
|
||||
};
|
||||
format!(
|
||||
"{} {} merge request {} in {}: {}{}",
|
||||
merge_req.user.name,
|
||||
action,
|
||||
merge_req.object_attributes.iid,
|
||||
merge_req.project.name,
|
||||
merge_req.object_attributes.title,
|
||||
merge_req
|
||||
.object_attributes
|
||||
.url
|
||||
.as_ref()
|
||||
.map(|url| format!(" <{}>", url))
|
||||
.unwrap_or("".to_owned())
|
||||
)
|
||||
}
|
||||
WebHook::Note(note) => {
|
||||
println!("Note: {:?}", note);
|
||||
return None;
|
||||
}
|
||||
WebHook::Build(build) => {
|
||||
println!("Build: {:?}", build);
|
||||
return None;
|
||||
}
|
||||
WebHook::WikiPage(page) => {
|
||||
let action = match page.object_attributes.action {
|
||||
WikiPageAction::Update => "updated",
|
||||
WikiPageAction::Create => "created",
|
||||
};
|
||||
format!(
|
||||
"{} {} {} wiki page {} <{}>",
|
||||
page.user.name,
|
||||
action,
|
||||
page.project.name,
|
||||
page.object_attributes.title,
|
||||
page.object_attributes.url,
|
||||
)
|
||||
}
|
||||
_wh => {
|
||||
debug!("Webhook not supported");
|
||||
return None;
|
||||
}
|
||||
})
|
||||
}
|
||||
Loading…
Reference in a new issue