mirror of https://github.com/gogs/gogs.git
error: move ErrRepoNotExist -> errors.RepoNotExist
parent
902372067c
commit
beee6e03b1
|
@ -162,7 +162,7 @@ func runServ(c *cli.Context) error {
|
|||
|
||||
repo, err := models.GetRepositoryByName(owner.ID, repoName)
|
||||
if err != nil {
|
||||
if models.IsErrRepoNotExist(err) {
|
||||
if errors.IsRepoNotExist(err) {
|
||||
fail(_ACCESS_DENIED_MESSAGE, "Repository does not exist: %s/%s", owner.Name, repoName)
|
||||
}
|
||||
fail("Internal error", "Fail to get repository: %v", err)
|
||||
|
|
|
@ -8,6 +8,8 @@ import (
|
|||
"fmt"
|
||||
|
||||
log "gopkg.in/clog.v1"
|
||||
|
||||
"github.com/gogits/gogs/models/errors"
|
||||
)
|
||||
|
||||
type AccessMode int
|
||||
|
@ -109,7 +111,7 @@ func (u *User) GetRepositoryAccesses() (map[*Repository]AccessMode, error) {
|
|||
for _, access := range accesses {
|
||||
repo, err := GetRepositoryByID(access.RepoID)
|
||||
if err != nil {
|
||||
if IsErrRepoNotExist(err) {
|
||||
if errors.IsRepoNotExist(err) {
|
||||
log.Error(4, "GetRepositoryByID: %v", err)
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -305,21 +305,6 @@ func (err ErrLastOrgOwner) Error() string {
|
|||
// |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
|
||||
// \/ \/|__| \/ \/
|
||||
|
||||
type ErrRepoNotExist struct {
|
||||
ID int64
|
||||
UID int64
|
||||
Name string
|
||||
}
|
||||
|
||||
func IsErrRepoNotExist(err error) bool {
|
||||
_, ok := err.(ErrRepoNotExist)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (err ErrRepoNotExist) Error() string {
|
||||
return fmt.Sprintf("repository does not exist [id: %d, uid: %d, name: %s]", err.ID, err.UID, err.Name)
|
||||
}
|
||||
|
||||
type ErrRepoAlreadyExist struct {
|
||||
Uname string
|
||||
Name string
|
||||
|
|
|
@ -6,6 +6,21 @@ package errors
|
|||
|
||||
import "fmt"
|
||||
|
||||
type RepoNotExist struct {
|
||||
ID int64
|
||||
UserID int64
|
||||
Name string
|
||||
}
|
||||
|
||||
func IsRepoNotExist(err error) bool {
|
||||
_, ok := err.(RepoNotExist)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (err RepoNotExist) Error() string {
|
||||
return fmt.Sprintf("repository does not exist [id: %d, user_id: %d, name: %s]", err.ID, err.UserID, err.Name)
|
||||
}
|
||||
|
||||
type InvalidRepoReference struct {
|
||||
Ref string
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ func (pr *PullRequest) AfterSet(colName string, _ xorm.Cell) {
|
|||
func (pr *PullRequest) loadAttributes(e Engine) (err error) {
|
||||
if pr.HeadRepo == nil {
|
||||
pr.HeadRepo, err = getRepositoryByID(e, pr.HeadRepoID)
|
||||
if err != nil && !IsErrRepoNotExist(err) {
|
||||
if err != nil && !errors.IsRepoNotExist(err) {
|
||||
return fmt.Errorf("getRepositoryByID.(HeadRepo) [%d]: %v", pr.HeadRepoID, err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1366,7 +1366,7 @@ func DeleteRepository(uid, repoID int64) error {
|
|||
if err != nil {
|
||||
return err
|
||||
} else if !has {
|
||||
return ErrRepoNotExist{repoID, uid, ""}
|
||||
return errors.RepoNotExist{repoID, uid, ""}
|
||||
}
|
||||
|
||||
// In case is a organization.
|
||||
|
@ -1503,9 +1503,9 @@ 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, errors.RepoNotExist{0, ownerID, name}
|
||||
}
|
||||
return repo, err
|
||||
return repo, repo.LoadAttributes()
|
||||
}
|
||||
|
||||
func getRepositoryByID(e Engine, id int64) (*Repository, error) {
|
||||
|
@ -1514,9 +1514,9 @@ func getRepositoryByID(e Engine, id int64) (*Repository, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
return nil, ErrRepoNotExist{id, 0, ""}
|
||||
return nil, errors.RepoNotExist{id, 0, ""}
|
||||
}
|
||||
return repo, nil
|
||||
return repo, repo.loadAttributes(e)
|
||||
}
|
||||
|
||||
// GetRepositoryByID returns the repository by given id if exists.
|
||||
|
|
|
@ -111,7 +111,7 @@ func (r *Repository) PullRequestURL(baseBranch, headBranch string) string {
|
|||
func RetrieveBaseRepo(ctx *Context, repo *models.Repository) {
|
||||
// Non-fork repository will not return error in this method.
|
||||
if err := repo.GetBaseRepo(); err != nil {
|
||||
if models.IsErrRepoNotExist(err) {
|
||||
if errors.IsRepoNotExist(err) {
|
||||
repo.IsFork = false
|
||||
repo.ForkID = 0
|
||||
return
|
||||
|
@ -180,7 +180,7 @@ func RepoAssignment() macaron.Handler {
|
|||
// Get repository.
|
||||
repo, err := models.GetRepositoryByName(owner.ID, repoName)
|
||||
if err != nil {
|
||||
if models.IsErrRepoNotExist(err) {
|
||||
if errors.IsRepoNotExist(err) {
|
||||
if ctx.Query("go-get") == "1" {
|
||||
earlyResponseForGoGetMeta(ctx)
|
||||
return
|
||||
|
|
|
@ -6,13 +6,14 @@ package admin
|
|||
|
||||
import (
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/models/errors"
|
||||
"github.com/gogits/gogs/modules/context"
|
||||
)
|
||||
|
||||
func GetRepositoryByParams(ctx *context.APIContext) *models.Repository {
|
||||
repo, err := models.GetRepositoryByName(ctx.Org.Team.OrgID, ctx.Params(":reponame"))
|
||||
if err != nil {
|
||||
if models.IsErrRepoNotExist(err) {
|
||||
if errors.IsRepoNotExist(err) {
|
||||
ctx.Status(404)
|
||||
} else {
|
||||
ctx.Error(500, "GetRepositoryByName", err)
|
||||
|
|
|
@ -52,7 +52,7 @@ func repoAssignment() macaron.Handler {
|
|||
// Get repository.
|
||||
repo, err := models.GetRepositoryByName(owner.ID, repoName)
|
||||
if err != nil {
|
||||
if models.IsErrRepoNotExist(err) {
|
||||
if errors.IsRepoNotExist(err) {
|
||||
ctx.Status(404)
|
||||
} else {
|
||||
ctx.Error(500, "GetRepositoryByName", err)
|
||||
|
|
|
@ -291,7 +291,7 @@ func parseOwnerAndRepo(ctx *context.APIContext) (*models.User, *models.Repositor
|
|||
|
||||
repo, err := models.GetRepositoryByName(owner.ID, ctx.Params(":reponame"))
|
||||
if err != nil {
|
||||
if models.IsErrRepoNotExist(err) {
|
||||
if errors.IsRepoNotExist(err) {
|
||||
ctx.Status(404)
|
||||
} else {
|
||||
ctx.Error(500, "GetRepositoryByName", err)
|
||||
|
|
|
@ -121,7 +121,7 @@ func TeamsRepoAction(ctx *context.Context) {
|
|||
var repo *models.Repository
|
||||
repo, err = models.GetRepositoryByName(ctx.Org.Organization.ID, repoName)
|
||||
if err != nil {
|
||||
if models.IsErrRepoNotExist(err) {
|
||||
if errors.IsRepoNotExist(err) {
|
||||
ctx.Flash.Error(ctx.Tr("org.teams.add_nonexistent_repo"))
|
||||
ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories")
|
||||
return
|
||||
|
|
|
@ -66,7 +66,7 @@ func HTTPContexter() macaron.Handler {
|
|||
|
||||
repo, err := models.GetRepositoryByName(owner.ID, repoName)
|
||||
if err != nil {
|
||||
ctx.NotFoundOrServerError("GetRepositoryByName", models.IsErrRepoNotExist, err)
|
||||
ctx.NotFoundOrServerError("GetRepositoryByName", errors.IsRepoNotExist, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ var (
|
|||
func parseBaseRepository(ctx *context.Context) *models.Repository {
|
||||
baseRepo, err := models.GetRepositoryByID(ctx.ParamsInt64(":repoid"))
|
||||
if err != nil {
|
||||
ctx.NotFoundOrServerError("GetRepositoryByID", models.IsErrRepoNotExist, err)
|
||||
ctx.NotFoundOrServerError("GetRepositoryByID", errors.IsRepoNotExist, err)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -718,7 +718,7 @@ func parseOwnerAndRepo(ctx *context.Context) (*models.User, *models.Repository)
|
|||
|
||||
repo, err := models.GetRepositoryByName(owner.ID, ctx.Params(":reponame"))
|
||||
if err != nil {
|
||||
ctx.NotFoundOrServerError("GetRepositoryByName", models.IsErrRepoNotExist, err)
|
||||
ctx.NotFoundOrServerError("GetRepositoryByName", errors.IsRepoNotExist, err)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue