feat: [CODE-2425]: Add webhook and trigger for all comment types (#2815)

* feat: [CODE-2425]: Arg format
* Merge branch 'main' into akp/CODE-2425
* feat: [CODE-2425]: return immediately in notification service if its a code-comment
* feat: [CODE-2425]: send gitness comment type
* Merge branch 'main' into akp/CODE-2425
* feat: [CODE-2425]: Add webhook and trigger for all comment types
This commit is contained in:
Akhilesh Pandey 2024-10-30 16:32:06 +00:00 committed by Harness
parent d79a1a290c
commit b848c642fc
4 changed files with 18 additions and 6 deletions

View File

@ -220,9 +220,14 @@ func (c *Controller) CommentCreate(
log.Ctx(ctx).Warn().Err(err).Msg("failed to publish PR changed event")
}
// if it's a regular comment publish a comment create event
if act.Type == enum.PullReqActivityTypeComment && act.Kind == enum.PullReqActivityKindComment {
c.reportCommentCreated(ctx, pr, session.Principal.ID, act.ID, act.IsReply())
// publish event for all comments
if act.Type == enum.PullReqActivityTypeComment || act.Type == enum.PullReqActivityTypeCodeComment {
c.reportCommentCreated(
ctx,
pr,
session.Principal.ID,
act.ID, act.IsReply(),
)
}
err = c.instrumentation.Track(ctx, instrument.Event{

View File

@ -21,6 +21,7 @@ import (
pullreqevents "github.com/harness/gitness/app/events/pullreq"
"github.com/harness/gitness/events"
"github.com/harness/gitness/types"
gitnessenum "github.com/harness/gitness/types/enum"
)
type CommentPayload struct {
@ -106,6 +107,10 @@ func (s *Service) processCommentCreatedEvent(
return nil, nil, nil, nil, fmt.Errorf("failed to fetch activity from pullReqActivityStore: %w", err)
}
if activity.Type != gitnessenum.PullReqActivityTypeComment {
return nil, nil, nil, nil, fmt.Errorf("code-comments are not supported currently")
}
commenter, err := s.principalInfoView.Find(ctx, activity.CreatedBy)
if err != nil {
return nil, nil, nil, nil, fmt.Errorf("failed to fetch commenter from principalInfoView: %w", err)

View File

@ -359,6 +359,7 @@ func (s *Service) handleEventPullReqComment(
Text: activity.Text,
ID: activity.ID,
ParentID: activity.ParentID,
Kind: activity.Kind,
},
},
}, nil

View File

@ -299,9 +299,10 @@ type ReferenceInfo struct {
}
type CommentInfo struct {
ID int64 `json:"id"`
ParentID *int64 `json:"parent_id,omitempty"`
Text string `json:"text"`
ID int64 `json:"id"`
ParentID *int64 `json:"parent_id,omitempty"`
Text string `json:"text"`
Kind enum.PullReqActivityKind `json:"kind"`
}
type LabelInfo struct {