aboutsummaryrefslogtreecommitdiffstats
path: root/services/repository/fork.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-08-25 10:31:57 +0800
committerGitHub <noreply@github.com>2022-08-25 10:31:57 +0800
commit1d8543e7db58d7c4973758e47f005c4d8bd7d7a3 (patch)
treeb60c99e2dfd69ccb998f8a0829d98d7cadcf0d6b /services/repository/fork.go
parent4a4bfafa238bf48851f8c11fa3701bd42b912475 (diff)
downloadgitea-1d8543e7db58d7c4973758e47f005c4d8bd7d7a3.tar.gz
gitea-1d8543e7db58d7c4973758e47f005c4d8bd7d7a3.zip
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>
Diffstat (limited to 'services/repository/fork.go')
-rw-r--r--services/repository/fork.go22
1 files changed, 19 insertions, 3 deletions
diff --git a/services/repository/fork.go b/services/repository/fork.go
index b274585ed5..96c391e715 100644
--- a/services/repository/fork.go
+++ b/services/repository/fork.go
@@ -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
}