Add support for issue comments

Signed-off-by: pep <pep@bouah.net>
This commit is contained in:
pep 2025-05-03 17:33:16 +02:00
commit f90b152abf
No known key found for this signature in database
GPG key ID: DEDA74AEECA9D0F2

View file

@ -13,7 +13,9 @@
// 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::hooks::types::{Commit, Hook, Issue, IssueAction, Push, Repository, User}; use crate::hooks::types::{
Commit, Hook, Issue, IssueAction, IssueAttrs, Note, Push, Repository, User,
};
use crate::Error; use crate::Error;
pub use ::forgejo_hooks::{Hook as ForgejoHook, Issue as FjIssue, IssueAction as FjIssueAction}; pub use ::forgejo_hooks::{Hook as ForgejoHook, Issue as FjIssue, IssueAction as FjIssueAction};
@ -21,7 +23,7 @@ pub use ::forgejo_hooks::{Hook as ForgejoHook, Issue as FjIssue, IssueAction as
impl From<FjIssueAction> for IssueAction { impl From<FjIssueAction> for IssueAction {
fn from(other: FjIssueAction) -> IssueAction { fn from(other: FjIssueAction) -> IssueAction {
match other { match other {
FjIssueAction::Opened => IssueAction::Open, FjIssueAction::Created | FjIssueAction::Opened => IssueAction::Open,
FjIssueAction::Edited => IssueAction::Update, FjIssueAction::Edited => IssueAction::Update,
} }
} }
@ -44,6 +46,30 @@ impl From<FjIssue> for Issue {
} }
} }
impl From<FjIssue> for Note {
fn from(other: FjIssue) -> Note {
Note {
issue: Some(IssueAttrs {
id: other.issue.number as u64,
title: other.issue.title,
}),
commit: None,
merge_request: None,
snippet: false,
author: User {
name: other.issue.user.login,
},
repository: Repository {
name: other.repository.name,
},
url: other
.comment
.map(|c| c.html_url)
.unwrap_or(other.issue.html_url),
}
}
}
impl TryFrom<ForgejoHook> for Hook { impl TryFrom<ForgejoHook> for Hook {
type Error = Error; type Error = Error;
@ -68,7 +94,15 @@ impl TryFrom<ForgejoHook> for Hook {
name: push.pusher.username, name: push.pusher.username,
}, },
}), }),
ForgejoHook::Issue(issue) => Hook::Issue(issue.into()), ForgejoHook::Issue(issue) => {
log::debug!("FOO: issue: {:?}", issue);
// TODO: Handle is_pull
if issue.comment.is_none() {
Hook::Issue(issue.into())
} else {
Hook::Note(issue.into())
}
}
_ => return Err(Error::UnsupportedHookConversion), _ => return Err(Error::UnsupportedHookConversion),
}) })
} }