Add support for ForgejoHook::Issue

Signed-off-by: pep <pep@bouah.net>
This commit is contained in:
pep 2024-09-04 23:43:30 +02:00
parent 468b42abfd
commit fc0b13079f

View file

@ -13,10 +13,36 @@
// 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/>.
use crate::hooks::types::{Commit, Hook, Push, Repository, User};
use crate::hooks::types::{Commit, Hook, Issue, IssueAction, Push, Repository, User};
use crate::Error;
pub use ::forgejo_hooks::Hook as ForgejoHook;
pub use ::forgejo_hooks::{Hook as ForgejoHook, Issue as FjIssue, IssueAction as FjIssueAction};
impl From<FjIssueAction> for IssueAction {
fn from(other: FjIssueAction) -> IssueAction {
match other {
FjIssueAction::Opened => IssueAction::Open,
FjIssueAction::Edited => IssueAction::Update,
}
}
}
impl From<FjIssue> for Issue {
fn from(other: FjIssue) -> Issue {
Issue {
id: other.number,
action: Some(other.action.into()),
title: other.issue.title,
author: User {
name: other.issue.user.login,
},
repository: Repository {
name: other.repository.name,
},
url: None,
}
}
}
impl TryFrom<ForgejoHook> for Hook {
type Error = Error;
@ -42,6 +68,7 @@ impl TryFrom<ForgejoHook> for Hook {
name: push.pusher.username,
},
}),
ForgejoHook::Issue(issue) => Hook::Issue(issue.into()),
_ => return Err(Error::UnsupportedHookConversion),
})
}