Applied suggested code changes

* better commented KeywordsFound bitmask constants
* populate issueKeywordsToFind variable at point of definition rather
than in init()
* add needed `xorm:"-"` statements to the fields that were added to
Comment
* also move calculation of uniqueID out of loop
This commit is contained in:
Keith Rutkowski 2018-04-07 10:33:51 -04:00
parent b216bcf335
commit 0b6e2cd8cc
2 changed files with 19 additions and 23 deletions

View File

@ -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 {

View File

@ -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)"`