mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-30 19:22:08 +00:00
chore: remove redundant code (#9378)
Found this while working on !9360. Making sure that the dir doesn't exist is already done a few lines above. The removed parameter was always set to false, since the function is only called in a single place. (it smells like this code was refactored at some point, but some stuff was forgotten) ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [ ] in their respective `*_test.go` for unit tests. - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [x] I do not want this change to show in the release notes. - [ ] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9378 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: patka <patka@patka.dev> Co-committed-by: patka <patka@patka.dev>
This commit is contained in:
parent
2dd333f8fb
commit
ff888dbee3
3 changed files with 8 additions and 18 deletions
|
@ -10,7 +10,6 @@ import (
|
||||||
|
|
||||||
"forgejo.org/models/db"
|
"forgejo.org/models/db"
|
||||||
user_model "forgejo.org/models/user"
|
user_model "forgejo.org/models/user"
|
||||||
"forgejo.org/modules/log"
|
|
||||||
"forgejo.org/modules/util"
|
"forgejo.org/modules/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -106,7 +105,7 @@ func (err ErrRepoFilesAlreadyExist) Unwrap() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckCreateRepository check if a repository can be created
|
// CheckCreateRepository check if a repository can be created
|
||||||
func CheckCreateRepository(ctx context.Context, doer, u *user_model.User, name string, overwriteOrAdopt bool) error {
|
func CheckCreateRepository(ctx context.Context, doer, u *user_model.User, name string) error {
|
||||||
if !doer.IsAdmin && !u.CanCreateRepo() {
|
if !doer.IsAdmin && !u.CanCreateRepo() {
|
||||||
return ErrReachLimitOfRepo{u.MaxRepoCreation}
|
return ErrReachLimitOfRepo{u.MaxRepoCreation}
|
||||||
}
|
}
|
||||||
|
@ -122,15 +121,6 @@ func CheckCreateRepository(ctx context.Context, doer, u *user_model.User, name s
|
||||||
return ErrRepoAlreadyExist{u.Name, name}
|
return ErrRepoAlreadyExist{u.Name, name}
|
||||||
}
|
}
|
||||||
|
|
||||||
repoPath := RepoPath(u.Name, name)
|
|
||||||
isExist, err := util.IsExist(repoPath)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !overwriteOrAdopt && isExist {
|
|
||||||
return ErrRepoFilesAlreadyExist{u.Name, name}
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ func TestCheckCreateRepository(t *testing.T) {
|
||||||
t.Run("Success", func(t *testing.T) {
|
t.Run("Success", func(t *testing.T) {
|
||||||
user := &user_model.User{MaxRepoCreation: 1}
|
user := &user_model.User{MaxRepoCreation: 1}
|
||||||
|
|
||||||
err := repo_model.CheckCreateRepository(db.DefaultContext, user, user, "testName", true)
|
err := repo_model.CheckCreateRepository(db.DefaultContext, user, user, "testName")
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
@ -30,7 +30,7 @@ func TestCheckCreateRepository(t *testing.T) {
|
||||||
t.Run("AdminIgnoresRepoLimit", func(t *testing.T) {
|
t.Run("AdminIgnoresRepoLimit", func(t *testing.T) {
|
||||||
user := &user_model.User{MaxRepoCreation: 0, IsAdmin: true}
|
user := &user_model.User{MaxRepoCreation: 0, IsAdmin: true}
|
||||||
|
|
||||||
err := repo_model.CheckCreateRepository(db.DefaultContext, user, user, "testName", true)
|
err := repo_model.CheckCreateRepository(db.DefaultContext, user, user, "testName")
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
@ -38,7 +38,7 @@ func TestCheckCreateRepository(t *testing.T) {
|
||||||
t.Run("RepoLimitReached", func(t *testing.T) {
|
t.Run("RepoLimitReached", func(t *testing.T) {
|
||||||
user := &user_model.User{MaxRepoCreation: 0}
|
user := &user_model.User{MaxRepoCreation: 0}
|
||||||
|
|
||||||
err := repo_model.CheckCreateRepository(db.DefaultContext, user, user, "testName", true)
|
err := repo_model.CheckCreateRepository(db.DefaultContext, user, user, "testName")
|
||||||
|
|
||||||
require.ErrorIs(t, err, repo_model.ErrReachLimitOfRepo{})
|
require.ErrorIs(t, err, repo_model.ErrReachLimitOfRepo{})
|
||||||
})
|
})
|
||||||
|
@ -46,7 +46,7 @@ func TestCheckCreateRepository(t *testing.T) {
|
||||||
t.Run("UnusableRepoName", func(t *testing.T) {
|
t.Run("UnusableRepoName", func(t *testing.T) {
|
||||||
user := &user_model.User{MaxRepoCreation: 1}
|
user := &user_model.User{MaxRepoCreation: 1}
|
||||||
|
|
||||||
err := repo_model.CheckCreateRepository(db.DefaultContext, user, user, "testName/", true)
|
err := repo_model.CheckCreateRepository(db.DefaultContext, user, user, "testName/")
|
||||||
|
|
||||||
require.ErrorIs(t, err, db.ErrNameCharsNotAllowed{Name: "testName/"})
|
require.ErrorIs(t, err, db.ErrNameCharsNotAllowed{Name: "testName/"})
|
||||||
})
|
})
|
||||||
|
@ -55,7 +55,7 @@ func TestCheckCreateRepository(t *testing.T) {
|
||||||
unittest.AssertExistsIf(t, true, &repo_model.Repository{Name: "repo1"})
|
unittest.AssertExistsIf(t, true, &repo_model.Repository{Name: "repo1"})
|
||||||
user := &user_model.User{MaxRepoCreation: 2}
|
user := &user_model.User{MaxRepoCreation: 2}
|
||||||
|
|
||||||
err := repo_model.CheckCreateRepository(db.DefaultContext, user, user, "repo1", true)
|
err := repo_model.CheckCreateRepository(db.DefaultContext, user, user, "repo1")
|
||||||
|
|
||||||
require.ErrorIs(t, err, repo_model.ErrRepoAlreadyExist{Name: "repo1"})
|
require.ErrorIs(t, err, repo_model.ErrRepoAlreadyExist{Name: "repo1"})
|
||||||
})
|
})
|
||||||
|
@ -67,7 +67,7 @@ func TestCheckCreateRepository(t *testing.T) {
|
||||||
exists, _ := util.IsExist(repo_model.RepoPath("user2", "repo1"))
|
exists, _ := util.IsExist(repo_model.RepoPath("user2", "repo1"))
|
||||||
assert.True(t, exists)
|
assert.True(t, exists)
|
||||||
|
|
||||||
err := repo_model.CheckCreateRepository(db.DefaultContext, user, user, "repo1", false)
|
err := repo_model.CheckCreateRepository(db.DefaultContext, user, user, "repo1")
|
||||||
|
|
||||||
require.ErrorIs(t, err, repo_model.ErrRepoAlreadyExist{Name: "repo1", Uname: "user2"})
|
require.ErrorIs(t, err, repo_model.ErrRepoAlreadyExist{Name: "repo1", Uname: "user2"})
|
||||||
})
|
})
|
||||||
|
|
|
@ -239,7 +239,7 @@ func MigratePost(ctx *context.Context) {
|
||||||
opts.Releases = false
|
opts.Releases = false
|
||||||
}
|
}
|
||||||
|
|
||||||
err = repo_model.CheckCreateRepository(ctx, ctx.Doer, ctxUser, opts.RepoName, false)
|
err = repo_model.CheckCreateRepository(ctx, ctx.Doer, ctxUser, opts.RepoName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleMigrateError(ctx, ctxUser, err, "MigratePost", tpl, form)
|
handleMigrateError(ctx, ctxUser, err, "MigratePost", tpl, form)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue