Fix ref parsing in commit messages (#3067)

This commit is contained in:
Ethan Koenig
2017-12-02 18:20:12 -08:00
committed by Lunny Xiao
parent b0971ae37c
commit 3163abedd6
3 changed files with 87 additions and 102 deletions

View File

@ -5,7 +5,6 @@
package models
import (
"errors"
"fmt"
"path"
"sort"
@ -22,11 +21,6 @@ import (
"code.gitea.io/gitea/modules/util"
)
var (
errMissingIssueNumber = errors.New("No issue number specified")
errInvalidIssueNumber = errors.New("Invalid issue number")
)
// Issue represents an issue or pull request of repository.
type Issue struct {
ID int64 `xorm:"pk autoincr"`
@ -961,32 +955,6 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string)
return nil
}
// 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, error) {
n := strings.IndexByte(ref, '#')
if n == -1 {
return nil, errMissingIssueNumber
}
index, err := com.StrTo(ref[n+1:]).Int64()
if err != nil {
return nil, errInvalidIssueNumber
}
i := strings.IndexByte(ref[:n], '/')
if i < 2 {
return nil, ErrInvalidReference
}
repo, err := GetRepositoryByOwnerAndName(ref[:i], ref[i+1:n])
if err != nil {
return nil, err
}
return GetIssueByIndex(repo.ID, index)
}
// GetRawIssueByIndex returns raw issue without loading attributes by index in a repository.
func GetRawIssueByIndex(repoID, index int64) (*Issue, error) {
issue := &Issue{