@@ -21,6 +21,7 @@ import (
2121 "code.gitea.io/gitea/modules/gitrepo"
2222 "code.gitea.io/gitea/modules/json"
2323 api "code.gitea.io/gitea/modules/structs"
24+ "code.gitea.io/gitea/modules/util"
2425 webhook_module "code.gitea.io/gitea/modules/webhook"
2526 "code.gitea.io/gitea/tests"
2627
@@ -64,8 +65,9 @@ func testAPICreateWebhookForRepo(t *testing.T, session *TestSession, userName, r
6465 "content_type" : "json" ,
6566 "url" : url ,
6667 },
67- Events : []string {event },
68- Active : true ,
68+ Events : []string {event },
69+ Active : true ,
70+ BranchFilter : util .Iif (len (branchFilter ) > 0 , branchFilter [0 ], "" ),
6971 }).AddTokenAuth (token )
7072 MakeRequest (t , req , http .StatusCreated )
7173}
@@ -342,10 +344,15 @@ func Test_WebhookPushDevBranch(t *testing.T) {
342344 // only for dev branch
343345 testAPICreateWebhookForRepo (t , session , "user2" , "repo1" , provider .URL (), "push" , "develop" )
344346
345- // 2. trigger the webhook
347+ // 2. this should not trigger the webhook
348+ testCreateFile (t , session , "user2" , "repo1" , "master" , "test_webhook_push.md" , "# a test file for webhook push" )
349+ assert .Equal (t , "" , triggeredEvent )
350+ assert .Len (t , payloads , 0 )
351+
352+ // 3. trigger the webhook
346353 testCreateFile (t , session , "user2" , "repo1" , "develop" , "test_webhook_push.md" , "# a test file for webhook push" )
347354
348- // 3 . validate the webhook is triggered
355+ // 4 . validate the webhook is triggered
349356 assert .Equal (t , "push" , triggeredEvent )
350357 assert .Len (t , payloads , 1 )
351358 assert .Equal (t , "repo1" , payloads [0 ].Repo .Name )
0 commit comments