diff options
author | 无闻 <joe2010xtmf@163.com> | 2014-07-24 04:25:00 -0400 |
---|---|---|
committer | 无闻 <joe2010xtmf@163.com> | 2014-07-24 04:25:00 -0400 |
commit | a76a948a029f46697a0e2327ea6ca86872a760d7 (patch) | |
tree | 52e07c859411253fd87f29a3e6798e3f082b0459 /models/repo.go | |
parent | 6e9f1c52b18f112eecd5c72e295cfea1809f07fa (diff) | |
parent | d43c5895bc5026fb29dd9aa509056e49b4644ba7 (diff) |
Merge pull request #305 from nuss-justin/feature/commit-issue-fix
Fix #302. Show referencing commits in issue.
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 845c1b75..8dda6f0d 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 +} |