Skip to content

Commit

Permalink
Merge pull request #65 from linear/leela/undo-changes
Browse files Browse the repository at this point in the history
Revert local changes
  • Loading branch information
leelasn authored Aug 29, 2024
2 parents 0aa31e5 + 2c02b26 commit 2adde07
Show file tree
Hide file tree
Showing 26 changed files with 155 additions and 488 deletions.
Binary file removed .DS_Store
Binary file not shown.
4 changes: 1 addition & 3 deletions .env.default
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
LINEAR_API_KEY=""
LINEAR_TEAM_ID=""
CLIENT_ID="7216cc181f5dde9023e6b50f9431a7f3"
CLIENT_SECRET="1abbd8d3668f0aa45707e8f91e19eaf0"
LINEAR_TEAM_ID=""
3 changes: 1 addition & 2 deletions .zapierapprc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"id": 210859,
"key": "App210859"
"id": 66808
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "linear-zapier-test",
"version": "1.0.0",
"description": "Test Linear Zapier integration",
"name": "linear-zapier",
"version": "2.14.0",
"description": "Linear's Zapier integration",
"main": "index.js",
"license": "MIT",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions src/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface AuthResponse {

const testAuth = async (z: ZObject, bundle: Bundle) => {
const response = await z.request({
url: "https://linear-dev-zapier.ngrok.io/graphql",
url: "https://api.linear.app/graphql",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Expand Down Expand Up @@ -55,7 +55,7 @@ export const authentication = {
// "authorizeUrl" could also be a function returning a string url
authorizeUrl: {
method: "GET",
url: "https://local.linear.dev:8080/oauth/authorize",
url: "https://linear.app/oauth/authorize",
params: {
client_id: "{{process.env.CLIENT_ID}}",
state: "{{bundle.inputData.state}}",
Expand All @@ -69,7 +69,7 @@ export const authentication = {
// "getAccessToken" could also be a function returning an object
getAccessToken: {
method: "POST",
url: "https://linear-dev-zapier.ngrok.io/oauth/token",
url: "https://api.linear.app/oauth/token",
body: {
code: "{{bundle.inputData.code}}",
client_id: "{{process.env.CLIENT_ID}}",
Expand Down
2 changes: 1 addition & 1 deletion src/creates/createComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const createCommentRequest = async (z: ZObject, bundle: Bundle) => {
}`;

const response = await z.request({
url: "https://linear-dev-zapier.ngrok.io/graphql",
url: "https://api.linear.app/graphql",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Expand Down
24 changes: 12 additions & 12 deletions src/creates/createIssue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ const createIssueRequest = async (z: ZObject, bundle: Bundle) => {
const priority = bundle.inputData.priority ? parseInt(bundle.inputData.priority) : 0;
const estimate = bundle.inputData.estimate ? parseInt(bundle.inputData.estimate) : null;

const subscriberIds: string[] = [];
const subscriberIds: string[] = []
if (bundle.inputData.subscriber_emails) {
z.console.log(`Getting subscribers by emails: ${bundle.inputData.subscriber_emails.length}`);
z.console.log(`Getting subscribers by emails: ${bundle.inputData.subscriber_emails.length}`)
const usersQuery = `
query ZapierUsersByEmails($filter: UserFilter, $first: Int) {
users(filter: $filter, first: $first) {
Expand All @@ -38,13 +38,13 @@ const createIssueRequest = async (z: ZObject, bundle: Bundle) => {
`;
const usersVariables = {
filter: {
email: { in: bundle.inputData.subscriber_emails },
email: {in: bundle.inputData.subscriber_emails}
},
first: 100,
};
first: 100
}
// Transform subscriber emails to user ids
const usersResponse = await z.request({
url: "https://linear-dev-zapier.ngrok.io/graphql",
url: "https://api.linear.app/graphql",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Expand Down Expand Up @@ -72,16 +72,16 @@ const createIssueRequest = async (z: ZObject, bundle: Bundle) => {

if (users.errors && users.errors.length) {
const error = users.errors[0];
z.console.error(`Failed to get subscribers: ${JSON.stringify(error)}`);
z.console.error(`Failed to get subscribers: ${JSON.stringify(error)}`)
throw new z.errors.Error(
(error.extensions && error.extensions.userPresentableMessage) || error.message,
"invalid_input",
400
);
}

z.console.log(`Got ${users.data?.users.nodes.length} subscribers`);
subscriberIds.push(...(users.data?.users.nodes.map((user) => user.id) || []));
z.console.log(`Got ${users.data?.users.nodes.length} subscribers`)
subscriberIds.push(...(users.data?.users.nodes.map(user => user.id) || []))
}

const variables = {
Expand All @@ -97,7 +97,7 @@ const createIssueRequest = async (z: ZObject, bundle: Bundle) => {
projectMilestoneId: bundle.inputData.project_milestone_id,
dueDate: bundle.inputData.due_date,
labelIds: bundle.inputData.labels || [],
subscriberIds,
subscriberIds
};

const query = `
Expand Down Expand Up @@ -142,7 +142,7 @@ const createIssueRequest = async (z: ZObject, bundle: Bundle) => {
}`;

const response = await z.request({
url: "https://linear-dev-zapier.ngrok.io/graphql",
url: "https://api.linear.app/graphql",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Expand Down Expand Up @@ -282,7 +282,7 @@ export const createIssue = {
data: {
id: "4",
title: "Do the roar",
url: "https://local.linear.dev/team-best-team/issue/ENG-118/do-the-roar",
url: "https://linear.app/team-best-team/issue/ENG-118/do-the-roar",
identifier: "ENG-118",
},
},
Expand Down
6 changes: 2 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,21 @@ import { projectMilestone } from "./triggers/projectMilestone";
import { HttpResponse, ZObject } from "zapier-platform-core";
import { createComment } from "./creates/createComment";
import { estimate } from "./triggers/estimate";
import { newDocumentCommentV2 } from "./triggers/commentDocumentV2";

const handleErrors = (response: HttpResponse, z: ZObject) => {
if (response.request.url !== "https://linear-dev-zapier.ngrok.io/graphql") {
if (response.request.url !== "https://api.linear.app/graphql") {
return response;
}

if (response.status === 200) {
const data = response.json as any;
const error = data.errors ? data.errors[0] : undefined;
z.console.log("handling errors", data);
if (error && error.extensions.type === "authentication error") {
throw new z.errors.ExpiredAuthError(`Authentication with Linear failed. Please reconnect.`);
}
} else {
z.console.log("Catch error", response.status, response.json);
z.console.log("Error extensions", response.json.errors?.extensions);
throw new z.errors.Error(`Something went wrong`, "request_execution_failed", 400);
}
return response;
Expand All @@ -48,7 +47,6 @@ const App = {
[newProjectUpdate.key]: newProjectUpdate,
[newProjectUpdateComment.key]: newProjectUpdateComment,
[newDocumentComment.key]: newDocumentComment,
[newDocumentCommentV2.key]: newDocumentCommentV2,
[updatedProjectUpdate.key]: updatedProjectUpdate,
[team.key]: team,
[status.key]: status,
Expand Down
2 changes: 1 addition & 1 deletion src/samples/documentComment.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"project": {
"id": "73cd5db5-35a1-4d6a-a796-7060c98842f5",
"name": "iOS App",
"url": "https://local.linear.dev/example/project/ios-app-629ae4138e0d"
"url": "https://linear.app/example/project/ios-app-629ae4138e0d"
},
"document": null
},
Expand Down
4 changes: 2 additions & 2 deletions src/samples/issue.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "dbb942a5-cb3e-4dd0-a4bb-34711761f6ab",
"identifier": "SAMPLE-15",
"url": "https://local.linear.dev/example/issue/SAMPLE-15",
"url": "https://linear.app/example/issue/SAMPLE-15",
"title": "Zapier sample",
"description": "More information about the issue",
"priority": 0,
Expand Down Expand Up @@ -37,7 +37,7 @@
"parent": {
"id": "a4d10085-11bc-408a-909d-c9a1a146f8b4",
"identifier": "SAMPLE-10",
"url": "https://local.linear.dev/example/issue/SAMPLE-10",
"url": "https://linear.app/example/issue/SAMPLE-10",
"title": "Zapier parent sample"
}
}
4 changes: 2 additions & 2 deletions src/samples/issueComment.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"id": "dbb942a5-cb3e-4dd0-a4bb-34711761f6ab",
"body": "New comment",
"url": "https://local.linear.dev/example/issue/SAMPLE-15#comment-dbb942a5-cb3e-4dd0-a4bb-34711761f6ab",
"url": "https://linear.app/example/issue/SAMPLE-15#comment-dbb942a5-cb3e-4dd0-a4bb-34711761f6ab",
"createdAt": "2020-10-27T21:20:59.199Z",
"updatedAt": "2020-10-27T21:20:59.199Z",
"issue": {
"id": "dbb942a5-cb3e-4dd0-a4bb-34711761f6ac",
"identifier": "SAMPLE-15",
"title": "Zapier sample",
"url": "https://local.linear.dev/example/issue/SAMPLE-15",
"url": "https://linear.app/example/issue/SAMPLE-15",
"team": {
"id": "df2b39ba-3dfd-4b75-9ce2-2be2d1c79a2d",
"name": "Sample team"
Expand Down
2 changes: 1 addition & 1 deletion src/samples/projectUpdate.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"body": "This is a project update body in Markdown format!",
"diffMarkdown": "This is a project update diff in Markdown format!",
"health": "onTrack|atRisk|offTrack",
"url": "https://local.linear.dev/linear/updateA",
"url": "https://linear.app/linear/updateA",
"editedAt": "2022-10-27T21:20:59.199Z",
"createdAt": "2022-10-27T21:20:59.199Z",
"updatedAt": "2022-10-27T21:20:59.199Z",
Expand Down
4 changes: 2 additions & 2 deletions src/samples/projectUpdateComment.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
"email": "[email protected]",
"avatarUrl": null
},
"url": "https://local.linear.dev/example/project/the-bext-project-4437c60bc5ec#projectUpdate-bb1cfa33",
"url": "https://linear.app/example/project/the-bext-project-4437c60bc5ec#projectUpdate-bb1cfa33",
"project": {
"id": "9f337b8e-f1fa-4d37-b41a-7f58e2321b63",
"name": "The Best Project",
"url": "https://local.linear.dev/example/project/the-bext-project-4437c60bc5ec"
"url": "https://linear.app/example/project/the-bext-project-4437c60bc5ec"
}
},
"user": {
Expand Down
25 changes: 9 additions & 16 deletions src/triggers/commentDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,12 @@ interface CommentsResponse {
const getCommentList = () => async (z: ZObject, bundle: Bundle) => {
const cursor = bundle.meta.page ? await z.cursor.get() : undefined;

const variables = omitBy(
{
creatorId: bundle.inputData.creator_id,
projectId: bundle.inputData.project_id,
documentId: bundle.inputData.document_id,
after: cursor,
},
(v) => v === undefined
);
const variables = omitBy({
creatorId: bundle.inputData.creator_id,
projectId: bundle.inputData.project_id,
documentId: bundle.inputData.document_id,
after: cursor,
}, v => v === undefined);

const filters = [];
if ("creatorId" in variables) {
Expand All @@ -87,7 +84,7 @@ const getCommentList = () => async (z: ZObject, bundle: Bundle) => {
}

const response = await z.request({
url: "https://linear-dev-zapier.ngrok.io/graphql",
url: "https://api.linear.app/graphql",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Expand All @@ -104,16 +101,12 @@ const getCommentList = () => async (z: ZObject, bundle: Bundle) => {
comments(
first: 25
after: $after
${
filters.length > 0
? `
${filters.length > 0 ?`
filter: {
and : [
${filters.join("\n ")}
]
}`
: ""
}
}` : ""}
) {
nodes {
id
Expand Down
Loading

0 comments on commit 2adde07

Please sign in to comment.