77	"context" 
88
99	actions_model "code.gitea.io/gitea/models/actions" 
10+ 	"code.gitea.io/gitea/models/db" 
1011	git_model "code.gitea.io/gitea/models/git" 
1112	issues_model "code.gitea.io/gitea/models/issues" 
1213	"code.gitea.io/gitea/models/organization" 
@@ -15,10 +16,12 @@ import (
1516	access_model "code.gitea.io/gitea/models/perm/access" 
1617	repo_model "code.gitea.io/gitea/models/repo" 
1718	user_model "code.gitea.io/gitea/models/user" 
19+ 	webhook_model "code.gitea.io/gitea/models/webhook" 
1820	"code.gitea.io/gitea/modules/git" 
1921	"code.gitea.io/gitea/modules/gitrepo" 
2022	"code.gitea.io/gitea/modules/httplib" 
2123	"code.gitea.io/gitea/modules/log" 
24+ 	"code.gitea.io/gitea/modules/optional" 
2225	"code.gitea.io/gitea/modules/repository" 
2326	"code.gitea.io/gitea/modules/setting" 
2427	api "code.gitea.io/gitea/modules/structs" 
@@ -640,6 +643,57 @@ func (m *webhookNotifier) IssueChangeMilestone(ctx context.Context, doer *user_m
640643	}
641644}
642645
646+ // applyWebhookPayloadOptimizations applies payload size optimizations based on webhook configurations 
647+ func  (m  * webhookNotifier ) applyWebhookPayloadOptimizations (ctx  context.Context , repo  * repo_model.Repository , apiCommits  []* api.PayloadCommit , apiHeadCommit  * api.PayloadCommit ) ([]* api.PayloadCommit , * api.PayloadCommit ) {
648+ 	// Get webhooks for this repository to check their configuration 
649+ 	webhooks , err  :=  db .Find [webhook_model.Webhook ](ctx , webhook_model.ListWebhookOptions {
650+ 		RepoID :   repo .ID ,
651+ 		IsActive : optional .Some (true ),
652+ 	})
653+ 	if  err  !=  nil  {
654+ 		log .Error ("Failed to get webhooks for repository %d: %v" , repo .ID , err )
655+ 		// Continue with default behavior if we can't get webhooks 
656+ 		return  apiCommits , apiHeadCommit 
657+ 	}
658+ 
659+ 	// Check if any webhook has payload optimization options enabled 
660+ 	hasExcludeFiles  :=  false 
661+ 	hasExcludeCommits  :=  false 
662+ 	for  _ , webhook  :=  range  webhooks  {
663+ 		if  webhook .HasEvent (webhook_module .HookEventPush ) {
664+ 			if  webhook .ExcludeFiles  {
665+ 				hasExcludeFiles  =  true 
666+ 			}
667+ 			if  webhook .ExcludeCommits  {
668+ 				hasExcludeCommits  =  true 
669+ 			}
670+ 		}
671+ 	}
672+ 
673+ 	// Apply payload optimizations based on webhook configurations 
674+ 	if  hasExcludeFiles  {
675+ 		// Remove file information from commits 
676+ 		for  _ , commit  :=  range  apiCommits  {
677+ 			commit .Added  =  nil 
678+ 			commit .Removed  =  nil 
679+ 			commit .Modified  =  nil 
680+ 		}
681+ 		if  apiHeadCommit  !=  nil  {
682+ 			apiHeadCommit .Added  =  nil 
683+ 			apiHeadCommit .Removed  =  nil 
684+ 			apiHeadCommit .Modified  =  nil 
685+ 		}
686+ 	}
687+ 
688+ 	if  hasExcludeCommits  {
689+ 		// Exclude commits and head_commit from payload 
690+ 		apiCommits  =  nil 
691+ 		apiHeadCommit  =  nil 
692+ 	}
693+ 
694+ 	return  apiCommits , apiHeadCommit 
695+ }
696+ 
643697func  (m  * webhookNotifier ) PushCommits (ctx  context.Context , pusher  * user_model.User , repo  * repo_model.Repository , opts  * repository.PushUpdateOptions , commits  * repository.PushCommits ) {
644698	apiPusher  :=  convert .ToUser (ctx , pusher , nil )
645699	apiCommits , apiHeadCommit , err  :=  commits .ToAPIPayloadCommits (ctx , repo )
@@ -648,6 +702,9 @@ func (m *webhookNotifier) PushCommits(ctx context.Context, pusher *user_model.Us
648702		return 
649703	}
650704
705+ 	// Apply payload optimizations 
706+ 	apiCommits , apiHeadCommit  =  m .applyWebhookPayloadOptimizations (ctx , repo , apiCommits , apiHeadCommit )
707+ 
651708	if  err  :=  PrepareWebhooks (ctx , EventSource {Repository : repo }, webhook_module .HookEventPush , & api.PushPayload {
652709		Ref :          opts .RefFullName .String (),
653710		Before :       opts .OldCommitID ,
@@ -887,6 +944,9 @@ func (m *webhookNotifier) SyncPushCommits(ctx context.Context, pusher *user_mode
887944		return 
888945	}
889946
947+ 	// Apply payload optimizations 
948+ 	apiCommits , apiHeadCommit  =  m .applyWebhookPayloadOptimizations (ctx , repo , apiCommits , apiHeadCommit )
949+ 
890950	if  err  :=  PrepareWebhooks (ctx , EventSource {Repository : repo }, webhook_module .HookEventPush , & api.PushPayload {
891951		Ref :          opts .RefFullName .String (),
892952		Before :       opts .OldCommitID ,
0 commit comments