MCPcopy
hub / github.com/harness/harness / CommentUpdate

Method CommentUpdate

app/api/controller/pullreq/comment_update.go:48–122  ·  view source on GitHub ↗

CommentUpdate updates a pull request comment.

(
	ctx context.Context,
	session *auth.Session,
	repoRef string,
	prNum int64,
	commentID int64,
	in *CommentUpdateInput,
)

Source from the content-addressed store, hash-verified

46
47// CommentUpdate updates a pull request comment.
48func (c *Controller) CommentUpdate(
49 ctx context.Context,
50 session *auth.Session,
51 repoRef string,
52 prNum int64,
53 commentID int64,
54 in *CommentUpdateInput,
55) (*types.PullReqActivity, error) {
56 if err := in.Sanitize(); err != nil {
57 return nil, err
58 }
59
60 repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoReview)
61 if err != nil {
62 return nil, fmt.Errorf("failed to acquire access to repo: %w", err)
63 }
64
65 pr, err := c.pullreqStore.FindByNumber(ctx, repo.ID, prNum)
66 if err != nil {
67 return nil, fmt.Errorf("failed to find pull request by number: %w", err)
68 }
69
70 act, err := c.getCommentCheckEditAccess(ctx, session, pr, commentID)
71 if err != nil {
72 return nil, fmt.Errorf("failed to get comment: %w", err)
73 }
74
75 if !in.hasChanges(act) {
76 return act, nil
77 }
78
79 // fetch parent activity
80 var parentAct *types.PullReqActivity
81 if act.IsReply() {
82 parentAct, err = c.activityStore.Find(ctx, *act.ParentID)
83 if err != nil {
84 return nil, fmt.Errorf("failed to find parent pull request activity: %w", err)
85 }
86 }
87
88 // generate all metadata updates
89 var metadataUpdates []types.PullReqActivityMetadataUpdate
90
91 metadataUpdates, principalInfos, err := c.appendMetadataUpdateForMentions(
92 ctx, metadataUpdates, in.Text,
93 )
94 if err != nil {
95 return nil, fmt.Errorf("failed to update metadata for mentions: %w", err)
96 }
97
98 // suggestion metadata in case of code comments or code comment replies (don't restrict to either side for now).
99 if act.IsValidCodeComment() || (act.IsReply() && parentAct.IsValidCodeComment()) {
100 metadataUpdates = appendMetadataUpdateForSuggestions(metadataUpdates, in.Text)
101 }
102
103 act, err = c.activityStore.UpdateOptLock(ctx, act, func(act *types.PullReqActivity) error {
104 now := time.Now().UnixMilli()
105 act.Edited = now

Callers 1

HandleCommentUpdateFunction · 0.80

Calls 15

getRepoCheckAccessMethod · 0.95
IsValidCodeCommentMethod · 0.95
reportCommentUpdatedMethod · 0.95
UpdateMetadataMethod · 0.80
SanitizeMethod · 0.65
FindByNumberMethod · 0.65
FindMethod · 0.65
UpdateOptLockMethod · 0.65
PublishMethod · 0.65

Tested by

no test coverage detected