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") log.Ctx(ctx).Warn().Err(err).Msg("failed to publish PR changed event")
} }
// if it's a regular comment publish a comment create event // publish event for all comments
if act.Type == enum.PullReqActivityTypeComment && act.Kind == enum.PullReqActivityKindComment { if act.Type == enum.PullReqActivityTypeComment || act.Type == enum.PullReqActivityTypeCodeComment {
c.reportCommentCreated(ctx, pr, session.Principal.ID, act.ID, act.IsReply()) c.reportCommentCreated(
ctx,
pr,
session.Principal.ID,
act.ID, act.IsReply(),
)
} }
err = c.instrumentation.Track(ctx, instrument.Event{ err = c.instrumentation.Track(ctx, instrument.Event{

View File

@ -21,6 +21,7 @@ import (
pullreqevents "github.com/harness/gitness/app/events/pullreq" pullreqevents "github.com/harness/gitness/app/events/pullreq"
"github.com/harness/gitness/events" "github.com/harness/gitness/events"
"github.com/harness/gitness/types" "github.com/harness/gitness/types"
gitnessenum "github.com/harness/gitness/types/enum"
) )
type CommentPayload struct { 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) 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) commenter, err := s.principalInfoView.Find(ctx, activity.CreatedBy)
if err != nil { if err != nil {
return nil, nil, nil, nil, fmt.Errorf("failed to fetch commenter from principalInfoView: %w", err) 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, Text: activity.Text,
ID: activity.ID, ID: activity.ID,
ParentID: activity.ParentID, ParentID: activity.ParentID,
Kind: activity.Kind,
}, },
}, },
}, nil }, nil

View File

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