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

Function updateCommitReferencesToIssues

internal/database/actions.go:315–446  ·  view source on GitHub ↗

updateCommitReferencesToIssues checks if issues are manipulated by commit message.

(doer *User, repo *Repository, commits []*PushCommit)

Source from the content-addressed store, hash-verified

313
314// updateCommitReferencesToIssues checks if issues are manipulated by commit message.
315func updateCommitReferencesToIssues(doer *User, repo *Repository, commits []*PushCommit) error {
316 trimRightNonDigits := func(c rune) bool {
317 return !unicode.IsDigit(c)
318 }
319
320 // Commits are appended in the reverse order.
321 for i := len(commits) - 1; i >= 0; i-- {
322 c := commits[i]
323
324 refMarked := make(map[int64]bool)
325 for _, ref := range issueReferencePattern.FindAllString(c.Message, -1) {
326 ref = strings.TrimSpace(ref)
327 ref = strings.TrimRightFunc(ref, trimRightNonDigits)
328
329 if ref == "" {
330 continue
331 }
332
333 // Add repo name if missing
334 if ref[0] == '#' {
335 ref = fmt.Sprintf("%s%s", repo.FullName(), ref)
336 } else if !strings.Contains(ref, "/") {
337 // FIXME: We don't support User#ID syntax yet
338 continue
339 }
340
341 issue, err := GetIssueByRef(ref)
342 if err != nil {
343 if IsErrIssueNotExist(err) {
344 continue
345 }
346 return err
347 }
348
349 if refMarked[issue.ID] {
350 continue
351 }
352 refMarked[issue.ID] = true
353
354 msgLines := strings.Split(c.Message, "\n")
355 shortMsg := msgLines[0]
356 if len(msgLines) > 2 {
357 shortMsg += "..."
358 }
359 message := fmt.Sprintf(`<a href="%s/commit/%s">%s</a>`, repo.Link(), c.Sha1, shortMsg)
360 if err = CreateRefComment(doer, repo, issue, message, c.Sha1); err != nil {
361 return err
362 }
363 }
364
365 refMarked = make(map[int64]bool)
366 // FIXME: Can merge this and the next for loop to a common function.
367 for _, ref := range issueCloseKeywordsPattern.FindAllString(c.Message, -1) {
368 ref = ref[strings.IndexByte(ref, byte(' '))+1:]
369 ref = strings.TrimRightFunc(ref, trimRightNonDigits)
370
371 if ref == "" {
372 continue

Callers 1

CommitRepoMethod · 0.85

Calls 8

GetIssueByRefFunction · 0.85
IsErrIssueNotExistFunction · 0.85
CreateRefCommentFunction · 0.85
FindAllStringMethod · 0.80
SplitMethod · 0.80
FullNameMethod · 0.65
LinkMethod · 0.45
ChangeStatusMethod · 0.45

Tested by

no test coverage detected