mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-31 03:18:24 +00:00 
			
		
		
		
	Move some files into models' sub packages (#20262)
* Move some files into models' sub packages * Move functions * merge main branch * Fix check * fix check * Fix some tests * Fix lint * Fix lint * Revert lint changes * Fix error comments * Fix lint Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
		| @@ -10,7 +10,6 @@ import ( | ||||
| 	"strings" | ||||
| 	"time" | ||||
|  | ||||
| 	"code.gitea.io/gitea/models" | ||||
| 	"code.gitea.io/gitea/models/db" | ||||
| 	git_model "code.gitea.io/gitea/models/git" | ||||
| 	repo_model "code.gitea.io/gitea/models/repo" | ||||
| @@ -23,6 +22,23 @@ import ( | ||||
| 	"code.gitea.io/gitea/modules/util" | ||||
| ) | ||||
|  | ||||
| // 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) | ||||
| } | ||||
|  | ||||
| // ForkRepoOptions contains the fork repository options | ||||
| type ForkRepoOptions struct { | ||||
| 	BaseRepo    *repo_model.Repository | ||||
| @@ -37,7 +53,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	if forkedRepo != nil { | ||||
| 		return nil, models.ErrForkAlreadyExist{ | ||||
| 		return nil, ErrForkAlreadyExist{ | ||||
| 			Uname:    owner.Name, | ||||
| 			RepoName: opts.BaseRepo.FullName(), | ||||
| 			ForkName: forkedRepo.FullName(), | ||||
| @@ -93,7 +109,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork | ||||
| 	}() | ||||
|  | ||||
| 	err = db.WithTx(func(txCtx context.Context) error { | ||||
| 		if err = models.CreateRepository(txCtx, doer, owner, repo, false); err != nil { | ||||
| 		if err = repo_module.CreateRepositoryByExample(txCtx, doer, owner, repo, false); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user