MCPcopy Index your code
hub / github.com/git-bug/git-bug / Apply

Method Apply

entities/bug/op_edit_comment.go:32–82  ·  view source on GitHub ↗
(snapshot *Snapshot)

Source from the content-addressed store, hash-verified

30}
31
32func (op *EditCommentOperation) Apply(snapshot *Snapshot) {
33 // Todo: currently any message can be edited, even by a different author
34 // crypto signature are needed.
35
36 // Recreate the combined Id to match on
37 combinedId := entity.CombineIds(snapshot.Id(), op.Target)
38
39 var target TimelineItem
40 for i, item := range snapshot.Timeline {
41 if item.CombinedId() == combinedId {
42 target = snapshot.Timeline[i]
43 break
44 }
45 }
46
47 if target == nil {
48 // Target not found, edit is a no-op
49 return
50 }
51
52 comment := Comment{
53 combinedId: combinedId,
54 targetId: op.Target,
55 Message: op.Message,
56 Files: op.Files,
57 unixTime: timestamp.Timestamp(op.UnixTime),
58 }
59
60 switch target := target.(type) {
61 case *CreateTimelineItem:
62 target.Append(comment)
63 case *AddCommentTimelineItem:
64 target.Append(comment)
65 default:
66 // somehow, the target matched on something that is not a comment
67 // we make the op a no-op
68 return
69 }
70
71 snapshot.addActor(op.Author())
72
73 // Updating the corresponding comment
74
75 for i := range snapshot.Comments {
76 if snapshot.Comments[i].CombinedId() == combinedId {
77 snapshot.Comments[i].Message = op.Message
78 snapshot.Comments[i].Files = op.Files
79 break
80 }
81 }
82}
83
84func (op *EditCommentOperation) GetFiles() []repository.Hash {
85 return op.Files

Callers

nothing calls this directly

Calls 7

CombineIdsFunction · 0.92
TimestampTypeAlias · 0.92
addActorMethod · 0.80
IdMethod · 0.65
CombinedIdMethod · 0.65
AppendMethod · 0.65
AuthorMethod · 0.65

Tested by

no test coverage detected