Add support for issue comments
Signed-off-by: pep <pep@bouah.net>
This commit is contained in:
parent
96353016d4
commit
f90b152abf
1 changed files with 37 additions and 3 deletions
|
|
@ -13,7 +13,9 @@
|
|||
// 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, Issue, IssueAction, Push, Repository, User};
|
||||
use crate::hooks::types::{
|
||||
Commit, Hook, Issue, IssueAction, IssueAttrs, Note, Push, Repository, User,
|
||||
};
|
||||
use crate::Error;
|
||||
|
||||
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 {
|
||||
fn from(other: FjIssueAction) -> IssueAction {
|
||||
match other {
|
||||
FjIssueAction::Opened => IssueAction::Open,
|
||||
FjIssueAction::Created | FjIssueAction::Opened => IssueAction::Open,
|
||||
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 {
|
||||
type Error = Error;
|
||||
|
||||
|
|
@ -68,7 +94,15 @@ impl TryFrom<ForgejoHook> for Hook {
|
|||
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),
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue