5
5
package migrations
6
6
7
7
import (
8
- "code.gitea.io/gitea/models"
9
- "code.gitea.io/gitea/modules/migrations/base"
10
- "code.gitea.io/gitea/modules/structs"
11
8
"code.gitea.io/gitea/modules/util"
12
9
13
10
jsoniter "github.com/json-iterator/go"
@@ -16,20 +13,38 @@ import (
16
13
)
17
14
18
15
func deleteMigrationCredentials (x * xorm.Engine ) (err error ) {
16
+ // Task represents a task
17
+ type Task struct {
18
+ ID int64
19
+ DoerID int64 `xorm:"index"` // operator
20
+ OwnerID int64 `xorm:"index"` // repo owner id, when creating, the repoID maybe zero
21
+ RepoID int64 `xorm:"index"`
22
+ Type int
23
+ Status int `xorm:"index"`
24
+ StartTime int64
25
+ EndTime int64
26
+ PayloadContent string `xorm:"TEXT"`
27
+ Errors string `xorm:"TEXT"` // if task failed, saved the error reason
28
+ Created int64 `xorm:"created"`
29
+ }
30
+
31
+ const TaskTypeMigrateRepo = 0
32
+ const TaskStatusStopped = 2
33
+
19
34
const batchSize = 100
20
35
21
36
// only match migration tasks, that are not pending or running
22
37
cond := builder.Eq {
23
- "type" : structs . TaskTypeMigrateRepo ,
38
+ "type" : TaskTypeMigrateRepo ,
24
39
}.And (builder.Gte {
25
- "status" : structs . TaskStatusStopped ,
40
+ "status" : TaskStatusStopped ,
26
41
})
27
42
28
43
sess := x .NewSession ()
29
44
defer sess .Close ()
30
45
31
46
for start := 0 ; ; start += batchSize {
32
- tasks := make ([]* models. Task , 0 , batchSize )
47
+ tasks := make ([]* Task , 0 , batchSize )
33
48
if err = sess .Limit (batchSize , start ).Where (cond , 0 ).Find (& tasks ); err != nil {
34
49
return
35
50
}
@@ -55,7 +70,41 @@ func deleteMigrationCredentials(x *xorm.Engine) (err error) {
55
70
}
56
71
57
72
func removeCredentials (payload string ) (string , error ) {
58
- var opts base.MigrateOptions
73
+ // MigrateOptions defines the way a repository gets migrated
74
+ // this is for internal usage by migrations module and func who interact with it
75
+ type MigrateOptions struct {
76
+ // required: true
77
+ CloneAddr string `json:"clone_addr" binding:"Required"`
78
+ CloneAddrEncrypted string `json:"clone_addr_encrypted,omitempty"`
79
+ AuthUsername string `json:"auth_username"`
80
+ AuthPassword string `json:"-"`
81
+ AuthPasswordEncrypted string `json:"auth_password_encrypted,omitempty"`
82
+ AuthToken string `json:"-"`
83
+ AuthTokenEncrypted string `json:"auth_token_encrypted,omitempty"`
84
+ // required: true
85
+ UID int `json:"uid" binding:"Required"`
86
+ // required: true
87
+ RepoName string `json:"repo_name" binding:"Required"`
88
+ Mirror bool `json:"mirror"`
89
+ LFS bool `json:"lfs"`
90
+ LFSEndpoint string `json:"lfs_endpoint"`
91
+ Private bool `json:"private"`
92
+ Description string `json:"description"`
93
+ OriginalURL string
94
+ GitServiceType int
95
+ Wiki bool
96
+ Issues bool
97
+ Milestones bool
98
+ Labels bool
99
+ Releases bool
100
+ Comments bool
101
+ PullRequests bool
102
+ ReleaseAssets bool
103
+ MigrateToRepoID int64
104
+ MirrorInterval string `json:"mirror_interval"`
105
+ }
106
+
107
+ var opts MigrateOptions
59
108
json := jsoniter .ConfigCompatibleWithStandardLibrary
60
109
err := json .Unmarshal ([]byte (payload ), & opts )
61
110
if err != nil {
0 commit comments