summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author无闻 <u@gogs.io>2015-02-04 23:21:20 -0500
committer无闻 <u@gogs.io>2015-02-04 23:21:20 -0500
commit02c5bade0fabc24b9b7c05a74c65965e2e53f687 (patch)
tree91e9159fa3e06943d0a28f55cd82a1dddde8d186
parentf706102890af33c14aa9afc7e62a4c2dd52bd2a4 (diff)
parent5c4b85c0290adce70b9c58ed151e30081151a57c (diff)
downloadgitea-02c5bade0fabc24b9b7c05a74c65965e2e53f687.tar.gz
gitea-02c5bade0fabc24b9b7c05a74c65965e2e53f687.zip
Merge pull request #892 from EtienneBruines/commit_reference
Referencing issues from commit messages is now possible.
-rw-r--r--models/action.go48
1 files changed, 40 insertions, 8 deletions
diff --git a/models/action.go b/models/action.go
index de2cdd12cc..318a5f6ad4 100644
--- a/models/action.go
+++ b/models/action.go
@@ -41,12 +41,14 @@ var (
var (
// Same as Github. See https://help.github.com/articles/closing-issues-via-commit-messages
- IssueKeywords = []string{"close", "closes", "closed", "fix", "fixes", "fixed", "resolve", "resolves", "resolved"}
- IssueKeywordsPat *regexp.Regexp
+ IssueCloseKeywords = []string{"close", "closes", "closed", "fix", "fixes", "fixed", "resolve", "resolves", "resolved"}
+ IssueCloseKeywordsPat *regexp.Regexp
+ IssueReferenceKeywordsPat *regexp.Regexp
)
func init() {
- IssueKeywordsPat = regexp.MustCompile(fmt.Sprintf(`(?i)(?:%s) \S+`, strings.Join(IssueKeywords, "|")))
+ IssueCloseKeywordsPat = regexp.MustCompile(fmt.Sprintf(`(?i)(?:%s) \S+`, strings.Join(IssueCloseKeywords, "|")))
+ IssueReferenceKeywordsPat = regexp.MustCompile(fmt.Sprintf(`(?i)(?:) \S+`))
}
// Action represents user operation type and other information to repository.,
@@ -110,13 +112,13 @@ func (a Action) GetIssueInfos() []string {
func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, commits []*base.PushCommit) error {
for _, c := range commits {
- refs := IssueKeywordsPat.FindAllString(c.Message, -1)
-
- for _, ref := range refs {
+ references := IssueReferenceKeywordsPat.FindAllString(c.Message, -1)
+
+ for _, ref := range references {
ref := ref[strings.IndexByte(ref, byte(' '))+1:]
ref = strings.TrimRightFunc(ref, func(c rune) bool {
- return !unicode.IsDigit(c)
- })
+ return !unicode.IsDigit(c)
+ })
if len(ref) == 0 {
continue
@@ -144,6 +146,35 @@ func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, com
if _, err = CreateComment(userId, issue.RepoId, issue.Id, 0, 0, COMMIT, message, nil); err != nil {
return err
}
+ }
+
+ closes := IssueCloseKeywordsPat.FindAllString(c.Message, -1)
+
+ for _, ref := range closes {
+ ref := ref[strings.IndexByte(ref, byte(' '))+1:]
+ ref = strings.TrimRightFunc(ref, func(c rune) bool {
+ return !unicode.IsDigit(c)
+ })
+
+ if len(ref) == 0 {
+ continue
+ }
+
+ // Add repo name if missing
+ if ref[0] == '#' {
+ ref = fmt.Sprintf("%s/%s%s", repoUserName, repoName, ref)
+ } else if strings.Contains(ref, "/") == false {
+ // We don't support User#ID syntax yet
+ // return ErrNotImplemented
+
+ continue
+ }
+
+ issue, err := GetIssueByRef(ref)
+
+ if err != nil {
+ return err
+ }
if issue.RepoId == repoId {
if issue.IsClosed {
@@ -168,6 +199,7 @@ func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, com
}
}
}
+
}
return nil