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:
parent
b216bcf335
commit
0b6e2cd8cc
|
@ -54,9 +54,9 @@ type KeywordsFoundMaskType int
|
||||||
|
|
||||||
// Possible bitmask types for keywords that can be found.
|
// Possible bitmask types for keywords that can be found.
|
||||||
const (
|
const (
|
||||||
KeywordsFoundReference KeywordsFoundMaskType = 1 << iota // 1
|
KeywordsFoundReference KeywordsFoundMaskType = 1 << iota // 1 = 1 << 0
|
||||||
KeywordsFoundReopen // 2
|
KeywordsFoundReopen // 2 = 1 << 1
|
||||||
KeywordsFoundClose // 4
|
KeywordsFoundClose // 4 = 1 << 2
|
||||||
)
|
)
|
||||||
|
|
||||||
// IssueKeywordsToFind represents a pairing of a pattern to use to find keywords in message and the keywords bitmask value.
|
// 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"}
|
issueCloseKeywords = []string{"close", "closes", "closed", "fix", "fixes", "fixed", "resolve", "resolves", "resolved"}
|
||||||
issueReopenKeywords = []string{"reopen", "reopens", "reopened"}
|
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
|
// populate with details to find keywords for reference, reopen, close
|
||||||
issueKeywordsToFind = []*IssueKeywordsToFind{
|
issueKeywordsToFind = []*IssueKeywordsToFind{
|
||||||
{
|
{
|
||||||
|
@ -96,6 +86,12 @@ func init() {
|
||||||
KeywordsFoundMask: KeywordsFoundClose,
|
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
|
// 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
|
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)
|
refs, err := findIssueReferencesInString(refString, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -504,11 +505,6 @@ func UpdateIssuesComment(doer *User, repo *Repository, commentIssue *Issue, comm
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mask & KeywordsFoundReference) == KeywordsFoundReference {
|
if (mask & KeywordsFoundReference) == KeywordsFoundReference {
|
||||||
uniqueID := fmt.Sprintf("%d", commentIssue.ID)
|
|
||||||
if comment != nil {
|
|
||||||
uniqueID += fmt.Sprintf("@%d", comment.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
if comment != nil {
|
if comment != nil {
|
||||||
err = CreateCommentRefComment(doer, repo, issue, fmt.Sprintf(`%d`, comment.ID), base.EncodeSha1(uniqueID))
|
err = CreateCommentRefComment(doer, repo, issue, fmt.Sprintf(`%d`, comment.ID), base.EncodeSha1(uniqueID))
|
||||||
} else if commentIssue.IsPull {
|
} else if commentIssue.IsPull {
|
||||||
|
|
|
@ -109,11 +109,11 @@ type Comment struct {
|
||||||
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
|
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
|
||||||
|
|
||||||
// Reference issue in commit message, comments, issues, or pull requests
|
// Reference issue in commit message, comments, issues, or pull requests
|
||||||
RefExists bool
|
RefExists bool `xorm:"-"`
|
||||||
RefIssue *Issue
|
RefIssue *Issue `xorm:"-"`
|
||||||
RefComment *Comment
|
RefComment *Comment `xorm:"-"`
|
||||||
RefMessage string
|
RefMessage string `xorm:"-"`
|
||||||
RefURL string
|
RefURL string `xorm:"-"`
|
||||||
// the commit SHA for commit refs otherwise a SHA of a unique reference identifier
|
// the commit SHA for commit refs otherwise a SHA of a unique reference identifier
|
||||||
CommitSHA string `xorm:"VARCHAR(40)"`
|
CommitSHA string `xorm:"VARCHAR(40)"`
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user