Add error for fork already existing (#7185)
This commit is contained in:
parent
f9ec2f89f2
commit
744fd6a1c8
3 changed files with 22 additions and 4 deletions
|
@ -674,6 +674,23 @@ func (err ErrRepoAlreadyExist) Error() string {
|
||||||
return fmt.Sprintf("repository already exists [uname: %s, name: %s]", err.Uname, err.Name)
|
return fmt.Sprintf("repository already exists [uname: %s, name: %s]", err.Uname, err.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ErrForkAlreadyExist represents a "ForkAlreadyExist" kind of error.
|
||||||
|
type ErrForkAlreadyExist struct {
|
||||||
|
Uname string
|
||||||
|
RepoName string
|
||||||
|
ForkName string
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsErrForkAlreadyExist checks if an error is an ErrForkAlreadyExist.
|
||||||
|
func IsErrForkAlreadyExist(err error) bool {
|
||||||
|
_, ok := err.(ErrForkAlreadyExist)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (err ErrForkAlreadyExist) Error() string {
|
||||||
|
return fmt.Sprintf("repository is already forked by user [uname: %s, repo path: %s, fork path: %s]", err.Uname, err.RepoName, err.ForkName)
|
||||||
|
}
|
||||||
|
|
||||||
// ErrRepoRedirectNotExist represents a "RepoRedirectNotExist" kind of error.
|
// ErrRepoRedirectNotExist represents a "RepoRedirectNotExist" kind of error.
|
||||||
type ErrRepoRedirectNotExist struct {
|
type ErrRepoRedirectNotExist struct {
|
||||||
OwnerID int64
|
OwnerID int64
|
||||||
|
|
|
@ -2395,9 +2395,10 @@ func ForkRepository(doer, u *User, oldRepo *Repository, name, desc string) (_ *R
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if forkedRepo != nil {
|
if forkedRepo != nil {
|
||||||
return nil, ErrRepoAlreadyExist{
|
return nil, ErrForkAlreadyExist{
|
||||||
Uname: u.Name,
|
Uname: u.Name,
|
||||||
Name: forkedRepo.Name,
|
RepoName: oldRepo.FullName(),
|
||||||
|
ForkName: forkedRepo.FullName(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,7 @@ func TestForkRepository(t *testing.T) {
|
||||||
fork, err := ForkRepository(user, user, repo, "test", "test")
|
fork, err := ForkRepository(user, user, repo, "test", "test")
|
||||||
assert.Nil(t, fork)
|
assert.Nil(t, fork)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.True(t, IsErrRepoAlreadyExist(err))
|
assert.True(t, IsErrForkAlreadyExist(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRepoAPIURL(t *testing.T) {
|
func TestRepoAPIURL(t *testing.T) {
|
||||||
|
|
Reference in a new issue