@@ -98,17 +98,17 @@ func TestWebhookPayloadOptimization(t *testing.T) {
9898 // Create a test repository
9999 repo := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {ID : 1 })
100100
101- // Create a webhook with payload optimization enabled
101+ // Create a webhook with file limit = 1
102102 webhook := & webhook_model.Webhook {
103- RepoID : repo .ID ,
104- URL : "http://example.com/webhook" ,
105- HTTPMethod : "POST" ,
106- ContentType : webhook_model .ContentTypeJSON ,
107- Secret : "secret" ,
108- IsActive : true ,
109- Type : webhook_module .GITEA ,
110- ExcludeFiles : true ,
111- ExcludeCommits : false ,
103+ RepoID : repo .ID ,
104+ URL : "http://example.com/webhook" ,
105+ HTTPMethod : "POST" ,
106+ ContentType : webhook_model .ContentTypeJSON ,
107+ Secret : "secret" ,
108+ IsActive : true ,
109+ Type : webhook_module .GITEA ,
110+ ExcludeFilesLimit : 1 ,
111+ ExcludeCommitsLimit : 0 ,
112112 HookEvent : & webhook_module.HookEvent {
113113 PushOnly : true ,
114114 },
@@ -143,30 +143,41 @@ func TestWebhookPayloadOptimization(t *testing.T) {
143143 Modified : []string {"file1.txt" },
144144 }
145145
146- // Test payload optimization
146+ // Test payload optimization: should truncate to 1 file per field
147147 notifier := & webhookNotifier {}
148- optimizedCommits , optimizedHeadCommit := notifier .applyWebhookPayloadOptimizations (db .DefaultContext , repo , apiCommits , apiHeadCommit )
149-
150- // Verify that file information was removed when ExcludeFiles is true
151- assert .Nil (t , optimizedCommits [0 ].Added )
152- assert .Nil (t , optimizedCommits [0 ].Removed )
153- assert .Nil (t , optimizedCommits [0 ].Modified )
154- assert .Nil (t , optimizedCommits [1 ].Added )
155- assert .Nil (t , optimizedCommits [1 ].Removed )
156- assert .Nil (t , optimizedCommits [1 ].Modified )
157- assert .Nil (t , optimizedHeadCommit .Added )
158- assert .Nil (t , optimizedHeadCommit .Removed )
159- assert .Nil (t , optimizedHeadCommit .Modified )
160-
161- // Test with ExcludeCommits enabled
162- webhook .ExcludeFiles = false
163- webhook .ExcludeCommits = true
148+ optimizedCommits , _ := notifier .applyWebhookPayloadOptimizations (db .DefaultContext , repo , apiCommits , apiHeadCommit )
149+ assert .Equal (t , []string {"file1.txt" }, optimizedCommits [0 ].Added )
150+ assert .Equal (t , []string {"oldfile.txt" }, optimizedCommits [0 ].Removed )
151+ assert .Equal (t , []string {"modified.txt" }, optimizedCommits [0 ].Modified )
152+ assert .Equal (t , []string {"file3.txt" }, optimizedCommits [1 ].Added )
153+ assert .Equal (t , []string {}, optimizedCommits [1 ].Removed )
154+ assert .Equal (t , []string {"file1.txt" }, optimizedCommits [1 ].Modified )
155+ assert .Equal (t , []string {"file3.txt" }, optimizedHeadCommit .Added )
156+ assert .Equal (t , []string {}, optimizedHeadCommit .Removed )
157+ assert .Equal (t , []string {"file1.txt" }, optimizedHeadCommit .Modified )
158+
159+ // Test with commit limit = 1
160+ webhook .ExcludeFilesLimit = 0
161+ webhook .ExcludeCommitsLimit = 1
164162 err = webhook_model .UpdateWebhook (db .DefaultContext , webhook )
165163 assert .NoError (t , err )
166-
167164 optimizedCommits , optimizedHeadCommit = notifier .applyWebhookPayloadOptimizations (db .DefaultContext , repo , apiCommits , apiHeadCommit )
165+ assert .Len (t , optimizedCommits , 1 )
166+ assert .Equal (t , "abc123" , optimizedCommits [0 ].ID )
168167
169- // Verify that commits and head_commit were excluded
170- assert .Nil (t , optimizedCommits )
171- assert .Nil (t , optimizedHeadCommit )
168+ // Test with no limits (0 means unlimited)
169+ webhook .ExcludeFilesLimit = 0
170+ webhook .ExcludeCommitsLimit = 0
171+ err = webhook_model .UpdateWebhook (db .DefaultContext , webhook )
172+ assert .NoError (t , err )
173+ optimizedCommits , optimizedHeadCommit = notifier .applyWebhookPayloadOptimizations (db .DefaultContext , repo , apiCommits , apiHeadCommit )
174+ assert .Equal (t , []string {"file1.txt" , "file2.txt" }, optimizedCommits [0 ].Added )
175+ assert .Equal (t , []string {"oldfile.txt" }, optimizedCommits [0 ].Removed )
176+ assert .Equal (t , []string {"modified.txt" }, optimizedCommits [0 ].Modified )
177+ assert .Equal (t , []string {"file3.txt" }, optimizedCommits [1 ].Added )
178+ assert .Equal (t , []string {}, optimizedCommits [1 ].Removed )
179+ assert .Equal (t , []string {"file1.txt" }, optimizedCommits [1 ].Modified )
180+ assert .Equal (t , []string {"file3.txt" }, optimizedHeadCommit .Added )
181+ assert .Equal (t , []string {}, optimizedHeadCommit .Removed )
182+ assert .Equal (t , []string {"file1.txt" }, optimizedHeadCommit .Modified )
172183}
0 commit comments