diff options
Diffstat (limited to 'models/repo.go')
-rw-r--r-- | models/repo.go | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/models/repo.go b/models/repo.go index 845c1b75a9..8dda6f0d03 100644 --- a/models/repo.go +++ b/models/repo.go @@ -7,9 +7,9 @@ package models import ( "errors" "fmt" - "io/ioutil" "html" "html/template" + "io/ioutil" "os" "path" "path/filepath" @@ -43,6 +43,7 @@ var ( ErrRepoNameIllegal = errors.New("Repository name contains illegal characters") ErrRepoFileNotLoaded = errors.New("Repository file not loaded") ErrMirrorNotExist = errors.New("Mirror does not exist") + ErrInvalidReference = errors.New("Invalid reference specified") ) var ( @@ -837,6 +838,26 @@ func DeleteRepository(userId, repoId int64, userName string) error { return sess.Commit() } +// GetRepositoryByRef returns a Repository specified by a GFM reference. +// See https://help.github.com/articles/writing-on-github#references for more information on the syntax. +func GetRepositoryByRef(ref string) (*Repository, error) { + n := strings.IndexByte(ref, byte('/')) + + if n < 2 { + return nil, ErrInvalidReference + } + + userName, repoName := ref[:n], ref[n+1:] + + user, err := GetUserByName(userName) + + if err != nil { + return nil, err + } + + return GetRepositoryByName(user.Id, repoName) +} + // GetRepositoryByName returns the repository by given name under user if exists. func GetRepositoryByName(userId int64, repoName string) (*Repository, error) { repo := &Repository{ @@ -1017,4 +1038,4 @@ func IsWatching(uid, rid int64) bool { func ForkRepository(repoName string, uid int64) { -}
\ No newline at end of file +} |