This commit is contained in:
Lunny Xiao 2025-05-11 12:32:38 -07:00
parent 67ef19b099
commit 8171db0c36
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A

View File

@ -21,6 +21,7 @@ import (
"code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
webhook_module "code.gitea.io/gitea/modules/webhook" webhook_module "code.gitea.io/gitea/modules/webhook"
"code.gitea.io/gitea/tests" "code.gitea.io/gitea/tests"
@ -64,8 +65,9 @@ func testAPICreateWebhookForRepo(t *testing.T, session *TestSession, userName, r
"content_type": "json", "content_type": "json",
"url": url, "url": url,
}, },
Events: []string{event}, Events: []string{event},
Active: true, Active: true,
BranchFilter: util.Iif(len(branchFilter) > 0, branchFilter[0], ""),
}).AddTokenAuth(token) }).AddTokenAuth(token)
MakeRequest(t, req, http.StatusCreated) MakeRequest(t, req, http.StatusCreated)
} }
@ -342,10 +344,15 @@ func Test_WebhookPushDevBranch(t *testing.T) {
// only for dev branch // only for dev branch
testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "push", "develop") testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "push", "develop")
// 2. trigger the webhook // 2. this should not trigger the webhook
testCreateFile(t, session, "user2", "repo1", "master", "test_webhook_push.md", "# a test file for webhook push")
assert.Equal(t, "", triggeredEvent)
assert.Len(t, payloads, 0)
// 3. trigger the webhook
testCreateFile(t, session, "user2", "repo1", "develop", "test_webhook_push.md", "# a test file for webhook push") testCreateFile(t, session, "user2", "repo1", "develop", "test_webhook_push.md", "# a test file for webhook push")
// 3. validate the webhook is triggered // 4. validate the webhook is triggered
assert.Equal(t, "push", triggeredEvent) assert.Equal(t, "push", triggeredEvent)
assert.Len(t, payloads, 1) assert.Len(t, payloads, 1)
assert.Equal(t, "repo1", payloads[0].Repo.Name) assert.Equal(t, "repo1", payloads[0].Repo.Name)