@@ -6,6 +6,7 @@ package webhook
66import (
77 "context"
88
9+ git_model "code.gitea.io/gitea/models/git"
910 issues_model "code.gitea.io/gitea/models/issues"
1011 packages_model "code.gitea.io/gitea/models/packages"
1112 "code.gitea.io/gitea/models/perm"
@@ -15,6 +16,7 @@ import (
1516 "code.gitea.io/gitea/modules/git"
1617 "code.gitea.io/gitea/modules/log"
1718 "code.gitea.io/gitea/modules/repository"
19+ repo_module "code.gitea.io/gitea/modules/repository"
1820 "code.gitea.io/gitea/modules/setting"
1921 api "code.gitea.io/gitea/modules/structs"
2022 webhook_module "code.gitea.io/gitea/modules/webhook"
@@ -851,6 +853,36 @@ func (m *webhookNotifier) SyncPushCommits(ctx context.Context, pusher *user_mode
851853 }
852854}
853855
856+ func (m * webhookNotifier ) CreateCommitStatus (ctx context.Context , repo * repo_model.Repository , commit * repository.PushCommit , sender * user_model.User , status * git_model.CommitStatus ) {
857+ apiSender := convert .ToUser (ctx , sender , nil )
858+ apiCommit , err := repo_module .ToAPIPayloadCommit (ctx , map [string ]* user_model.User {}, repo .RepoPath (), repo .HTMLURL (), commit )
859+ if err != nil {
860+ log .Error ("commits.ToAPIPayloadCommits failed: %v" , err )
861+ return
862+ }
863+
864+ payload := api.CommitStatusPayload {
865+ Context : status .Context ,
866+ CreatedAt : status .CreatedUnix .AsTime ().UTC (),
867+ Description : status .Description ,
868+ ID : status .ID ,
869+ SHA : commit .Sha1 ,
870+ State : status .State .String (),
871+ TargetURL : status .TargetURL ,
872+
873+ Commit : apiCommit ,
874+ Repo : convert .ToRepo (ctx , repo , access_model.Permission {AccessMode : perm .AccessModeOwner }),
875+ Sender : apiSender ,
876+ }
877+ if ! status .UpdatedUnix .IsZero () {
878+ t := status .UpdatedUnix .AsTime ().UTC ()
879+ payload .UpdatedAt = & t
880+ }
881+ if err := PrepareWebhooks (ctx , EventSource {Repository : repo }, webhook_module .HookEventPush , & payload ); err != nil {
882+ log .Error ("PrepareWebhooks: %v" , err )
883+ }
884+ }
885+
854886func (m * webhookNotifier ) SyncCreateRef (ctx context.Context , pusher * user_model.User , repo * repo_model.Repository , refFullName git.RefName , refID string ) {
855887 m .CreateRef (ctx , pusher , repo , refFullName , refID )
856888}
0 commit comments