@@ -7,7 +7,6 @@ package base
7
7
8
8
import (
9
9
"context"
10
- "time"
11
10
12
11
"code.gitea.io/gitea/modules/structs"
13
12
)
@@ -24,220 +23,11 @@ type Downloader interface {
24
23
GetComments (issueNumber int64 ) ([]* Comment , error )
25
24
GetPullRequests (page , perPage int ) ([]* PullRequest , bool , error )
26
25
GetReviews (pullRequestNumber int64 ) ([]* Review , error )
26
+ FormatCloneURL (opts MigrateOptions , remoteAddr string ) (string , error )
27
27
}
28
28
29
29
// DownloaderFactory defines an interface to match a downloader implementation and create a downloader
30
30
type DownloaderFactory interface {
31
31
New (ctx context.Context , opts MigrateOptions ) (Downloader , error )
32
32
GitServiceType () structs.GitServiceType
33
33
}
34
-
35
- var (
36
- _ Downloader = & RetryDownloader {}
37
- )
38
-
39
- // RetryDownloader retry the downloads
40
- type RetryDownloader struct {
41
- Downloader
42
- ctx context.Context
43
- RetryTimes int // the total execute times
44
- RetryDelay int // time to delay seconds
45
- }
46
-
47
- // NewRetryDownloader creates a retry downloader
48
- func NewRetryDownloader (ctx context.Context , downloader Downloader , retryTimes , retryDelay int ) * RetryDownloader {
49
- return & RetryDownloader {
50
- Downloader : downloader ,
51
- ctx : ctx ,
52
- RetryTimes : retryTimes ,
53
- RetryDelay : retryDelay ,
54
- }
55
- }
56
-
57
- // SetContext set context
58
- func (d * RetryDownloader ) SetContext (ctx context.Context ) {
59
- d .ctx = ctx
60
- d .Downloader .SetContext (ctx )
61
- }
62
-
63
- // GetRepoInfo returns a repository information with retry
64
- func (d * RetryDownloader ) GetRepoInfo () (* Repository , error ) {
65
- var (
66
- times = d .RetryTimes
67
- repo * Repository
68
- err error
69
- )
70
- for ; times > 0 ; times -- {
71
- if repo , err = d .Downloader .GetRepoInfo (); err == nil {
72
- return repo , nil
73
- }
74
- select {
75
- case <- d .ctx .Done ():
76
- return nil , d .ctx .Err ()
77
- case <- time .After (time .Second * time .Duration (d .RetryDelay )):
78
- }
79
- }
80
- return nil , err
81
- }
82
-
83
- // GetTopics returns a repository's topics with retry
84
- func (d * RetryDownloader ) GetTopics () ([]string , error ) {
85
- var (
86
- times = d .RetryTimes
87
- topics []string
88
- err error
89
- )
90
- for ; times > 0 ; times -- {
91
- if topics , err = d .Downloader .GetTopics (); err == nil {
92
- return topics , nil
93
- }
94
- select {
95
- case <- d .ctx .Done ():
96
- return nil , d .ctx .Err ()
97
- case <- time .After (time .Second * time .Duration (d .RetryDelay )):
98
- }
99
- }
100
- return nil , err
101
- }
102
-
103
- // GetMilestones returns a repository's milestones with retry
104
- func (d * RetryDownloader ) GetMilestones () ([]* Milestone , error ) {
105
- var (
106
- times = d .RetryTimes
107
- milestones []* Milestone
108
- err error
109
- )
110
- for ; times > 0 ; times -- {
111
- if milestones , err = d .Downloader .GetMilestones (); err == nil {
112
- return milestones , nil
113
- }
114
- select {
115
- case <- d .ctx .Done ():
116
- return nil , d .ctx .Err ()
117
- case <- time .After (time .Second * time .Duration (d .RetryDelay )):
118
- }
119
- }
120
- return nil , err
121
- }
122
-
123
- // GetReleases returns a repository's releases with retry
124
- func (d * RetryDownloader ) GetReleases () ([]* Release , error ) {
125
- var (
126
- times = d .RetryTimes
127
- releases []* Release
128
- err error
129
- )
130
- for ; times > 0 ; times -- {
131
- if releases , err = d .Downloader .GetReleases (); err == nil {
132
- return releases , nil
133
- }
134
- select {
135
- case <- d .ctx .Done ():
136
- return nil , d .ctx .Err ()
137
- case <- time .After (time .Second * time .Duration (d .RetryDelay )):
138
- }
139
- }
140
- return nil , err
141
- }
142
-
143
- // GetLabels returns a repository's labels with retry
144
- func (d * RetryDownloader ) GetLabels () ([]* Label , error ) {
145
- var (
146
- times = d .RetryTimes
147
- labels []* Label
148
- err error
149
- )
150
- for ; times > 0 ; times -- {
151
- if labels , err = d .Downloader .GetLabels (); err == nil {
152
- return labels , nil
153
- }
154
- select {
155
- case <- d .ctx .Done ():
156
- return nil , d .ctx .Err ()
157
- case <- time .After (time .Second * time .Duration (d .RetryDelay )):
158
- }
159
- }
160
- return nil , err
161
- }
162
-
163
- // GetIssues returns a repository's issues with retry
164
- func (d * RetryDownloader ) GetIssues (page , perPage int ) ([]* Issue , bool , error ) {
165
- var (
166
- times = d .RetryTimes
167
- issues []* Issue
168
- isEnd bool
169
- err error
170
- )
171
- for ; times > 0 ; times -- {
172
- if issues , isEnd , err = d .Downloader .GetIssues (page , perPage ); err == nil {
173
- return issues , isEnd , nil
174
- }
175
- select {
176
- case <- d .ctx .Done ():
177
- return nil , false , d .ctx .Err ()
178
- case <- time .After (time .Second * time .Duration (d .RetryDelay )):
179
- }
180
- }
181
- return nil , false , err
182
- }
183
-
184
- // GetComments returns a repository's comments with retry
185
- func (d * RetryDownloader ) GetComments (issueNumber int64 ) ([]* Comment , error ) {
186
- var (
187
- times = d .RetryTimes
188
- comments []* Comment
189
- err error
190
- )
191
- for ; times > 0 ; times -- {
192
- if comments , err = d .Downloader .GetComments (issueNumber ); err == nil {
193
- return comments , nil
194
- }
195
- select {
196
- case <- d .ctx .Done ():
197
- return nil , d .ctx .Err ()
198
- case <- time .After (time .Second * time .Duration (d .RetryDelay )):
199
- }
200
- }
201
- return nil , err
202
- }
203
-
204
- // GetPullRequests returns a repository's pull requests with retry
205
- func (d * RetryDownloader ) GetPullRequests (page , perPage int ) ([]* PullRequest , bool , error ) {
206
- var (
207
- times = d .RetryTimes
208
- prs []* PullRequest
209
- err error
210
- isEnd bool
211
- )
212
- for ; times > 0 ; times -- {
213
- if prs , isEnd , err = d .Downloader .GetPullRequests (page , perPage ); err == nil {
214
- return prs , isEnd , nil
215
- }
216
- select {
217
- case <- d .ctx .Done ():
218
- return nil , false , d .ctx .Err ()
219
- case <- time .After (time .Second * time .Duration (d .RetryDelay )):
220
- }
221
- }
222
- return nil , false , err
223
- }
224
-
225
- // GetReviews returns pull requests reviews
226
- func (d * RetryDownloader ) GetReviews (pullRequestNumber int64 ) ([]* Review , error ) {
227
- var (
228
- times = d .RetryTimes
229
- reviews []* Review
230
- err error
231
- )
232
- for ; times > 0 ; times -- {
233
- if reviews , err = d .Downloader .GetReviews (pullRequestNumber ); err == nil {
234
- return reviews , nil
235
- }
236
- select {
237
- case <- d .ctx .Done ():
238
- return nil , d .ctx .Err ()
239
- case <- time .After (time .Second * time .Duration (d .RetryDelay )):
240
- }
241
- }
242
- return nil , err
243
- }
0 commit comments