@@ -208,91 +208,91 @@ func (a *Action) loadRepo(ctx context.Context) {
208208}
209209
210210// 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 )
213213 return a .ActUser .FullName
214214}
215215
216216// 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 )
219219 return a .ActUser .Name
220220}
221221
222222// ShortActUserName gets the action's user name trimmed to max 20
223223// 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 )
226226}
227227
228228// 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 {
230230 if setting .UI .DefaultShowFullName {
231- trimmedFullName := strings .TrimSpace (a .GetActFullName ())
231+ trimmedFullName := strings .TrimSpace (a .GetActFullName (ctx ))
232232 if len (trimmedFullName ) > 0 {
233233 return trimmedFullName
234234 }
235235 }
236- return a .ShortActUserName ()
236+ return a .ShortActUserName (ctx )
237237}
238238
239239// 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 {
241241 if setting .UI .DefaultShowFullName {
242- return a .ShortActUserName ()
242+ return a .ShortActUserName (ctx )
243243 }
244- return a .GetActFullName ()
244+ return a .GetActFullName (ctx )
245245}
246246
247247// 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 )
250250 return a .Repo .OwnerName
251251}
252252
253253// ShortRepoUserName returns the name of the action repository owner
254254// 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 )
257257}
258258
259259// 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 )
262262 return a .Repo .Name
263263}
264264
265265// ShortRepoName returns the name of the action repository
266266// 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 )
269269}
270270
271271// 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 ))
274274}
275275
276276// ShortRepoPath returns the virtual path to the action repository
277277// 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 ))
280280}
281281
282282// GetRepoLink returns relative link to action repository.
283- func (a * Action ) GetRepoLink () string {
283+ func (a * Action ) GetRepoLink (ctx context. Context ) string {
284284 // 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 )))
286286}
287287
288288// 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 ))
291291}
292292
293293// 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 )
296296}
297297
298298func (a * Action ) loadComment (ctx context.Context ) (err error ) {
@@ -309,7 +309,7 @@ func (a *Action) getCommentHTMLURL(ctx context.Context) string {
309309 }
310310 _ = a .loadComment (ctx )
311311 if a .Comment != nil {
312- return a .Comment .HTMLURL ()
312+ return a .Comment .HTMLURL (ctx )
313313 }
314314 if len (a .GetIssueInfos ()) == 0 {
315315 return "#"
@@ -334,8 +334,8 @@ func (a *Action) getCommentHTMLURL(ctx context.Context) string {
334334}
335335
336336// 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 )
339339}
340340
341341func (a * Action ) getCommentLink (ctx context.Context ) string {
@@ -344,7 +344,7 @@ func (a *Action) getCommentLink(ctx context.Context) string {
344344 }
345345 _ = a .loadComment (ctx )
346346 if a .Comment != nil {
347- return a .Comment .Link ()
347+ return a .Comment .Link (ctx )
348348 }
349349 if len (a .GetIssueInfos ()) == 0 {
350350 return "#"
@@ -374,8 +374,8 @@ func (a *Action) GetBranch() string {
374374}
375375
376376// 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 )
379379}
380380
381381// GetTag returns the action's repository tag.
@@ -399,11 +399,10 @@ func (a *Action) GetIssueInfos() []string {
399399 return strings .SplitN (a .Content , "|" , 3 )
400400}
401401
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 {
405404 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 )
407406 if err != nil {
408407 log .Error ("GetIssueByIndex: %v" , err )
409408 return "500 when get issue"
@@ -442,7 +441,7 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
442441 return nil , 0 , fmt .Errorf ("need at least one of these filters: RequestedUser, RequestedTeam, RequestedRepo" )
443442 }
444443
445- cond , err := activityQueryCondition (opts )
444+ cond , err := activityQueryCondition (ctx , opts )
446445 if err != nil {
447446 return nil , 0 , err
448447 }
@@ -473,11 +472,11 @@ func ActivityReadable(user, doer *user_model.User) bool {
473472 doer != nil && (doer .IsAdmin || user .ID == doer .ID )
474473}
475474
476- func activityQueryCondition (opts GetFeedsOptions ) (builder.Cond , error ) {
475+ func activityQueryCondition (ctx context. Context , opts GetFeedsOptions ) (builder.Cond , error ) {
477476 cond := builder .NewCond ()
478477
479478 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 )
481480 if err != nil {
482481 return nil , err
483482 }
@@ -564,12 +563,12 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
564563}
565564
566565// 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 ) {
568567 if olderThan <= 0 {
569568 return nil
570569 }
571570
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 {})
573572 return err
574573}
575574
@@ -679,8 +678,8 @@ func NotifyWatchers(ctx context.Context, actions ...*Action) error {
679678}
680679
681680// 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 )
684683 if err != nil {
685684 return err
686685 }
0 commit comments