mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-14 05:01:13 +00:00
Make GetRepositoryByName more safer (#31712)
Fix #31708 (cherry picked from commit d109923ed8e58bce0ad26b47385edbc79403803d)
This commit is contained in:
parent
170c1c5152
commit
7850fa30a5
1 changed files with 7 additions and 6 deletions
|
@ -766,17 +766,18 @@ func GetRepositoryByOwnerAndName(ctx context.Context, ownerName, repoName string
|
|||
|
||||
// GetRepositoryByName returns the repository by given name under user if exists.
|
||||
func GetRepositoryByName(ctx context.Context, ownerID int64, name string) (*Repository, error) {
|
||||
repo := &Repository{
|
||||
OwnerID: ownerID,
|
||||
LowerName: strings.ToLower(name),
|
||||
}
|
||||
has, err := db.GetEngine(ctx).Get(repo)
|
||||
var repo Repository
|
||||
has, err := db.GetEngine(ctx).
|
||||
Where("`owner_id`=?", ownerID).
|
||||
And("`lower_name`=?", strings.ToLower(name)).
|
||||
NoAutoCondition().
|
||||
Get(&repo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
return nil, ErrRepoNotExist{0, ownerID, "", name}
|
||||
}
|
||||
return repo, err
|
||||
return &repo, err
|
||||
}
|
||||
|
||||
// getRepositoryURLPathSegments returns segments (owner, reponame) extracted from a url
|
||||
|
|
Loading…
Reference in a new issue