diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2020-01-12 20:11:17 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-12 20:11:17 +0800 |
commit | b465d0d78793da6e67890a7cb9d3ae1b807c53ca (patch) | |
tree | 1cdfb83699ad2fd31d5835bb2ac1e1b579eaf784 /models/task.go | |
parent | 5765212c6dbcaeb27779707af3ca57775e535bd9 (diff) | |
download | gitea-b465d0d78793da6e67890a7cb9d3ae1b807c53ca.tar.gz gitea-b465d0d78793da6e67890a7cb9d3ae1b807c53ca.zip |
Move create/fork repository from models to modules/repository (#9489)
* Move create/fork repository from models to modules/repository
* fix wrong reference
* fix test
* fix test
* fix lint
* Fix DBContext
* remove duplicated TestMain
* fix lint
* fix conflicts
Diffstat (limited to 'models/task.go')
-rw-r--r-- | models/task.go | 53 |
1 files changed, 5 insertions, 48 deletions
diff --git a/models/task.go b/models/task.go index e1d751bc3c..f4fce058c0 100644 --- a/models/task.go +++ b/models/task.go @@ -8,8 +8,6 @@ import ( "encoding/json" "fmt" - "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/migrations/base" "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" @@ -169,57 +167,16 @@ func FindTasks(opts FindTaskOptions) ([]*Task, error) { return tasks, err } +// CreateTask creates a task on database +func CreateTask(task *Task) error { + return createTask(x, task) +} + func createTask(e Engine, task *Task) error { _, err := e.Insert(task) return err } -// CreateMigrateTask creates a migrate task -func CreateMigrateTask(doer, u *User, opts base.MigrateOptions) (*Task, error) { - bs, err := json.Marshal(&opts) - if err != nil { - return nil, err - } - - var task = Task{ - DoerID: doer.ID, - OwnerID: u.ID, - Type: structs.TaskTypeMigrateRepo, - Status: structs.TaskStatusQueue, - PayloadContent: string(bs), - } - - if err := createTask(x, &task); err != nil { - return nil, err - } - - repo, err := CreateRepository(doer, u, CreateRepoOptions{ - Name: opts.RepoName, - Description: opts.Description, - OriginalURL: opts.OriginalURL, - GitServiceType: opts.GitServiceType, - IsPrivate: opts.Private, - IsMirror: opts.Mirror, - Status: RepositoryBeingMigrated, - }) - if err != nil { - task.EndTime = timeutil.TimeStampNow() - task.Status = structs.TaskStatusFailed - err2 := task.UpdateCols("end_time", "status") - if err2 != nil { - log.Error("UpdateCols Failed: %v", err2.Error()) - } - return nil, err - } - - task.RepoID = repo.ID - if err = task.UpdateCols("repo_id"); err != nil { - return nil, err - } - - return &task, nil -} - // FinishMigrateTask updates database when migrate task finished func FinishMigrateTask(task *Task) error { task.Status = structs.TaskStatusFinished |