MCPcopy Create free account
hub / github.com/gogs/gogs / UpdateCommentContent

Function UpdateCommentContent

internal/route/repo/issue.go:922–964  ·  view source on GitHub ↗
(c *context.Context)

Source from the content-addressed store, hash-verified

920}
921
922func UpdateCommentContent(c *context.Context) {
923 comment, err := database.GetCommentByID(c.ParamsInt64(":id"))
924 if err != nil {
925 c.NotFoundOrError(err, "get comment by ID")
926 return
927 }
928
929 issue, err := database.GetIssueByID(comment.IssueID)
930 if err != nil {
931 c.NotFoundOrError(err, "get issue by ID")
932 return
933 }
934
935 if issue.RepoID != c.Repo.Repository.ID {
936 c.NotFound()
937 return
938 }
939
940 if c.UserID() != comment.PosterID && !c.Repo.IsAdmin() {
941 c.NotFound()
942 return
943 } else if comment.Type != database.CommentTypeComment {
944 c.Status(http.StatusNoContent)
945 return
946 }
947
948 oldContent := comment.Content
949 comment.Content = c.Query("content")
950 if comment.Content == "" {
951 c.JSONSuccess(map[string]any{
952 "content": "",
953 })
954 return
955 }
956 if err = database.UpdateComment(c.User, comment, oldContent); err != nil {
957 c.Error(err, "update comment")
958 return
959 }
960
961 c.JSONSuccess(map[string]string{
962 "content": string(markup.Markdown(comment.Content, c.Query("context"), c.Repo.Repository.ComposeMetas())),
963 })
964}
965
966func DeleteComment(c *context.Context) {
967 comment, err := database.GetCommentByID(c.ParamsInt64(":id"))

Callers

nothing calls this directly

Calls 12

GetCommentByIDFunction · 0.92
GetIssueByIDFunction · 0.92
UpdateCommentFunction · 0.92
MarkdownFunction · 0.92
stringFunction · 0.85
UserIDMethod · 0.80
IsAdminMethod · 0.80
JSONSuccessMethod · 0.80
NotFoundMethod · 0.65
ComposeMetasMethod · 0.65
NotFoundOrErrorMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected