From afccd0a3eeb070100b375cd9bb83cd5b213d01b3 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 6 Feb 2015 20:34:49 -0500 Subject: [PATCH] models/action.go: mirror fix on #892 - modules/base/markdown.go: fix issue link issue - routers/repo/view.go: remove useless code --- models/action.go | 22 ++++++++++++---------- modules/base/markdown.go | 4 ++-- routers/repo/view.go | 12 ------------ 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/models/action.go b/models/action.go index 318a5f6ad4..ed90ad900e 100644 --- a/models/action.go +++ b/models/action.go @@ -41,14 +41,14 @@ var ( var ( // 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"} - IssueCloseKeywordsPat *regexp.Regexp + IssueCloseKeywords = []string{"close", "closes", "closed", "fix", "fixes", "fixed", "resolve", "resolves", "resolved"} + IssueCloseKeywordsPat *regexp.Regexp IssueReferenceKeywordsPat *regexp.Regexp ) func init() { 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., @@ -113,12 +113,14 @@ func (a Action) GetIssueInfos() []string { func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, commits []*base.PushCommit) error { for _, c := range commits { 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 { 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 @@ -128,7 +130,7 @@ func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, com 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 + // FIXME: We don't support User#ID syntax yet // return ErrNotImplemented continue @@ -153,8 +155,8 @@ func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, com for _, ref := range closes { 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 @@ -199,7 +201,7 @@ func updateIssuesCommit(userId, repoId int64, repoUserName, repoName string, com } } } - + } return nil diff --git a/modules/base/markdown.go b/modules/base/markdown.go index 4122098618..b5f397dce0 100644 --- a/modules/base/markdown.go +++ b/modules/base/markdown.go @@ -177,8 +177,8 @@ func RenderSha1CurrentPattern(rawBytes []byte, urlPrefix string) []byte { func RenderIssueIndexPattern(rawBytes []byte, urlPrefix string) []byte { ms := issueIndexPattern.FindAll(rawBytes, -1) for _, m := range ms { - rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf( - `%s`, urlPrefix, m[1:], m)), -1) + rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf(`%s`, + urlPrefix, strings.TrimPrefix(string(m[1:]), "#"), m)), -1) } return rawBytes } diff --git a/routers/repo/view.go b/routers/repo/view.go index cb689df6a0..cfe0fa010c 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -127,7 +127,6 @@ func Home(ctx *middleware.Context) { entries.Sort() files := make([][]interface{}, 0, len(entries)) - for _, te := range entries { if te.Type != git.COMMIT { c, err := ctx.Repo.Commit.GetCommitOfRelPath(filepath.Join(treePath, te.Name())) @@ -151,16 +150,6 @@ func Home(ctx *middleware.Context) { files = append(files, []interface{}{te, git.NewSubModuleFile(c, sm.Url, te.Id.String())}) } } - - // Render issue index links. - for _, f := range files { - switch c := f[1].(type) { - case *git.Commit: - c.CommitMessage = c.CommitMessage - case *git.SubModuleFile: - c.CommitMessage = c.CommitMessage - } - } ctx.Data["Files"] = files var readmeFile *git.Blob @@ -208,7 +197,6 @@ func Home(ctx *middleware.Context) { } lastCommit := ctx.Repo.Commit - lastCommit.CommitMessage = string(base.RenderIssueIndexPattern([]byte(lastCommit.CommitMessage), ctx.Repo.RepoLink)) if len(treePath) > 0 { c, err := ctx.Repo.Commit.GetCommitOfRelPath(treePath) if err != nil {