1
0
mirror of https://github.com/go-gitea/gitea synced 2024-12-24 03:35:55 +01:00

Add GetRepositoryByName and GetRepositoryById

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

@ -49,6 +49,7 @@ var (
var (
ErrRepoAlreadyExist = errors.New("Repository already exist")
ErrRepoNotExist = errors.New("Repository does not exist")
)
func init() {
@ -225,6 +226,30 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep
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.
func GetRepositories(user *User) ([]Repository, error) {
repos := make([]Repository, 0, 10)