|
|
@ -41,14 +41,14 @@ var ( |
|
|
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
var ( |
|
|
|
// Same as Github. See https://help.github.com/articles/closing-issues-via-commit-messages
|
|
|
|
// Same as Github. See https://help.github.com/articles/closing-issues-via-commit-messages
|
|
|
|
IssueCloseKeywords = []string{"close", "closes", "closed", "fix", "fixes", "fixed", "resolve", "resolves", "resolved"} |
|
|
|
IssueCloseKeywords = []string{"close", "closes", "closed", "fix", "fixes", "fixed", "resolve", "resolves", "resolved"} |
|
|
|
IssueCloseKeywordsPat *regexp.Regexp |
|
|
|
IssueCloseKeywordsPat *regexp.Regexp |
|
|
|
IssueReferenceKeywordsPat *regexp.Regexp |
|
|
|
IssueReferenceKeywordsPat *regexp.Regexp |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func init() { |
|
|
|
func init() { |
|
|
|
IssueCloseKeywordsPat = regexp.MustCompile(fmt.Sprintf(`(?i)(?:%s) \S+`, strings.Join(IssueCloseKeywords, "|"))) |
|
|
|
IssueCloseKeywordsPat = regexp.MustCompile(fmt.Sprintf(`(?i)(?:%s) \S+`, strings.Join(IssueCloseKeywords, "|"))) |
|
|
|
IssueReferenceKeywordsPat = regexp.MustCompile(fmt.Sprintf(`(?i)(?:) \S+`)) |
|
|
|
IssueReferenceKeywordsPat = regexp.MustCompile(`(?i)(?:)(^| )\S+`) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Action represents user operation type and other information to repository.,
|
|
|
|
// Action represents user operation type and other information to repository.,
|
|
|
@ -113,12 +113,14 @@ func (a Action) GetIssueInfos() []string { |
|
|
|
func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, commits []*base.PushCommit) error { |
|
|
|
func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, commits []*base.PushCommit) error { |
|
|
|
for _, c := range commits { |
|
|
|
for _, c := range commits { |
|
|
|
references := IssueReferenceKeywordsPat.FindAllString(c.Message, -1) |
|
|
|
references := IssueReferenceKeywordsPat.FindAllString(c.Message, -1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME: should not be a reference when it comes with action.
|
|
|
|
|
|
|
|
// e.g. fixes #1 will not have duplicated reference message.
|
|
|
|
for _, ref := range references { |
|
|
|
for _, ref := range references { |
|
|
|
ref := ref[strings.IndexByte(ref, byte(' '))+1:] |
|
|
|
ref := ref[strings.IndexByte(ref, byte(' '))+1:] |
|
|
|
ref = strings.TrimRightFunc(ref, func(c rune) bool { |
|
|
|
ref = strings.TrimRightFunc(ref, func(c rune) bool { |
|
|
|
return !unicode.IsDigit(c) |
|
|
|
return !unicode.IsDigit(c) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
if len(ref) == 0 { |
|
|
|
if len(ref) == 0 { |
|
|
|
continue |
|
|
|
continue |
|
|
@ -128,7 +130,7 @@ func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, com |
|
|
|
if ref[0] == '#' { |
|
|
|
if ref[0] == '#' { |
|
|
|
ref = fmt.Sprintf("%s/%s%s", repoUserName, repoName, ref) |
|
|
|
ref = fmt.Sprintf("%s/%s%s", repoUserName, repoName, ref) |
|
|
|
} else if strings.Contains(ref, "/") == false { |
|
|
|
} else if strings.Contains(ref, "/") == false { |
|
|
|
// We don't support User#ID syntax yet
|
|
|
|
// FIXME: We don't support User#ID syntax yet
|
|
|
|
// return ErrNotImplemented
|
|
|
|
// return ErrNotImplemented
|
|
|
|
|
|
|
|
|
|
|
|
continue |
|
|
|
continue |
|
|
@ -153,8 +155,8 @@ func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, com |
|
|
|
for _, ref := range closes { |
|
|
|
for _, ref := range closes { |
|
|
|
ref := ref[strings.IndexByte(ref, byte(' '))+1:] |
|
|
|
ref := ref[strings.IndexByte(ref, byte(' '))+1:] |
|
|
|
ref = strings.TrimRightFunc(ref, func(c rune) bool { |
|
|
|
ref = strings.TrimRightFunc(ref, func(c rune) bool { |
|
|
|
return !unicode.IsDigit(c) |
|
|
|
return !unicode.IsDigit(c) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
if len(ref) == 0 { |
|
|
|
if len(ref) == 0 { |
|
|
|
continue |
|
|
|
continue |
|
|
@ -199,7 +201,7 @@ func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, com |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
|