diff --git a/models/action.go b/models/action.go index 740bcd0d0..0b374bb27 100644 --- a/models/action.go +++ b/models/action.go @@ -54,9 +54,9 @@ type KeywordsFoundMaskType int // Possible bitmask types for keywords that can be found. const ( - KeywordsFoundReference KeywordsFoundMaskType = 1 << iota // 1 - KeywordsFoundReopen // 2 - KeywordsFoundClose // 4 + KeywordsFoundReference KeywordsFoundMaskType = 1 << iota // 1 = 1 << 0 + KeywordsFoundReopen // 2 = 1 << 1 + KeywordsFoundClose // 4 = 1 << 2 ) // IssueKeywordsToFind represents a pairing of a pattern to use to find keywords in message and the keywords bitmask value. @@ -71,16 +71,6 @@ var ( issueCloseKeywords = []string{"close", "closes", "closed", "fix", "fixes", "fixed", "resolve", "resolves", "resolved"} issueReopenKeywords = []string{"reopen", "reopens", "reopened"} - issueKeywordsToFind []*IssueKeywordsToFind -) - -const issueRefRegexpStr = `(?:\S+/\S=)?#\d+` - -func assembleKeywordsPattern(words []string) string { - return fmt.Sprintf(`(?i)(?:%s) %s`, strings.Join(words, "|"), issueRefRegexpStr) -} - -func init() { // populate with details to find keywords for reference, reopen, close issueKeywordsToFind = []*IssueKeywordsToFind{ { @@ -96,6 +86,12 @@ func init() { KeywordsFoundMask: KeywordsFoundClose, }, } +) + +const issueRefRegexpStr = `(?:\S+/\S=)?#\d+` + +func assembleKeywordsPattern(words []string) string { + return fmt.Sprintf(`(?i)(?:%s) %s`, strings.Join(words, "|"), issueRefRegexpStr) } // Action represents user operation type and other information to @@ -489,6 +485,11 @@ func UpdateIssuesComment(doer *User, repo *Repository, commentIssue *Issue, comm refString = commentIssue.Title + ": " + commentIssue.Content } + uniqueID := fmt.Sprintf("%d", commentIssue.ID) + if comment != nil { + uniqueID += fmt.Sprintf("@%d", comment.ID) + } + refs, err := findIssueReferencesInString(refString, repo) if err != nil { return err @@ -504,11 +505,6 @@ func UpdateIssuesComment(doer *User, repo *Repository, commentIssue *Issue, comm } if (mask & KeywordsFoundReference) == KeywordsFoundReference { - uniqueID := fmt.Sprintf("%d", commentIssue.ID) - if comment != nil { - uniqueID += fmt.Sprintf("@%d", comment.ID) - } - if comment != nil { err = CreateCommentRefComment(doer, repo, issue, fmt.Sprintf(`%d`, comment.ID), base.EncodeSha1(uniqueID)) } else if commentIssue.IsPull { diff --git a/models/issue_comment.go b/models/issue_comment.go index d337fcedf..f52c47c40 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -109,11 +109,11 @@ type Comment struct { UpdatedUnix util.TimeStamp `xorm:"INDEX updated"` // Reference issue in commit message, comments, issues, or pull requests - RefExists bool - RefIssue *Issue - RefComment *Comment - RefMessage string - RefURL string + RefExists bool `xorm:"-"` + RefIssue *Issue `xorm:"-"` + RefComment *Comment `xorm:"-"` + RefMessage string `xorm:"-"` + RefURL string `xorm:"-"` // the commit SHA for commit refs otherwise a SHA of a unique reference identifier CommitSHA string `xorm:"VARCHAR(40)"`