summaryrefslogtreecommitdiffstats
path: root/models/repo.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2017-12-02 15:34:39 +0800
committerGitHub <noreply@github.com>2017-12-02 15:34:39 +0800
commit35cc5b0402d46d672e02bbe1ad15d1460077e8f4 (patch)
tree47723925eb89e286f328503ae30e77ca1eaaf021 /models/repo.go
parent674422b642452050a7185f10908a9e8a86604f24 (diff)
downloadgitea-35cc5b0402d46d672e02bbe1ad15d1460077e8f4.tar.gz
gitea-35cc5b0402d46d672e02bbe1ad15d1460077e8f4.zip
Remove GetRepositoryByRef and add GetRepositoryByOwnerAndName (#3043)
* remove GetRepositoryByRef and add GetRepositoryByOwnerAndName * fix tests * fix tests bug * some improvements
Diffstat (limited to 'models/repo.go')
-rw-r--r--models/repo.go31
1 files changed, 15 insertions, 16 deletions
diff --git a/models/repo.go b/models/repo.go
index 8d57ae51a5..a9f0d93031 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -1740,13 +1740,13 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
if err != nil {
return err
} else if !has {
- return ErrRepoNotExist{repoID, uid, ""}
+ return ErrRepoNotExist{repoID, uid, "", ""}
}
if cnt, err := sess.ID(repoID).Delete(&Repository{}); err != nil {
return err
} else if cnt != 1 {
- return ErrRepoNotExist{repoID, uid, ""}
+ return ErrRepoNotExist{repoID, uid, "", ""}
}
if org.IsOrganization() {
@@ -1891,21 +1891,20 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
return nil
}
-// 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)
+// GetRepositoryByOwnerAndName returns the repository by given ownername and reponame.
+func GetRepositoryByOwnerAndName(ownerName, repoName string) (*Repository, error) {
+ var repo Repository
+ has, err := x.Select("repository.*").
+ Join("INNER", "user", "`user`.id = repository.owner_id").
+ Where("repository.lower_name = ?", strings.ToLower(repoName)).
+ And("`user`.lower_name = ?", strings.ToLower(ownerName)).
+ Get(&repo)
if err != nil {
return nil, err
+ } else if !has {
+ return nil, ErrRepoNotExist{0, 0, ownerName, repoName}
}
-
- return GetRepositoryByName(user.ID, repoName)
+ return &repo, nil
}
// GetRepositoryByName returns the repository by given name under user if exists.
@@ -1918,7 +1917,7 @@ func GetRepositoryByName(ownerID int64, name string) (*Repository, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, ErrRepoNotExist{0, ownerID, name}
+ return nil, ErrRepoNotExist{0, ownerID, "", name}
}
return repo, err
}
@@ -1929,7 +1928,7 @@ func getRepositoryByID(e Engine, id int64) (*Repository, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, ErrRepoNotExist{id, 0, ""}
+ return nil, ErrRepoNotExist{id, 0, "", ""}
}
return repo, nil
}