@@ -16,9 +16,7 @@ import (
16
16
"code.gitea.io/gitea/models/db"
17
17
issues_model "code.gitea.io/gitea/models/issues"
18
18
"code.gitea.io/gitea/models/organization"
19
- access_model "code.gitea.io/gitea/models/perm/access"
20
19
repo_model "code.gitea.io/gitea/models/repo"
21
- "code.gitea.io/gitea/models/unit"
22
20
user_model "code.gitea.io/gitea/models/user"
23
21
"code.gitea.io/gitea/modules/git"
24
22
"code.gitea.io/gitea/modules/log"
@@ -200,15 +198,13 @@ func (a *Action) LoadActUser(ctx context.Context) {
200
198
}
201
199
}
202
200
203
- func (a * Action ) LoadRepo (ctx context.Context ) {
201
+ func (a * Action ) LoadRepo (ctx context.Context ) error {
204
202
if a .Repo != nil {
205
- return
203
+ return nil
206
204
}
207
205
var err error
208
206
a .Repo , err = repo_model .GetRepositoryByID (ctx , a .RepoID )
209
- if err != nil {
210
- log .Error ("repo_model.GetRepositoryByID(%d): %v" , a .RepoID , err )
211
- }
207
+ return err
212
208
}
213
209
214
210
// GetActFullName gets the action's user full name.
@@ -250,7 +246,7 @@ func (a *Action) GetActDisplayNameTitle(ctx context.Context) string {
250
246
251
247
// GetRepoUserName returns the name of the action repository owner.
252
248
func (a * Action ) GetRepoUserName (ctx context.Context ) string {
253
- a .LoadRepo (ctx )
249
+ _ = a .LoadRepo (ctx )
254
250
if a .Repo == nil {
255
251
return "(non-existing-repo)"
256
252
}
@@ -265,7 +261,7 @@ func (a *Action) ShortRepoUserName(ctx context.Context) string {
265
261
266
262
// GetRepoName returns the name of the action repository.
267
263
func (a * Action ) GetRepoName (ctx context.Context ) string {
268
- a .LoadRepo (ctx )
264
+ _ = a .LoadRepo (ctx )
269
265
if a .Repo == nil {
270
266
return "(non-existing-repo)"
271
267
}
@@ -567,130 +563,6 @@ func DeleteOldActions(ctx context.Context, olderThan time.Duration) (err error)
567
563
return err
568
564
}
569
565
570
- // NotifyWatchers creates batch of actions for every watcher.
571
- // It could insert duplicate actions for a repository action, like this:
572
- // * Original action: UserID=1 (the real actor), ActUserID=1
573
- // * Organization action: UserID=100 (the repo's org), ActUserID=1
574
- // * Watcher action: UserID=20 (a user who is watching a repo), ActUserID=1
575
- func NotifyWatchers (ctx context.Context , actions ... * Action ) error {
576
- var watchers []* repo_model.Watch
577
- var repo * repo_model.Repository
578
- var err error
579
- var permCode []bool
580
- var permIssue []bool
581
- var permPR []bool
582
-
583
- e := db .GetEngine (ctx )
584
-
585
- for _ , act := range actions {
586
- repoChanged := repo == nil || repo .ID != act .RepoID
587
-
588
- if repoChanged {
589
- // Add feeds for user self and all watchers.
590
- watchers , err = repo_model .GetWatchers (ctx , act .RepoID )
591
- if err != nil {
592
- return fmt .Errorf ("get watchers: %w" , err )
593
- }
594
- }
595
-
596
- // Add feed for actioner.
597
- act .UserID = act .ActUserID
598
- if _ , err = e .Insert (act ); err != nil {
599
- return fmt .Errorf ("insert new actioner: %w" , err )
600
- }
601
-
602
- if repoChanged {
603
- act .LoadRepo (ctx )
604
- repo = act .Repo
605
-
606
- // check repo owner exist.
607
- if err := act .Repo .LoadOwner (ctx ); err != nil {
608
- return fmt .Errorf ("can't get repo owner: %w" , err )
609
- }
610
- } else if act .Repo == nil {
611
- act .Repo = repo
612
- }
613
-
614
- // Add feed for organization
615
- if act .Repo .Owner .IsOrganization () && act .ActUserID != act .Repo .Owner .ID {
616
- act .ID = 0
617
- act .UserID = act .Repo .Owner .ID
618
- if err = db .Insert (ctx , act ); err != nil {
619
- return fmt .Errorf ("insert new actioner: %w" , err )
620
- }
621
- }
622
-
623
- if repoChanged {
624
- permCode = make ([]bool , len (watchers ))
625
- permIssue = make ([]bool , len (watchers ))
626
- permPR = make ([]bool , len (watchers ))
627
- for i , watcher := range watchers {
628
- user , err := user_model .GetUserByID (ctx , watcher .UserID )
629
- if err != nil {
630
- permCode [i ] = false
631
- permIssue [i ] = false
632
- permPR [i ] = false
633
- continue
634
- }
635
- perm , err := access_model .GetUserRepoPermission (ctx , repo , user )
636
- if err != nil {
637
- permCode [i ] = false
638
- permIssue [i ] = false
639
- permPR [i ] = false
640
- continue
641
- }
642
- permCode [i ] = perm .CanRead (unit .TypeCode )
643
- permIssue [i ] = perm .CanRead (unit .TypeIssues )
644
- permPR [i ] = perm .CanRead (unit .TypePullRequests )
645
- }
646
- }
647
-
648
- for i , watcher := range watchers {
649
- if act .ActUserID == watcher .UserID {
650
- continue
651
- }
652
- act .ID = 0
653
- act .UserID = watcher .UserID
654
- act .Repo .Units = nil
655
-
656
- switch act .OpType {
657
- case ActionCommitRepo , ActionPushTag , ActionDeleteTag , ActionPublishRelease , ActionDeleteBranch :
658
- if ! permCode [i ] {
659
- continue
660
- }
661
- case ActionCreateIssue , ActionCommentIssue , ActionCloseIssue , ActionReopenIssue :
662
- if ! permIssue [i ] {
663
- continue
664
- }
665
- case ActionCreatePullRequest , ActionCommentPull , ActionMergePullRequest , ActionClosePullRequest , ActionReopenPullRequest , ActionAutoMergePullRequest :
666
- if ! permPR [i ] {
667
- continue
668
- }
669
- }
670
-
671
- if err = db .Insert (ctx , act ); err != nil {
672
- return fmt .Errorf ("insert new action: %w" , err )
673
- }
674
- }
675
- }
676
- return nil
677
- }
678
-
679
- // NotifyWatchersActions creates batch of actions for every watcher.
680
- func NotifyWatchersActions (ctx context.Context , acts []* Action ) error {
681
- ctx , committer , err := db .TxContext (ctx )
682
- if err != nil {
683
- return err
684
- }
685
- defer committer .Close ()
686
- for _ , act := range acts {
687
- if err := NotifyWatchers (ctx , act ); err != nil {
688
- return err
689
- }
690
- }
691
- return committer .Commit ()
692
- }
693
-
694
566
// DeleteIssueActions delete all actions related with issueID
695
567
func DeleteIssueActions (ctx context.Context , repoID , issueID , issueIndex int64 ) error {
696
568
// delete actions assigned to this issue
0 commit comments