@@ -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"
@@ -861,6 +863,36 @@ func (m *webhookNotifier) SyncPushCommits(ctx context.Context, pusher *user_mode
861863 }
862864}
863865
866+ func (m * webhookNotifier ) CreateCommitStatus (ctx context.Context , repo * repo_model.Repository , commit * repository.PushCommit , sender * user_model.User , status * git_model.CommitStatus ) {
867+ apiSender := convert .ToUser (ctx , sender , nil )
868+ apiCommit , err := repo_module .ToAPIPayloadCommit (ctx , map [string ]* user_model.User {}, repo .RepoPath (), repo .HTMLURL (), commit )
869+ if err != nil {
870+ log .Error ("commits.ToAPIPayloadCommits failed: %v" , err )
871+ return
872+ }
873+
874+ payload := api.CommitStatusPayload {
875+ Context : status .Context ,
876+ CreatedAt : status .CreatedUnix .AsTime ().UTC (),
877+ Description : status .Description ,
878+ ID : status .ID ,
879+ SHA : commit .Sha1 ,
880+ State : status .State .String (),
881+ TargetURL : status .TargetURL ,
882+
883+ Commit : apiCommit ,
884+ Repo : convert .ToRepo (ctx , repo , access_model.Permission {AccessMode : perm .AccessModeOwner }),
885+ Sender : apiSender ,
886+ }
887+ if ! status .UpdatedUnix .IsZero () {
888+ t := status .UpdatedUnix .AsTime ().UTC ()
889+ payload .UpdatedAt = & t
890+ }
891+ if err := PrepareWebhooks (ctx , EventSource {Repository : repo }, webhook_module .HookEventPush , & payload ); err != nil {
892+ log .Error ("PrepareWebhooks: %v" , err )
893+ }
894+ }
895+
864896func (m * webhookNotifier ) SyncCreateRef (ctx context.Context , pusher * user_model.User , repo * repo_model.Repository , refFullName git.RefName , refID string ) {
865897 m .CreateRef (ctx , pusher , repo , refFullName , refID )
866898}
0 commit comments