Skip to content

Commit

Permalink
Merge pull request #82 from linear/leela/fea-4937-trigger
Browse files Browse the repository at this point in the history
Add "updated project" trigger
  • Loading branch information
leelasn authored Nov 5, 2024
2 parents 7d3b9a6 + b3857b1 commit c4246d7
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 44 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "linear-zapier",
"version": "4.4.2",
"version": "4.4.3",
"description": "Linear's Zapier integration",
"main": "index.js",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { projectWithoutTeam } from "./triggers/projectWithoutTeam";
import { newIssueInstant, updatedIssueInstant } from "./triggers/issueV2";
import { initiative } from "./triggers/initiative";
import { projectStatus } from "./triggers/projectStatus";
import { newProjectInstant } from "./triggers/newProject";
import { newProjectInstant, updatedProjectInstant } from "./triggers/newProject";
import { createIssueAttachment } from "./creates/createIssueAttachment";
import { createProject } from "./creates/createProject";
import { updateIssue } from "./creates/updateIssue";
Expand Down Expand Up @@ -83,6 +83,7 @@ const App = {
[initiative.key]: initiative,
[projectStatus.key]: projectStatus,
[newProjectInstant.key]: newProjectInstant,
[updatedProjectInstant.key]: updatedProjectInstant,
},
authentication,
beforeRequest: [addBearerHeader],
Expand Down
1 change: 1 addition & 0 deletions src/samples/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"description": "A test project",
"priority": 0,
"createdAt": "2024-10-04T22:38:43.396Z",
"updatedAt": "2024-10-04T22:39:43.396Z",
"startDate": "2024-10-05T22:38:43.396Z",
"targetDate": null,
"status": {
Expand Down
104 changes: 62 additions & 42 deletions src/triggers/newProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface ProjectCommon {
description: string;
priority: number;
createdAt: Date;
updatedAt: Date;
startDate?: Date;
targetDate?: Date;
status: {
Expand Down Expand Up @@ -52,7 +53,7 @@ interface ProjectWebhook extends ProjectCommon {
initiatives: IdAndName[];
}

const subscribeHook = async (z: ZObject, bundle: Bundle) => {
const subscribeHook = (eventType: "create" | "update") => async (z: ZObject, bundle: Bundle) => {
const inputData =
bundle.inputData && Object.keys(bundle.inputData).length > 0
? omitBy(
Expand All @@ -67,10 +68,11 @@ const subscribeHook = async (z: ZObject, bundle: Bundle) => {
url: bundle.targetUrl,
inputData,
};
const webhookType = eventType === "create" ? "createProject" : "updateProject";

return z
.request({
url: "https://client-api.linear.app/connect/zapier/subscribe/createProject",
url: `https://client-api.linear.app/connect/zapier/subscribe/${webhookType}`,
method: "POST",
body: data,
})
Expand Down Expand Up @@ -120,6 +122,7 @@ const getProjectList =
description: true,
priority: true,
createdAt: true,
updatedAt: true,
startDate: true,
targetDate: true,
status: {
Expand Down Expand Up @@ -167,6 +170,48 @@ const getProjectList =
);
};

const operationBase = {
inputFields: [
{
required: false,
label: "Team",
key: "teamId",
helpText: "The team associated with the project.",
dynamic: "team.id.name",
altersDynamicFields: true,
},
{
required: false,
label: "Status",
key: "statusId",
helpText: "The project status.",
dynamic: "projectStatus.id.name",
altersDynamicFields: true,
},
{
required: false,
label: "Lead",
key: "leadId",
helpText: "The user who is the lead of the project.",
dynamic: "user.id.name",
altersDynamicFields: true,
},
{
required: false,
label: "Initiative",
key: "initiativeId",
helpText: "The initiative this project belongs to.",
dynamic: "initiative.id.name",
altersDynamicFields: true,
},
],
type: "hook",
perform: getWebhookData,
performUnsubscribe: unsubscribeHook,
performList: getProjectList(),
sample,
};

export const newProjectInstant = {
noun: "Project",
key: "newProjectInstant",
Expand All @@ -175,45 +220,20 @@ export const newProjectInstant = {
description: "Triggers when a new project is created.",
},
operation: {
inputFields: [
{
required: false,
label: "Team",
key: "teamId",
helpText: "The team associated with the project.",
dynamic: "team.id.name",
altersDynamicFields: true,
},
{
required: false,
label: "Status",
key: "statusId",
helpText: "The project status.",
dynamic: "projectStatus.id.name",
altersDynamicFields: true,
},
{
required: false,
label: "Lead",
key: "leadId",
helpText: "The user who is the lead of the project.",
dynamic: "user.id.name",
altersDynamicFields: true,
},
{
required: false,
label: "Initiative",
key: "initiativeId",
helpText: "The initiative this project belongs to.",
dynamic: "initiative.id.name",
altersDynamicFields: true,
},
],
type: "hook",
perform: getWebhookData,
performUnsubscribe: unsubscribeHook,
performList: getProjectList(),
sample,
performSubscribe: subscribeHook,
...operationBase,
performSubscribe: subscribeHook("create"),
},
};

export const updatedProjectInstant = {
noun: "Project",
key: "updatedProjectInstant",
display: {
label: "Updated Project",
description: "Triggers when a project is updated.",
},
operation: {
...operationBase,
performSubscribe: subscribeHook("update"),
},
};

0 comments on commit c4246d7

Please sign in to comment.