Skip to content

Commit

Permalink
Merge pull request #83 from mynamebrody/mynamebrody-issue-project-sea…
Browse files Browse the repository at this point in the history
…rches

[Addition] Find Issue & Find Project "by ID" Searches
  • Loading branch information
leelasn authored Nov 8, 2024
2 parents 7313cb7 + 99713d1 commit fdd33e3
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 1 deletion.
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.4",
"version": "4.4.5",
"description": "Linear's Zapier integration",
"main": "index.js",
"license": "MIT",
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { createIssueAttachment } from "./creates/createIssueAttachment";
import { createProject } from "./creates/createProject";
import { updateIssue } from "./creates/updateIssue";
import { issueTemplates } from "./triggers/issueTemplates";
import { findIssueByID } from "./searches/issue";
import { findProjectByID } from "./searches/project";

const handleErrors = (response: HttpResponse, z: ZObject) => {
if (response.request.url !== "https://api.linear.app/graphql") {
Expand Down Expand Up @@ -85,6 +87,10 @@ const App = {
[newProjectInstant.key]: newProjectInstant,
[updatedProjectInstant.key]: updatedProjectInstant,
},
searches: {
[findIssueByID.key]: findIssueByID,
[findProjectByID.key]: findProjectByID,
},
authentication,
beforeRequest: [addBearerHeader],
afterResponse: [handleErrors],
Expand Down
117 changes: 117 additions & 0 deletions src/searches/issue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { ZObject, Bundle } from "zapier-platform-core";

interface IssueResponse {
data: {
issue: {
id: string;
title: string;
description: string;
url: string;
assignee: {
id: string;
email: string;
name: string;
};
};
};
}

const getIssue = async (z: ZObject, bundle: Bundle) => {
const response = await z.request({
url: "https://api.linear.app/graphql",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
authorization: bundle.authData.api_key,
},
body: {
query: `
query Issue {
issue(id: "${bundle.inputData.id}") {
id
title
description
url
assignee {
id
email
name
url
isMe
displayName
active
}
archivedAt
canceledAt
cycle {
id
name
description
}
completedAt
createdAt
creator {
id
email
name
url
isMe
displayName
active
}
dueDate
estimate
number
parent {
id
url
title
}
priority
priorityLabel
startedAt
startedTriageAt
trashed
triagedAt
updatedAt
team {
id
name
organization {
id
name
}
}
}
}`,
},
method: "POST",
});
const data = (response.json as IssueResponse).data;
const issue = data.issue;

return [issue];
};

export const findIssueByID = {
key: "issue",
noun: "Issue",

display: {
label: "Find Issue by ID",
hidden: false,
description:
"Find an Issue by ID.",
},

operation: {
perform: getIssue,
inputFields: [
{
key: "id",
required: true,
label: "ID of Issue",
}
]
},
};
107 changes: 107 additions & 0 deletions src/searches/project.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { ZObject, Bundle } from "zapier-platform-core";

interface ProjectResponse {
data: {
project: {
id: string;
name: string;
url: string;
creator: {
id: string;
email: string;
name: string;
};
};
};
}

const getProject = async (z: ZObject, bundle: Bundle) => {
const response = await z.request({
url: "https://api.linear.app/graphql",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
authorization: bundle.authData.api_key,
},
body: {
query: `
query Project {
project(id: ${bundle.inputData.id}) {
id
name
url
archivedAt
canceledAt
autoArchivedAt
completedAt
completedIssueCountHistory
content
createdAt
creator {
id
email
name
url
isMe
displayName
active
}
currentProgress
description
health
healthUpdatedAt
lead {
id
email
name
url
isMe
displayName
active
}
priority
prioritySortOrder
projectUpdateRemindersPausedUntilAt
slugId
startDate
startedAt
startDateResolution
status {
name
}
targetDate
trashed
updatedAt
}
}`,
},
method: "POST",
});
const data = (response.json as ProjectResponse).data;
const project = data.project;

return [project];
};

export const findProjectByID = {
key: "project",
noun: "Project",

display: {
label: "Find Project by ID",
hidden: false,
description:
"Find a Project by ID.",
},

operation: {
perform: getProject,
inputFields: [
{
key: "id",
required: true,
label: "Project ID or Slug ID",
}
]
},
};

0 comments on commit fdd33e3

Please sign in to comment.