⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(api): ignore gitlab issue events once an issue is confidential
zaralX6fb05681d215
diff --git a/apps/api/src/plugins/gitlab/webhook-handler.ts b/apps/api/src/plugins/gitlab/webhook-handler.tsindex 5cebfd351..0a3dce771 100644--- a/apps/api/src/plugins/gitlab/webhook-handler.ts+++ b/apps/api/src/plugins/gitlab/webhook-handler.ts@@ -63,6 +63,14 @@ function isNotePayload(return hasProject(payload) && hasObjectAttributes(payload);}+function isConfidentialIssue(payload: Record<string, unknown>): boolean {+ const attributes = payload.object_attributes;+ return (+ payload.event_type === "confidential_issue" ||+ (isRecord(attributes) && attributes.confidential === true)+ );+}+function objectAction(payload: Record<string, unknown>): string | undefined {const attributes = payload.object_attributes;if (!isRecord(attributes)) return undefined;@@ -149,7 +157,7 @@ async function dispatchGitlabEvent(}return;case "issue": {- if (!isIssuePayload(payload)) {+ if (!isIssuePayload(payload) || isConfidentialIssue(payload)) {return;}switch (objectAction(payload)) {diff --git a/tests/api/plugins/gitlab/webhook-handler.test.ts b/tests/api/plugins/gitlab/webhook-handler.test.tsindex 28a309727..bd154dd6c 100644--- a/tests/api/plugins/gitlab/webhook-handler.test.ts+++ b/tests/api/plugins/gitlab/webhook-handler.test.ts@@ -5,8 +5,26 @@ const mocks = vi.hoisted(() => ({integrationFindFirst: vi.fn(),handleGitlabMergeRequestOpened: vi.fn(),handleGitlabMergeRequestClosed: vi.fn(),+ handleGitlabIssueUpdated: vi.fn(),+ handleGitlabIssueClosed: vi.fn(),}));+vi.mock(+ "../../../../apps/api/src/plugins/gitlab/webhooks/issue-updated",+ () => ({+ handleGitlabIssueUpdated: (...args: unknown[]) =>+ mocks.handleGitlabIssueUpdated(...args),+ }),+);++vi.mock(+ "../../../../apps/api/src/plugins/gitlab/webhooks/issue-closed",+ () => ({+ handleGitlabIssueClosed: (...args: unknown[]) =>+ mocks.handleGitlabIssueClosed(...args),+ }),+);+vi.mock("../../../../apps/api/src/database", () => ({default: {query: {@@ -56,6 +74,35 @@ function mergeRequestUpdate(changes: Record<string, unknown>) {});}+function issueEvent({+ action,+ eventType = "issue",+ confidential = false,+}: {+ action: string;+ eventType?: string;+ confidential?: boolean;+}) {+ return JSON.stringify({+ object_kind: "issue",+ event_type: eventType,+ object_attributes: {+ iid: 7,+ title: "Payment provider keys",+ description: "internal details",+ url: "https://gitlab.com/acme/web/-/issues/7",+ action,+ confidential,+ },+ changes: { title: { previous: "Old", current: "Payment provider keys" } },+ project: {+ name: "web",+ web_url: "https://gitlab.com/acme/web",+ path_with_namespace: "acme/web",+ },+ });+}+beforeEach(() => {vi.clearAllMocks();mocks.integrationFindFirst.mockResolvedValue({@@ -117,3 +164,40 @@ describe("handleGitlabWebhookRequest merge request updates", () => {expect(mocks.handleGitlabMergeRequestOpened).not.toHaveBeenCalled();});});++describe("handleGitlabWebhookRequest confidential issues", () => {+ it("passes a regular issue update to the handler", async () => {+ await handleGitlabWebhookRequest(+ "integration-1",+ issueEvent({ action: "update" }),+ secret,+ );++ expect(mocks.handleGitlabIssueUpdated).toHaveBeenCalledOnce();+ });++ it("drops an update to an issue that was made confidential", async () => {+ const result = await handleGitlabWebhookRequest(+ "integration-1",+ issueEvent({+ action: "update",+ eventType: "confidential_issue",+ confidential: true,+ }),+ secret,+ );++ expect(result.success).toBe(true);+ expect(mocks.handleGitlabIssueUpdated).not.toHaveBeenCalled();+ });++ it("drops a confidential issue even without the event type", async () => {+ await handleGitlabWebhookRequest(+ "integration-1",+ issueEvent({ action: "close", confidential: true }),+ secret,+ );++ expect(mocks.handleGitlabIssueClosed).not.toHaveBeenCalled();+ });+});