mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-25 05:02:42 +01:00
Add GetRepositoryByName and GetRepositoryById
This commit is contained in:
parent
8dd956f88a
commit
3c67318d8f
1 changed files with 25 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue