From 5b2f40b2d8a890707b2c6dd5e0351e437febf50f Mon Sep 17 00:00:00 2001 From: Leela Senthil Nathan Date: Mon, 14 Oct 2024 21:56:26 -0500 Subject: [PATCH 1/2] Include labels in sample data in issue triggers --- package.json | 2 +- src/triggers/issueV2.ts | 232 +++++++++++++++++++++++----------------- 2 files changed, 134 insertions(+), 100 deletions(-) diff --git a/package.json b/package.json index 1885bf4..c0cf5aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "linear-zapier", - "version": "4.3.0", + "version": "4.3.1", "description": "Linear's Zapier integration", "main": "index.js", "license": "MIT", diff --git a/src/triggers/issueV2.ts b/src/triggers/issueV2.ts index 91c1327..a9a747b 100644 --- a/src/triggers/issueV2.ts +++ b/src/triggers/issueV2.ts @@ -5,7 +5,7 @@ import { unsubscribeHook } from "../handleWebhook"; import { jsonToGraphQLQuery, VariableType } from "json-to-graphql-query"; import { fetchFromLinear } from "../fetchFromLinear"; -interface Issue { +interface IssueCommon { id: string; identifier: string; url: string; @@ -49,11 +49,33 @@ interface Issue { }; } +interface IssueApi extends IssueCommon { + labels?: { + nodes: { + id: string; + color: string; + name: string; + parent?: { + id: string; + }; + }[]; + }; +} + +interface IssueWebhook extends IssueCommon { + labels?: { + id: string; + color: string; + name: string; + parentId?: string; + }[]; +} + interface TeamIssuesResponse { data: { team: { issues: { - nodes: Issue[]; + nodes: IssueApi[]; }; }; }; @@ -98,119 +120,131 @@ const subscribeHook = (eventType: "create" | "update") => async (z: ZObject, bun .then((response) => response.data); }; -const getIssueList = () => async (z: ZObject, bundle: Bundle) => { - if (!bundle.inputData.teamId) { - throw new z.errors.HaltedError("You must select a team"); - } +const getIssueList = + () => + async (z: ZObject, bundle: Bundle): Promise => { + if (!bundle.inputData.teamId) { + throw new z.errors.HaltedError("You must select a team"); + } - const variables: Record = {}; - const variableSchema: Record = {}; + const variables: Record = {}; + const variableSchema: Record = {}; - variableSchema.teamId = "String!"; - variables.teamId = bundle.inputData.teamId; + variableSchema.teamId = "String!"; + variables.teamId = bundle.inputData.teamId; - const filters: unknown[] = []; - if (bundle.inputData.priority) { - variableSchema.priority = "Float"; - variables.priority = Number(bundle.inputData.priority); - filters.push({ priority: { eq: new VariableType("priority") } }); - } - if (bundle.inputData.statusId) { - variableSchema.statusId = "ID"; - variables.statusId = bundle.inputData.statusId; - filters.push({ state: { id: { eq: new VariableType("statusId") } } }); - } - if (bundle.inputData.creatorId) { - variableSchema.creatorId = "ID"; - variables.creatorId = bundle.inputData.creatorId; - filters.push({ creator: { id: { eq: new VariableType("creatorId") } } }); - } - if (bundle.inputData.assigneeId) { - variableSchema.assigneeId = "ID"; - variables.assigneeId = bundle.inputData.assigneeId; - filters.push({ assignee: { id: { eq: new VariableType("assigneeId") } } }); - } - if (bundle.inputData.projectId) { - variableSchema.projectId = "ID"; - variables.projectId = bundle.inputData.projectId; - filters.push({ project: { id: { eq: new VariableType("projectId") } } }); - } - if (bundle.inputData.projectMilestoneId) { - variableSchema.projectMilestoneId = "ID"; - variables.projectMilestoneId = bundle.inputData.projectMilestoneId; - filters.push({ projectMilestone: { id: { eq: new VariableType("projectMilestoneId") } } }); - } - if (bundle.inputData.labelId) { - variableSchema.labelId = "ID"; - variables.labelId = bundle.inputData.labelId; - filters.push({ labels: { id: { eq: new VariableType("labelId") } } }); - } - const filter = { and: filters }; + const filters: unknown[] = []; + if (bundle.inputData.priority) { + variableSchema.priority = "Float"; + variables.priority = Number(bundle.inputData.priority); + filters.push({ priority: { eq: new VariableType("priority") } }); + } + if (bundle.inputData.statusId) { + variableSchema.statusId = "ID"; + variables.statusId = bundle.inputData.statusId; + filters.push({ state: { id: { eq: new VariableType("statusId") } } }); + } + if (bundle.inputData.creatorId) { + variableSchema.creatorId = "ID"; + variables.creatorId = bundle.inputData.creatorId; + filters.push({ creator: { id: { eq: new VariableType("creatorId") } } }); + } + if (bundle.inputData.assigneeId) { + variableSchema.assigneeId = "ID"; + variables.assigneeId = bundle.inputData.assigneeId; + filters.push({ assignee: { id: { eq: new VariableType("assigneeId") } } }); + } + if (bundle.inputData.projectId) { + variableSchema.projectId = "ID"; + variables.projectId = bundle.inputData.projectId; + filters.push({ project: { id: { eq: new VariableType("projectId") } } }); + } + if (bundle.inputData.projectMilestoneId) { + variableSchema.projectMilestoneId = "ID"; + variables.projectMilestoneId = bundle.inputData.projectMilestoneId; + filters.push({ projectMilestone: { id: { eq: new VariableType("projectMilestoneId") } } }); + } + if (bundle.inputData.labelId) { + variableSchema.labelId = "ID"; + variables.labelId = bundle.inputData.labelId; + filters.push({ labels: { id: { eq: new VariableType("labelId") } } }); + } + const filter = { and: filters }; - const jsonQuery = { - query: { - __variables: variableSchema, - team: { - __args: { - id: new VariableType("teamId"), - }, - issues: { + const jsonQuery = { + query: { + __variables: variableSchema, + team: { __args: { - first: 10, - filter, + id: new VariableType("teamId"), }, - nodes: { - id: true, - identifier: true, - url: true, - title: true, - description: true, - priority: true, - estimate: true, - dueDate: true, - slaBreachesAt: true, - slaStartedAt: true, - createdAt: true, - updatedAt: true, - project: { - id: true, - name: true, - }, - projectMilestone: { - id: true, - name: true, - }, - creator: { - id: true, - name: true, - email: true, + issues: { + __args: { + first: 10, + filter, }, - assignee: { - id: true, - name: true, - email: true, - }, - state: { - id: true, - name: true, - type: true, - }, - parent: { + nodes: { id: true, identifier: true, url: true, title: true, + description: true, + priority: true, + estimate: true, + dueDate: true, + slaBreachesAt: true, + slaStartedAt: true, + createdAt: true, + updatedAt: true, + project: { + id: true, + name: true, + }, + projectMilestone: { + id: true, + name: true, + }, + creator: { + id: true, + name: true, + email: true, + }, + assignee: { + id: true, + name: true, + email: true, + }, + state: { + id: true, + name: true, + type: true, + }, + parent: { + id: true, + identifier: true, + url: true, + title: true, + }, }, }, }, }, - }, + }; + const query = jsonToGraphQLQuery(jsonQuery); + const response = await fetchFromLinear(z, bundle, query, variables); + const data = (response.json as TeamIssuesResponse).data; + const issuesRaw = data.team.issues.nodes; + // We need to map the API schema to the webhook schema + return issuesRaw.map((issueRaw) => ({ + ...issueRaw, + labels: issueRaw.labels?.nodes.map((label) => ({ + id: label.id, + color: label.color, + name: label.name, + parentId: label.parent?.id, + })), + })); }; - const query = jsonToGraphQLQuery(jsonQuery); - const response = await fetchFromLinear(z, bundle, query, variables); - const data = (response.json as TeamIssuesResponse).data; - return data.team.issues.nodes; -}; const getWebhookDataForIssue = (z: ZObject, bundle: Bundle) => { const entity = { From ea481d29eb778175be573376f467823380d71a51 Mon Sep 17 00:00:00 2001 From: Leela Senthil Nathan Date: Mon, 14 Oct 2024 22:01:30 -0500 Subject: [PATCH 2/2] Query labels --- src/triggers/issueV2.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/triggers/issueV2.ts b/src/triggers/issueV2.ts index a9a747b..70895b8 100644 --- a/src/triggers/issueV2.ts +++ b/src/triggers/issueV2.ts @@ -225,6 +225,16 @@ const getIssueList = url: true, title: true, }, + labels: { + nodes: { + id: true, + color: true, + name: true, + parent: { + id: true, + }, + }, + }, }, }, },