diff options
author | Unknwon <u@gogs.io> | 2015-09-03 04:34:08 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-09-03 04:34:08 -0400 |
commit | b6131793dacc3e49411d6bf1ade6220221739dc1 (patch) | |
tree | 6be86b6e58c6d5c3887951d304f6d2da81b3a8d5 /models/issue.go | |
parent | 1fd5f8edf85646d028aaa5bf8abc35fcab41dbe7 (diff) | |
download | gitea-b6131793dacc3e49411d6bf1ade6220221739dc1.tar.gz gitea-b6131793dacc3e49411d6bf1ade6220221739dc1.zip |
#1545 prevent duplicated refs of issues in single commit
Diffstat (limited to 'models/issue.go')
-rw-r--r-- | models/issue.go | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/models/issue.go b/models/issue.go index 1f63007768..dbc63b9574 100644 --- a/models/issue.go +++ b/models/issue.go @@ -13,7 +13,6 @@ import ( "mime/multipart" "os" "path" - "strconv" "strings" "time" @@ -384,25 +383,29 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string) // GetIssueByRef returns an Issue specified by a GFM reference. // See https://help.github.com/articles/writing-on-github#references for more information on the syntax. -func GetIssueByRef(ref string) (issue *Issue, err error) { - var issueNumber int64 - var repo *Repository - +func GetIssueByRef(ref string) (*Issue, error) { n := strings.IndexByte(ref, byte('#')) - if n == -1 { return nil, ErrMissingIssueNumber } - if issueNumber, err = strconv.ParseInt(ref[n+1:], 10, 64); err != nil { - return + index, err := com.StrTo(ref[n+1:]).Int64() + if err != nil { + return nil, err } - if repo, err = GetRepositoryByRef(ref[:n]); err != nil { - return + repo, err := GetRepositoryByRef(ref[:n]) + if err != nil { + return nil, err } - return GetIssueByIndex(repo.ID, issueNumber) + issue, err := GetIssueByIndex(repo.ID, index) + if err != nil { + return nil, err + } + + issue.Repo = repo + return issue, nil } // GetIssueByIndex returns issue by given index in repository. |