@@ -56,7 +56,7 @@ func TestNewWebHookLink(t *testing.T) {
5656	}
5757}
5858
59- func  testAPICreateWebhookForRepo (t  * testing.T , session  * TestSession , userName , repoName , url , event  string ) {
59+ func  testAPICreateWebhookForRepo (t  * testing.T , session  * TestSession , userName , repoName , url , event  string ,  branchFilter   ... string ) {
6060	token  :=  getTokenForLoggedInUser (t , session , auth_model .AccessTokenScopeAll )
6161	req  :=  NewRequestWithJSON (t , "POST" , "/api/v1/repos/" + userName + "/" + repoName + "/hooks" , api.CreateHookOption {
6262		Type : "gitea" ,
@@ -322,6 +322,40 @@ func Test_WebhookPush(t *testing.T) {
322322	})
323323}
324324
325+ func  Test_WebhookPushDevBranch (t  * testing.T ) {
326+ 	var  payloads  []api.PushPayload 
327+ 	var  triggeredEvent  string 
328+ 	provider  :=  newMockWebhookProvider (func (r  * http.Request ) {
329+ 		content , _  :=  io .ReadAll (r .Body )
330+ 		var  payload  api.PushPayload 
331+ 		err  :=  json .Unmarshal (content , & payload )
332+ 		assert .NoError (t , err )
333+ 		payloads  =  append (payloads , payload )
334+ 		triggeredEvent  =  "push" 
335+ 	}, http .StatusOK )
336+ 	defer  provider .Close ()
337+ 
338+ 	onGiteaRun (t , func (t  * testing.T , giteaURL  * url.URL ) {
339+ 		// 1. create a new webhook with special webhook for repo1 
340+ 		session  :=  loginUser (t , "user2" )
341+ 
342+ 		// only for dev branch 
343+ 		testAPICreateWebhookForRepo (t , session , "user2" , "repo1" , provider .URL (), "push" , "develop" )
344+ 
345+ 		// 2. trigger the webhook 
346+ 		testCreateFile (t , session , "user2" , "repo1" , "develop" , "test_webhook_push.md" , "# a test file for webhook push" )
347+ 
348+ 		// 3. validate the webhook is triggered 
349+ 		assert .Equal (t , "push" , triggeredEvent )
350+ 		assert .Len (t , payloads , 1 )
351+ 		assert .Equal (t , "repo1" , payloads [0 ].Repo .Name )
352+ 		assert .Equal (t , "develop" , payloads [0 ].Branch ())
353+ 		assert .Equal (t , "user2/repo1" , payloads [0 ].Repo .FullName )
354+ 		assert .Len (t , payloads [0 ].Commits , 1 )
355+ 		assert .Equal (t , []string {"test_webhook_push.md" }, payloads [0 ].Commits [0 ].Added )
356+ 	})
357+ }
358+ 
325359func  Test_WebhookIssue (t  * testing.T ) {
326360	var  payloads  []api.IssuePayload 
327361	var  triggeredEvent  string 
0 commit comments