@@ -17,7 +17,6 @@ import (
17
17
"unicode"
18
18
19
19
"code.gitea.io/gitea/modules/base"
20
- "code.gitea.io/gitea/modules/git"
21
20
"code.gitea.io/gitea/modules/log"
22
21
"code.gitea.io/gitea/modules/setting"
23
22
api "code.gitea.io/gitea/modules/structs"
@@ -441,6 +440,9 @@ func (pc *PushCommits) ToAPIPayloadCommits(repoLink string) []*api.PayloadCommit
441
440
// AvatarLink tries to match user in database with e-mail
442
441
// in order to show custom avatar, and falls back to general avatar link.
443
442
func (pc * PushCommits ) AvatarLink (email string ) string {
443
+ if pc .avatars == nil {
444
+ pc .avatars = make (map [string ]string )
445
+ }
444
446
avatar , ok := pc .avatars [email ]
445
447
if ok {
446
448
return avatar
@@ -655,200 +657,6 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit, bra
655
657
return nil
656
658
}
657
659
658
- // CommitRepoActionOptions represent options of a new commit action.
659
- type CommitRepoActionOptions struct {
660
- PusherName string
661
- RepoOwnerID int64
662
- RepoName string
663
- RefFullName string
664
- OldCommitID string
665
- NewCommitID string
666
- Commits * PushCommits
667
- }
668
-
669
- // CommitRepoAction adds new commit action to the repository, and prepare
670
- // corresponding webhooks.
671
- func CommitRepoAction (opts CommitRepoActionOptions ) error {
672
- pusher , err := GetUserByName (opts .PusherName )
673
- if err != nil {
674
- return fmt .Errorf ("GetUserByName [%s]: %v" , opts .PusherName , err )
675
- }
676
-
677
- repo , err := GetRepositoryByName (opts .RepoOwnerID , opts .RepoName )
678
- if err != nil {
679
- return fmt .Errorf ("GetRepositoryByName [owner_id: %d, name: %s]: %v" , opts .RepoOwnerID , opts .RepoName , err )
680
- }
681
-
682
- refName := git .RefEndName (opts .RefFullName )
683
-
684
- // Change default branch and empty status only if pushed ref is non-empty branch.
685
- if repo .IsEmpty && opts .NewCommitID != git .EmptySHA && strings .HasPrefix (opts .RefFullName , git .BranchPrefix ) {
686
- repo .DefaultBranch = refName
687
- repo .IsEmpty = false
688
- if refName != "master" {
689
- gitRepo , err := git .OpenRepository (repo .RepoPath ())
690
- if err != nil {
691
- return err
692
- }
693
- if err := gitRepo .SetDefaultBranch (repo .DefaultBranch ); err != nil {
694
- if ! git .IsErrUnsupportedVersion (err ) {
695
- return err
696
- }
697
- }
698
- }
699
- }
700
-
701
- // Change repository empty status and update last updated time.
702
- if err = UpdateRepository (repo , false ); err != nil {
703
- return fmt .Errorf ("UpdateRepository: %v" , err )
704
- }
705
-
706
- isNewBranch := false
707
- opType := ActionCommitRepo
708
- // Check it's tag push or branch.
709
- if strings .HasPrefix (opts .RefFullName , git .TagPrefix ) {
710
- opType = ActionPushTag
711
- if opts .NewCommitID == git .EmptySHA {
712
- opType = ActionDeleteTag
713
- }
714
- opts .Commits = & PushCommits {}
715
- } else if opts .NewCommitID == git .EmptySHA {
716
- opType = ActionDeleteBranch
717
- opts .Commits = & PushCommits {}
718
- } else {
719
- // if not the first commit, set the compare URL.
720
- if opts .OldCommitID == git .EmptySHA {
721
- isNewBranch = true
722
- } else {
723
- opts .Commits .CompareURL = repo .ComposeCompareURL (opts .OldCommitID , opts .NewCommitID )
724
- }
725
-
726
- if err = UpdateIssuesCommit (pusher , repo , opts .Commits .Commits , refName ); err != nil {
727
- log .Error ("updateIssuesCommit: %v" , err )
728
- }
729
- }
730
-
731
- if len (opts .Commits .Commits ) > setting .UI .FeedMaxCommitNum {
732
- opts .Commits .Commits = opts .Commits .Commits [:setting .UI .FeedMaxCommitNum ]
733
- }
734
-
735
- data , err := json .Marshal (opts .Commits )
736
- if err != nil {
737
- return fmt .Errorf ("Marshal: %v" , err )
738
- }
739
-
740
- if err = NotifyWatchers (& Action {
741
- ActUserID : pusher .ID ,
742
- ActUser : pusher ,
743
- OpType : opType ,
744
- Content : string (data ),
745
- RepoID : repo .ID ,
746
- Repo : repo ,
747
- RefName : refName ,
748
- IsPrivate : repo .IsPrivate ,
749
- }); err != nil {
750
- return fmt .Errorf ("NotifyWatchers: %v" , err )
751
- }
752
-
753
- defer func () {
754
- go HookQueue .Add (repo .ID )
755
- }()
756
-
757
- apiPusher := pusher .APIFormat ()
758
- apiRepo := repo .APIFormat (AccessModeNone )
759
-
760
- var shaSum string
761
- var isHookEventPush = false
762
- switch opType {
763
- case ActionCommitRepo : // Push
764
- isHookEventPush = true
765
-
766
- if isNewBranch {
767
- gitRepo , err := git .OpenRepository (repo .RepoPath ())
768
- if err != nil {
769
- log .Error ("OpenRepository[%s]: %v" , repo .RepoPath (), err )
770
- }
771
-
772
- shaSum , err = gitRepo .GetBranchCommitID (refName )
773
- if err != nil {
774
- log .Error ("GetBranchCommitID[%s]: %v" , opts .RefFullName , err )
775
- }
776
- if err = PrepareWebhooks (repo , HookEventCreate , & api.CreatePayload {
777
- Ref : refName ,
778
- Sha : shaSum ,
779
- RefType : "branch" ,
780
- Repo : apiRepo ,
781
- Sender : apiPusher ,
782
- }); err != nil {
783
- return fmt .Errorf ("PrepareWebhooks: %v" , err )
784
- }
785
- }
786
-
787
- case ActionDeleteBranch : // Delete Branch
788
- isHookEventPush = true
789
-
790
- if err = PrepareWebhooks (repo , HookEventDelete , & api.DeletePayload {
791
- Ref : refName ,
792
- RefType : "branch" ,
793
- PusherType : api .PusherTypeUser ,
794
- Repo : apiRepo ,
795
- Sender : apiPusher ,
796
- }); err != nil {
797
- return fmt .Errorf ("PrepareWebhooks.(delete branch): %v" , err )
798
- }
799
-
800
- case ActionPushTag : // Create
801
- isHookEventPush = true
802
-
803
- gitRepo , err := git .OpenRepository (repo .RepoPath ())
804
- if err != nil {
805
- log .Error ("OpenRepository[%s]: %v" , repo .RepoPath (), err )
806
- }
807
- shaSum , err = gitRepo .GetTagCommitID (refName )
808
- if err != nil {
809
- log .Error ("GetTagCommitID[%s]: %v" , opts .RefFullName , err )
810
- }
811
- if err = PrepareWebhooks (repo , HookEventCreate , & api.CreatePayload {
812
- Ref : refName ,
813
- Sha : shaSum ,
814
- RefType : "tag" ,
815
- Repo : apiRepo ,
816
- Sender : apiPusher ,
817
- }); err != nil {
818
- return fmt .Errorf ("PrepareWebhooks: %v" , err )
819
- }
820
- case ActionDeleteTag : // Delete Tag
821
- isHookEventPush = true
822
-
823
- if err = PrepareWebhooks (repo , HookEventDelete , & api.DeletePayload {
824
- Ref : refName ,
825
- RefType : "tag" ,
826
- PusherType : api .PusherTypeUser ,
827
- Repo : apiRepo ,
828
- Sender : apiPusher ,
829
- }); err != nil {
830
- return fmt .Errorf ("PrepareWebhooks.(delete tag): %v" , err )
831
- }
832
- }
833
-
834
- if isHookEventPush {
835
- if err = PrepareWebhooks (repo , HookEventPush , & api.PushPayload {
836
- Ref : opts .RefFullName ,
837
- Before : opts .OldCommitID ,
838
- After : opts .NewCommitID ,
839
- CompareURL : setting .AppURL + opts .Commits .CompareURL ,
840
- Commits : opts .Commits .ToAPIPayloadCommits (repo .HTMLURL ()),
841
- Repo : apiRepo ,
842
- Pusher : apiPusher ,
843
- Sender : apiPusher ,
844
- }); err != nil {
845
- return fmt .Errorf ("PrepareWebhooks: %v" , err )
846
- }
847
- }
848
-
849
- return nil
850
- }
851
-
852
660
func transferRepoAction (e Engine , doer , oldOwner * User , repo * Repository ) (err error ) {
853
661
if err = notifyWatchers (e , & Action {
854
662
ActUserID : doer .ID ,
0 commit comments