Add GetRepositoryByName and GetRepositoryById

This commit is contained in:
Unknown 2014-03-12 22:27:11 -04:00
parent 8dd956f88a
commit 3c67318d8f

View File

@ -49,6 +49,7 @@ var (
var ( var (
ErrRepoAlreadyExist = errors.New("Repository already exist") ErrRepoAlreadyExist = errors.New("Repository already exist")
ErrRepoNotExist = errors.New("Repository does not exist")
) )
func init() { func init() {
@ -225,6 +226,30 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep
return nil return nil
} }
func GetRepositoryByName(user *User, repoName string) (*Repository, error) {
repo := &Repository{
OwnerId: user.Id,
LowerName: strings.ToLower(repoName),
}
has, err := orm.Get(repo)
if err != nil {
return nil, err
} else if !has {
return nil, ErrRepoNotExist
}
return repo, err
}
func GetRepositoryById(id int64) (repo *Repository, err error) {
has, err := orm.Id(id).Get(repo)
if err != nil {
return nil, err
} else if !has {
return nil, ErrRepoNotExist
}
return repo, err
}
// GetRepositories returns the list of repositories of given user. // GetRepositories returns the list of repositories of given user.
func GetRepositories(user *User) ([]Repository, error) { func GetRepositories(user *User) ([]Repository, error) {
repos := make([]Repository, 0, 10) repos := make([]Repository, 0, 10)