Attempt at Forgejo Webhook support
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
2ef603151e
commit
8e94435604
7 changed files with 124 additions and 27 deletions
|
|
@ -13,12 +13,27 @@
|
|||
// 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};
|
||||
pub use forgejo_hooks::Hook as ForgejoHook;
|
||||
pub use gitlab::webhooks::{
|
||||
IssueAction, MergeRequestAction, WebHook as GitlabHook, WikiPageAction,
|
||||
};
|
||||
use log::debug;
|
||||
|
||||
pub fn format_webhook(wh: &WebHook) -> Option<String> {
|
||||
Some(match wh {
|
||||
WebHook::Push(push) => {
|
||||
#[derive(Debug)]
|
||||
pub enum Hook {
|
||||
Forgejo(ForgejoHook),
|
||||
Gitlab(GitlabHook),
|
||||
}
|
||||
|
||||
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) => {
|
||||
if push.ref_ != "refs/heads/main" {
|
||||
// Ignore: Action not on 'main' branch
|
||||
return None;
|
||||
|
|
@ -45,7 +60,7 @@ pub fn format_webhook(wh: &WebHook) -> Option<String> {
|
|||
}
|
||||
text
|
||||
}
|
||||
WebHook::Issue(issue) => {
|
||||
GitlabHook::Issue(issue) => {
|
||||
let action = match issue.object_attributes.action {
|
||||
Some(IssueAction::Update) => return None,
|
||||
Some(IssueAction::Open) => "opened",
|
||||
|
|
@ -68,7 +83,7 @@ pub fn format_webhook(wh: &WebHook) -> Option<String> {
|
|||
.unwrap_or("".to_owned())
|
||||
)
|
||||
}
|
||||
WebHook::MergeRequest(merge_req) => {
|
||||
GitlabHook::MergeRequest(merge_req) => {
|
||||
let action = match merge_req.object_attributes.action {
|
||||
Some(MergeRequestAction::Update) => return None,
|
||||
Some(MergeRequestAction::Open) => "opened",
|
||||
|
|
@ -93,7 +108,7 @@ pub fn format_webhook(wh: &WebHook) -> Option<String> {
|
|||
.unwrap_or("".to_owned())
|
||||
)
|
||||
}
|
||||
WebHook::Note(note) => {
|
||||
GitlabHook::Note(note) => {
|
||||
if let Some(_) = note.snippet {
|
||||
return None;
|
||||
}
|
||||
|
|
@ -120,11 +135,11 @@ pub fn format_webhook(wh: &WebHook) -> Option<String> {
|
|||
unreachable!()
|
||||
}
|
||||
}
|
||||
WebHook::Build(build) => {
|
||||
GitlabHook::Build(build) => {
|
||||
println!("Build: {:?}", build);
|
||||
return None;
|
||||
}
|
||||
WebHook::WikiPage(page) => {
|
||||
GitlabHook::WikiPage(page) => {
|
||||
let action = match page.object_attributes.action {
|
||||
WikiPageAction::Update => "updated",
|
||||
WikiPageAction::Create => "created",
|
||||
|
|
@ -138,7 +153,7 @@ pub fn format_webhook(wh: &WebHook) -> Option<String> {
|
|||
page.object_attributes.url,
|
||||
)
|
||||
}
|
||||
_wh => {
|
||||
_glh => {
|
||||
debug!("Webhook not supported");
|
||||
return None;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue