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

Function createComment

internal/database/comment.go:187–291  ·  view source on GitHub ↗
(e *xorm.Session, opts *CreateCommentOptions)

Source from the content-addressed store, hash-verified

185}
186
187func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err error) {
188 comment := &Comment{
189 Type: opts.Type,
190 PosterID: opts.Doer.ID,
191 Poster: opts.Doer,
192 IssueID: opts.Issue.ID,
193 CommitID: opts.CommitID,
194 CommitSHA: opts.CommitSHA,
195 Line: opts.LineNum,
196 Content: opts.Content,
197 }
198 if _, err = e.Insert(comment); err != nil {
199 return nil, err
200 }
201
202 // Compose comment action, could be plain comment, close or reopen issue/pull request.
203 // This object will be used to notify watchers in the end of function.
204 act := &Action{
205 ActUserID: opts.Doer.ID,
206 ActUserName: opts.Doer.Name,
207 Content: fmt.Sprintf("%d|%s", opts.Issue.Index, strings.Split(opts.Content, "\n")[0]),
208 RepoID: opts.Repo.ID,
209 RepoUserName: opts.Repo.Owner.Name,
210 RepoName: opts.Repo.Name,
211 IsPrivate: opts.Repo.IsPrivate,
212 }
213
214 // Check comment type.
215 switch opts.Type {
216 case CommentTypeComment:
217 act.OpType = ActionCommentIssue
218
219 if _, err = e.Exec("UPDATE `issue` SET num_comments=num_comments+1 WHERE id=?", opts.Issue.ID); err != nil {
220 return nil, err
221 }
222
223 // Check attachments
224 attachments := make([]*Attachment, 0, len(opts.Attachments))
225 for _, uuid := range opts.Attachments {
226 attach, err := getAttachmentByUUID(e, uuid)
227 if err != nil {
228 if IsErrAttachmentNotExist(err) {
229 continue
230 }
231 return nil, errors.Newf("getAttachmentByUUID [%s]: %v", uuid, err)
232 }
233 attachments = append(attachments, attach)
234 }
235
236 for i := range attachments {
237 attachments[i].IssueID = opts.Issue.ID
238 attachments[i].CommentID = comment.ID
239 // No assign value could be 0, so ignore AllCols().
240 if _, err = e.ID(attachments[i].ID).Update(attachments[i]); err != nil {
241 return nil, errors.Newf("update attachment [%d]: %v", attachments[i].ID, err)
242 }
243 }
244

Callers 2

createStatusCommentFunction · 0.85
CreateCommentFunction · 0.85

Calls 12

mailParticipantsMethod · 0.95
loadAttributesMethod · 0.95
getAttachmentByUUIDFunction · 0.85
IsErrAttachmentNotExistFunction · 0.85
appendFunction · 0.85
notifyWatchersFunction · 0.85
InsertMethod · 0.80
SplitMethod · 0.80
ExecMethod · 0.80
UpdateMethod · 0.65
IDMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected