Skip to content

Commit d11363a

Browse files
committed
fix: correct Bitbucket trigger type validation for push events
- Fix logic to reject tag events when triggerType is 'push' - Add test case to verify tags are rejected when triggerType is 'push' - Addresses Greptile bot feedback on PR #3711
1 parent 59b52b8 commit d11363a

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

apps/dokploy/__test__/deploy/github.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,16 @@ describe("Webhook Trigger Type Validation", () => {
504504
expect(validateTriggerType(headers, body, "push")).toBe(true);
505505
});
506506

507+
it("should reject tag push events when triggerType is push", () => {
508+
const headers = { "x-event-key": "repo:push" };
509+
const body = {
510+
push: {
511+
changes: [{ new: { type: "tag", name: "v1.0.0" } }],
512+
},
513+
};
514+
expect(validateTriggerType(headers, body, "push")).toBe(false);
515+
});
516+
507517
it("should allow tag push events when triggerType is tag", () => {
508518
const headers = { "x-event-key": "repo:push" };
509519
const body = {

apps/dokploy/pages/api/deploy/[refreshToken].ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,17 @@ export const validateTriggerType = (
7171
// Bitbucket
7272
const bitbucketEvent = headers["x-event-key"];
7373
if (bitbucketEvent?.includes("repo:push")) {
74+
const changes = body.push?.changes || [];
7475
if (triggerType === "tag") {
7576
// For Bitbucket, check if the push is for a tag
76-
const changes = body.push?.changes || [];
7777
return changes.some(
7878
(change: any) => change.new?.type === "tag" || change.new?.type === "annotated_tag",
7979
);
8080
}
8181
// For push trigger type, accept push events that are not tags
82-
return true;
82+
return !changes.some(
83+
(change: any) => change.new?.type === "tag" || change.new?.type === "annotated_tag",
84+
);
8385
}
8486

8587
// Default: if we can't determine the provider, allow the event (backward compatibility)

0 commit comments

Comments
 (0)