@@ -208,91 +208,91 @@ func (a *Action) loadRepo(ctx context.Context) {
208
208
}
209
209
210
210
// GetActFullName gets the action's user full name.
211
- func (a * Action ) GetActFullName () string {
212
- a .LoadActUser (db . DefaultContext )
211
+ func (a * Action ) GetActFullName (ctx context. Context ) string {
212
+ a .LoadActUser (ctx )
213
213
return a .ActUser .FullName
214
214
}
215
215
216
216
// GetActUserName gets the action's user name.
217
- func (a * Action ) GetActUserName () string {
218
- a .LoadActUser (db . DefaultContext )
217
+ func (a * Action ) GetActUserName (ctx context. Context ) string {
218
+ a .LoadActUser (ctx )
219
219
return a .ActUser .Name
220
220
}
221
221
222
222
// ShortActUserName gets the action's user name trimmed to max 20
223
223
// chars.
224
- func (a * Action ) ShortActUserName () string {
225
- return base .EllipsisString (a .GetActUserName (), 20 )
224
+ func (a * Action ) ShortActUserName (ctx context. Context ) string {
225
+ return base .EllipsisString (a .GetActUserName (ctx ), 20 )
226
226
}
227
227
228
228
// GetDisplayName gets the action's display name based on DEFAULT_SHOW_FULL_NAME, or falls back to the username if it is blank.
229
- func (a * Action ) GetDisplayName () string {
229
+ func (a * Action ) GetDisplayName (ctx context. Context ) string {
230
230
if setting .UI .DefaultShowFullName {
231
- trimmedFullName := strings .TrimSpace (a .GetActFullName ())
231
+ trimmedFullName := strings .TrimSpace (a .GetActFullName (ctx ))
232
232
if len (trimmedFullName ) > 0 {
233
233
return trimmedFullName
234
234
}
235
235
}
236
- return a .ShortActUserName ()
236
+ return a .ShortActUserName (ctx )
237
237
}
238
238
239
239
// GetDisplayNameTitle gets the action's display name used for the title (tooltip) based on DEFAULT_SHOW_FULL_NAME
240
- func (a * Action ) GetDisplayNameTitle () string {
240
+ func (a * Action ) GetDisplayNameTitle (ctx context. Context ) string {
241
241
if setting .UI .DefaultShowFullName {
242
- return a .ShortActUserName ()
242
+ return a .ShortActUserName (ctx )
243
243
}
244
- return a .GetActFullName ()
244
+ return a .GetActFullName (ctx )
245
245
}
246
246
247
247
// GetRepoUserName returns the name of the action repository owner.
248
- func (a * Action ) GetRepoUserName () string {
249
- a .loadRepo (db . DefaultContext )
248
+ func (a * Action ) GetRepoUserName (ctx context. Context ) string {
249
+ a .loadRepo (ctx )
250
250
return a .Repo .OwnerName
251
251
}
252
252
253
253
// ShortRepoUserName returns the name of the action repository owner
254
254
// trimmed to max 20 chars.
255
- func (a * Action ) ShortRepoUserName () string {
256
- return base .EllipsisString (a .GetRepoUserName (), 20 )
255
+ func (a * Action ) ShortRepoUserName (ctx context. Context ) string {
256
+ return base .EllipsisString (a .GetRepoUserName (ctx ), 20 )
257
257
}
258
258
259
259
// GetRepoName returns the name of the action repository.
260
- func (a * Action ) GetRepoName () string {
261
- a .loadRepo (db . DefaultContext )
260
+ func (a * Action ) GetRepoName (ctx context. Context ) string {
261
+ a .loadRepo (ctx )
262
262
return a .Repo .Name
263
263
}
264
264
265
265
// ShortRepoName returns the name of the action repository
266
266
// trimmed to max 33 chars.
267
- func (a * Action ) ShortRepoName () string {
268
- return base .EllipsisString (a .GetRepoName (), 33 )
267
+ func (a * Action ) ShortRepoName (ctx context. Context ) string {
268
+ return base .EllipsisString (a .GetRepoName (ctx ), 33 )
269
269
}
270
270
271
271
// GetRepoPath returns the virtual path to the action repository.
272
- func (a * Action ) GetRepoPath () string {
273
- return path .Join (a .GetRepoUserName (), a .GetRepoName ())
272
+ func (a * Action ) GetRepoPath (ctx context. Context ) string {
273
+ return path .Join (a .GetRepoUserName (ctx ), a .GetRepoName (ctx ))
274
274
}
275
275
276
276
// ShortRepoPath returns the virtual path to the action repository
277
277
// trimmed to max 20 + 1 + 33 chars.
278
- func (a * Action ) ShortRepoPath () string {
279
- return path .Join (a .ShortRepoUserName (), a .ShortRepoName ())
278
+ func (a * Action ) ShortRepoPath (ctx context. Context ) string {
279
+ return path .Join (a .ShortRepoUserName (ctx ), a .ShortRepoName (ctx ))
280
280
}
281
281
282
282
// GetRepoLink returns relative link to action repository.
283
- func (a * Action ) GetRepoLink () string {
283
+ func (a * Action ) GetRepoLink (ctx context. Context ) string {
284
284
// path.Join will skip empty strings
285
- return path .Join (setting .AppSubURL , "/" , url .PathEscape (a .GetRepoUserName ()), url .PathEscape (a .GetRepoName ()))
285
+ return path .Join (setting .AppSubURL , "/" , url .PathEscape (a .GetRepoUserName (ctx )), url .PathEscape (a .GetRepoName (ctx )))
286
286
}
287
287
288
288
// GetRepoAbsoluteLink returns the absolute link to action repository.
289
- func (a * Action ) GetRepoAbsoluteLink () string {
290
- return setting .AppURL + url .PathEscape (a .GetRepoUserName ()) + "/" + url .PathEscape (a .GetRepoName ())
289
+ func (a * Action ) GetRepoAbsoluteLink (ctx context. Context ) string {
290
+ return setting .AppURL + url .PathEscape (a .GetRepoUserName (ctx )) + "/" + url .PathEscape (a .GetRepoName (ctx ))
291
291
}
292
292
293
293
// GetCommentHTMLURL returns link to action comment.
294
- func (a * Action ) GetCommentHTMLURL () string {
295
- return a .getCommentHTMLURL (db . DefaultContext )
294
+ func (a * Action ) GetCommentHTMLURL (ctx context. Context ) string {
295
+ return a .getCommentHTMLURL (ctx )
296
296
}
297
297
298
298
func (a * Action ) loadComment (ctx context.Context ) (err error ) {
@@ -309,7 +309,7 @@ func (a *Action) getCommentHTMLURL(ctx context.Context) string {
309
309
}
310
310
_ = a .loadComment (ctx )
311
311
if a .Comment != nil {
312
- return a .Comment .HTMLURL ()
312
+ return a .Comment .HTMLURL (ctx )
313
313
}
314
314
if len (a .GetIssueInfos ()) == 0 {
315
315
return "#"
@@ -334,8 +334,8 @@ func (a *Action) getCommentHTMLURL(ctx context.Context) string {
334
334
}
335
335
336
336
// GetCommentLink returns link to action comment.
337
- func (a * Action ) GetCommentLink () string {
338
- return a .getCommentLink (db . DefaultContext )
337
+ func (a * Action ) GetCommentLink (ctx context. Context ) string {
338
+ return a .getCommentLink (ctx )
339
339
}
340
340
341
341
func (a * Action ) getCommentLink (ctx context.Context ) string {
@@ -344,7 +344,7 @@ func (a *Action) getCommentLink(ctx context.Context) string {
344
344
}
345
345
_ = a .loadComment (ctx )
346
346
if a .Comment != nil {
347
- return a .Comment .Link ()
347
+ return a .Comment .Link (ctx )
348
348
}
349
349
if len (a .GetIssueInfos ()) == 0 {
350
350
return "#"
@@ -374,8 +374,8 @@ func (a *Action) GetBranch() string {
374
374
}
375
375
376
376
// GetRefLink returns the action's ref link.
377
- func (a * Action ) GetRefLink () string {
378
- return git .RefURL (a .GetRepoLink (), a .RefName )
377
+ func (a * Action ) GetRefLink (ctx context. Context ) string {
378
+ return git .RefURL (a .GetRepoLink (ctx ), a .RefName )
379
379
}
380
380
381
381
// GetTag returns the action's repository tag.
@@ -399,11 +399,10 @@ func (a *Action) GetIssueInfos() []string {
399
399
return strings .SplitN (a .Content , "|" , 3 )
400
400
}
401
401
402
- // GetIssueTitle returns the title of first issue associated
403
- // with the action. This function will be invoked in template so keep db.DefaultContext here
404
- func (a * Action ) GetIssueTitle () string {
402
+ // GetIssueTitle returns the title of first issue associated with the action.
403
+ func (a * Action ) GetIssueTitle (ctx context.Context ) string {
405
404
index , _ := strconv .ParseInt (a .GetIssueInfos ()[0 ], 10 , 64 )
406
- issue , err := issues_model .GetIssueByIndex (db . DefaultContext , a .RepoID , index )
405
+ issue , err := issues_model .GetIssueByIndex (ctx , a .RepoID , index )
407
406
if err != nil {
408
407
log .Error ("GetIssueByIndex: %v" , err )
409
408
return "500 when get issue"
@@ -442,7 +441,7 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
442
441
return nil , 0 , fmt .Errorf ("need at least one of these filters: RequestedUser, RequestedTeam, RequestedRepo" )
443
442
}
444
443
445
- cond , err := activityQueryCondition (opts )
444
+ cond , err := activityQueryCondition (ctx , opts )
446
445
if err != nil {
447
446
return nil , 0 , err
448
447
}
@@ -473,11 +472,11 @@ func ActivityReadable(user, doer *user_model.User) bool {
473
472
doer != nil && (doer .IsAdmin || user .ID == doer .ID )
474
473
}
475
474
476
- func activityQueryCondition (opts GetFeedsOptions ) (builder.Cond , error ) {
475
+ func activityQueryCondition (ctx context. Context , opts GetFeedsOptions ) (builder.Cond , error ) {
477
476
cond := builder .NewCond ()
478
477
479
478
if opts .RequestedTeam != nil && opts .RequestedUser == nil {
480
- org , err := user_model .GetUserByID (db . DefaultContext , opts .RequestedTeam .OrgID )
479
+ org , err := user_model .GetUserByID (ctx , opts .RequestedTeam .OrgID )
481
480
if err != nil {
482
481
return nil , err
483
482
}
@@ -564,12 +563,12 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
564
563
}
565
564
566
565
// DeleteOldActions deletes all old actions from database.
567
- func DeleteOldActions (olderThan time.Duration ) (err error ) {
566
+ func DeleteOldActions (ctx context. Context , olderThan time.Duration ) (err error ) {
568
567
if olderThan <= 0 {
569
568
return nil
570
569
}
571
570
572
- _ , err = db .GetEngine (db . DefaultContext ).Where ("created_unix < ?" , time .Now ().Add (- olderThan ).Unix ()).Delete (& Action {})
571
+ _ , err = db .GetEngine (ctx ).Where ("created_unix < ?" , time .Now ().Add (- olderThan ).Unix ()).Delete (& Action {})
573
572
return err
574
573
}
575
574
@@ -679,8 +678,8 @@ func NotifyWatchers(ctx context.Context, actions ...*Action) error {
679
678
}
680
679
681
680
// NotifyWatchersActions creates batch of actions for every watcher.
682
- func NotifyWatchersActions (acts []* Action ) error {
683
- ctx , committer , err := db .TxContext (db . DefaultContext )
681
+ func NotifyWatchersActions (ctx context. Context , acts []* Action ) error {
682
+ ctx , committer , err := db .TxContext (ctx )
684
683
if err != nil {
685
684
return err
686
685
}
0 commit comments