Change variable names from KeywordsFound* to Keyword*
This commit is contained in:
parent
6c1a73a06d
commit
3be8911897
|
|
@ -49,20 +49,20 @@ const (
|
||||||
ActionDeleteBranch // 17
|
ActionDeleteBranch // 17
|
||||||
)
|
)
|
||||||
|
|
||||||
// KeywordsFoundMaskType represents the bitmask of types of keywords found in a message.
|
// KeywordMaskType represents the bitmask of types of keywords found in a message.
|
||||||
type KeywordsFoundMaskType int
|
type KeywordMaskType 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 = 1 << 0
|
KeywordReference KeywordMaskType = 1 << iota // 1 = 1 << 0
|
||||||
KeywordsFoundReopen // 2 = 1 << 1
|
KeywordReopen // 2 = 1 << 1
|
||||||
KeywordsFoundClose // 4 = 1 << 2
|
KeywordClose // 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.
|
||||||
type IssueKeywordsToFind struct {
|
type IssueKeywordsToFind struct {
|
||||||
Pattern *regexp.Regexp
|
Pattern *regexp.Regexp
|
||||||
KeywordsFoundMask KeywordsFoundMaskType
|
KeywordMask KeywordMaskType
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -74,16 +74,16 @@ var (
|
||||||
// populate with details to find keywords for reference, reopen, close
|
// populate with details to find keywords for reference, reopen, close
|
||||||
issueKeywordsToFind = []*IssueKeywordsToFind{
|
issueKeywordsToFind = []*IssueKeywordsToFind{
|
||||||
{
|
{
|
||||||
Pattern: regexp.MustCompile(issueRefRegexpStr),
|
Pattern: regexp.MustCompile(issueRefRegexpStr),
|
||||||
KeywordsFoundMask: KeywordsFoundReference,
|
KeywordMask: KeywordReference,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Pattern: regexp.MustCompile(assembleKeywordsPattern(issueReopenKeywords)),
|
Pattern: regexp.MustCompile(assembleKeywordsPattern(issueReopenKeywords)),
|
||||||
KeywordsFoundMask: KeywordsFoundReopen,
|
KeywordMask: KeywordReopen,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Pattern: regexp.MustCompile(assembleKeywordsPattern(issueCloseKeywords)),
|
Pattern: regexp.MustCompile(assembleKeywordsPattern(issueCloseKeywords)),
|
||||||
KeywordsFoundMask: KeywordsFoundClose,
|
KeywordMask: KeywordClose,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
@ -459,8 +459,8 @@ func getIssueFromRef(repo *Repository, ref string) (*Issue, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// findIssueReferencesInString iterates over the keywords to find in a message and accumulates the findings into refs
|
// findIssueReferencesInString iterates over the keywords to find in a message and accumulates the findings into refs
|
||||||
func findIssueReferencesInString(message string, repo *Repository) (map[int64]KeywordsFoundMaskType, error) {
|
func findIssueReferencesInString(message string, repo *Repository) (map[int64]KeywordMaskType, error) {
|
||||||
refs := make(map[int64]KeywordsFoundMaskType)
|
refs := make(map[int64]KeywordMaskType)
|
||||||
for _, kwToFind := range issueKeywordsToFind {
|
for _, kwToFind := range issueKeywordsToFind {
|
||||||
for _, ref := range kwToFind.Pattern.FindAllString(message, -1) {
|
for _, ref := range kwToFind.Pattern.FindAllString(message, -1) {
|
||||||
issue, err := getIssueFromRef(repo, ref)
|
issue, err := getIssueFromRef(repo, ref)
|
||||||
|
|
@ -469,7 +469,7 @@ func findIssueReferencesInString(message string, repo *Repository) (map[int64]Ke
|
||||||
}
|
}
|
||||||
|
|
||||||
if issue != nil {
|
if issue != nil {
|
||||||
refs[issue.ID] |= kwToFind.KeywordsFoundMask
|
refs[issue.ID] |= kwToFind.KeywordMask
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -504,7 +504,7 @@ func UpdateIssuesComment(doer *User, repo *Repository, commentIssue *Issue, comm
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mask & KeywordsFoundReference) == KeywordsFoundReference {
|
if (mask & KeywordReference) == KeywordReference {
|
||||||
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 {
|
||||||
|
|
@ -518,14 +518,14 @@ func UpdateIssuesComment(doer *User, repo *Repository, commentIssue *Issue, comm
|
||||||
}
|
}
|
||||||
|
|
||||||
if canOpenClose {
|
if canOpenClose {
|
||||||
// take no action if both KeywordsFoundClose and KeywordsFoundOpen are set
|
// take no action if both KeywordClose and KeywordOpen are set
|
||||||
if (mask & (KeywordsFoundReopen | KeywordsFoundClose)) == KeywordsFoundClose {
|
if (mask & (KeywordReopen | KeywordClose)) == KeywordClose {
|
||||||
if issue.RepoID == repo.ID && !issue.IsClosed {
|
if issue.RepoID == repo.ID && !issue.IsClosed {
|
||||||
if err = issue.ChangeStatus(doer, repo, true); err != nil {
|
if err = issue.ChangeStatus(doer, repo, true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (mask & (KeywordsFoundReopen | KeywordsFoundClose)) == KeywordsFoundReopen {
|
} else if (mask & (KeywordReopen | KeywordClose)) == KeywordReopen {
|
||||||
if issue.RepoID == repo.ID && issue.IsClosed {
|
if issue.RepoID == repo.ID && issue.IsClosed {
|
||||||
if err = issue.ChangeStatus(doer, repo, false); err != nil {
|
if err = issue.ChangeStatus(doer, repo, false); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -557,7 +557,7 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit, com
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mask & KeywordsFoundReference) == KeywordsFoundReference {
|
if (mask & KeywordReference) == KeywordReference {
|
||||||
message := fmt.Sprintf("%d %s", repo.ID, c.Sha1)
|
message := fmt.Sprintf("%d %s", repo.ID, c.Sha1)
|
||||||
if err = CreateCommitRefComment(doer, repo, issue, message, c.Sha1); err != nil {
|
if err = CreateCommitRefComment(doer, repo, issue, message, c.Sha1); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -565,14 +565,14 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit, com
|
||||||
}
|
}
|
||||||
|
|
||||||
if commitsAreMerged {
|
if commitsAreMerged {
|
||||||
// take no action if both KeywordsFoundClose and KeywordsFoundOpen are set
|
// take no action if both KeywordClose and KeywordOpen are set
|
||||||
if (mask & (KeywordsFoundReopen | KeywordsFoundClose)) == KeywordsFoundClose {
|
if (mask & (KeywordReopen | KeywordClose)) == KeywordClose {
|
||||||
if issue.RepoID == repo.ID && !issue.IsClosed {
|
if issue.RepoID == repo.ID && !issue.IsClosed {
|
||||||
if err = issue.ChangeStatus(doer, repo, true); err != nil {
|
if err = issue.ChangeStatus(doer, repo, true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (mask & (KeywordsFoundReopen | KeywordsFoundClose)) == KeywordsFoundReopen {
|
} else if (mask & (KeywordReopen | KeywordClose)) == KeywordReopen {
|
||||||
if issue.RepoID == repo.ID && issue.IsClosed {
|
if issue.RepoID == repo.ID && issue.IsClosed {
|
||||||
if err = issue.ChangeStatus(doer, repo, false); err != nil {
|
if err = issue.ChangeStatus(doer, repo, false); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user