|
|
@ -1740,13 +1740,13 @@ func DeleteRepository(doer *User, uid, repoID int64) error { |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} else if !has { |
|
|
|
} else if !has { |
|
|
|
return ErrRepoNotExist{repoID, uid, ""} |
|
|
|
return ErrRepoNotExist{repoID, uid, "", ""} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if cnt, err := sess.ID(repoID).Delete(&Repository{}); err != nil { |
|
|
|
if cnt, err := sess.ID(repoID).Delete(&Repository{}); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} else if cnt != 1 { |
|
|
|
} else if cnt != 1 { |
|
|
|
return ErrRepoNotExist{repoID, uid, ""} |
|
|
|
return ErrRepoNotExist{repoID, uid, "", ""} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if org.IsOrganization() { |
|
|
|
if org.IsOrganization() { |
|
|
@ -1891,21 +1891,20 @@ func DeleteRepository(doer *User, uid, repoID int64) error { |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetRepositoryByRef returns a Repository specified by a GFM reference.
|
|
|
|
// GetRepositoryByOwnerAndName returns the repository by given ownername and reponame.
|
|
|
|
// See https://help.github.com/articles/writing-on-github#references for more information on the syntax.
|
|
|
|
func GetRepositoryByOwnerAndName(ownerName, repoName string) (*Repository, error) { |
|
|
|
func GetRepositoryByRef(ref string) (*Repository, error) { |
|
|
|
var repo Repository |
|
|
|
n := strings.IndexByte(ref, byte('/')) |
|
|
|
has, err := x.Select("repository.*"). |
|
|
|
if n < 2 { |
|
|
|
Join("INNER", "user", "`user`.id = repository.owner_id"). |
|
|
|
return nil, ErrInvalidReference |
|
|
|
Where("repository.lower_name = ?", strings.ToLower(repoName)). |
|
|
|
} |
|
|
|
And("`user`.lower_name = ?", strings.ToLower(ownerName)). |
|
|
|
|
|
|
|
Get(&repo) |
|
|
|
userName, repoName := ref[:n], ref[n+1:] |
|
|
|
|
|
|
|
user, err := GetUserByName(userName) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
|
|
|
|
} else if !has { |
|
|
|
|
|
|
|
return nil, ErrRepoNotExist{0, 0, ownerName, repoName} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return &repo, nil |
|
|
|
return GetRepositoryByName(user.ID, repoName) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetRepositoryByName returns the repository by given name under user if exists.
|
|
|
|
// 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 { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} else if !has { |
|
|
|
} else if !has { |
|
|
|
return nil, ErrRepoNotExist{0, ownerID, name} |
|
|
|
return nil, ErrRepoNotExist{0, ownerID, "", name} |
|
|
|
} |
|
|
|
} |
|
|
|
return repo, err |
|
|
|
return repo, err |
|
|
|
} |
|
|
|
} |
|
|
@ -1929,7 +1928,7 @@ func getRepositoryByID(e Engine, id int64) (*Repository, error) { |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} else if !has { |
|
|
|
} else if !has { |
|
|
|
return nil, ErrRepoNotExist{id, 0, ""} |
|
|
|
return nil, ErrRepoNotExist{id, 0, "", ""} |
|
|
|
} |
|
|
|
} |
|
|
|
return repo, nil |
|
|
|
return repo, nil |
|
|
|
} |
|
|
|
} |
|
|
|