@@ -13,6 +13,8 @@ import (
1313 "code.gitea.io/gitea/models/unit"
1414 user_model "code.gitea.io/gitea/models/user"
1515 "code.gitea.io/gitea/modules/container"
16+ "code.gitea.io/gitea/modules/git"
17+ "code.gitea.io/gitea/modules/gitrepo"
1618 "code.gitea.io/gitea/modules/log"
1719 "code.gitea.io/gitea/modules/util"
1820
@@ -457,12 +459,25 @@ func (nl NotificationList) LoadComments(ctx context.Context) ([]int, error) {
457459 return failures , nil
458460}
459461
462+ func (nl NotificationList ) getPendingReleaseIDs () []int64 {
463+ ids := make (container.Set [int64 ], len (nl ))
464+ for _ , notification := range nl {
465+ if notification .Release != nil {
466+ continue
467+ }
468+ if notification .ReleaseID > 0 {
469+ ids .Add (notification .ReleaseID )
470+ }
471+ }
472+ return ids .Values ()
473+ }
474+
460475func (nl NotificationList ) LoadReleases (ctx context.Context ) ([]int , error ) {
461476 if len (nl ) == 0 {
462477 return []int {}, nil
463478 }
464479
465- releaseIDs := nl .getPendingCommentIDs ()
480+ releaseIDs := nl .getPendingReleaseIDs ()
466481 releases := make (map [int64 ]* repo_model.Release , len (releaseIDs ))
467482 if err := db .GetEngine (ctx ).In ("id" , releaseIDs ).Find (& releases ); err != nil {
468483 return nil , err
@@ -482,6 +497,50 @@ func (nl NotificationList) LoadReleases(ctx context.Context) ([]int, error) {
482497 return failures , nil
483498}
484499
500+ func (nl NotificationList ) LoadCommits (ctx context.Context ) ([]int , error ) {
501+ if len (nl ) == 0 {
502+ return []int {}, nil
503+ }
504+
505+ _ , _ , err := nl .LoadRepos (ctx )
506+ if err != nil {
507+ return nil , err
508+ }
509+
510+ failures := []int {}
511+ repos := make (map [int64 ]* git.Repository , len (nl ))
512+ for i , n := range nl {
513+ if n .Source != NotificationSourceCommit || n .CommitID == "" {
514+ continue
515+ }
516+
517+ repo , ok := repos [n .RepoID ]
518+ if ! ok {
519+ repo , err = gitrepo .OpenRepository (ctx , n .Repository )
520+ if err != nil {
521+ log .Error ("Notification[%d]: Failed to get repo for commit %s: %v" , n .ID , n .CommitID , err )
522+ failures = append (failures , i )
523+ continue
524+ }
525+ repos [n .RepoID ] = repo
526+ }
527+ n .Commit , err = repo .GetCommit (n .CommitID )
528+ if err != nil {
529+ log .Error ("Notification[%d]: Failed to get repo for commit %s: %v" , n .ID , n .CommitID , err )
530+ failures = append (failures , i )
531+ continue
532+ }
533+ }
534+
535+ for _ , repo := range repos {
536+ if err := repo .Close (); err != nil {
537+ log .Error ("Failed to close repository: %v" , err )
538+ }
539+ }
540+
541+ return failures , nil
542+ }
543+
485544// LoadIssuePullRequests loads all issues' pull requests if possible
486545func (nl NotificationList ) LoadIssuePullRequests (ctx context.Context ) error {
487546 issues := make (map [int64 ]* issues_model.Issue , len (nl ))
0 commit comments