-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from linear/leela/fea-2473-add-attachment-fiel…
…d-to-zapier-for-issue-creation Add "create issue attachment" action
- Loading branch information
Showing
4 changed files
with
113 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { Bundle, ZObject } from "zapier-platform-core"; | ||
import { fetchFromLinear } from "../fetchFromLinear"; | ||
|
||
interface AttachmentCreateResponse { | ||
data?: { attachmentCreate: { attachment: { id: string; url: string; title: string }; success: boolean } }; | ||
errors?: { | ||
message: string; | ||
extensions?: { | ||
userPresentableMessage?: string; | ||
}; | ||
}[]; | ||
} | ||
|
||
const createAttachmentRequest = async (z: ZObject, bundle: Bundle) => { | ||
const variables = { | ||
issueId: bundle.inputData.issue, | ||
url: bundle.inputData.url, | ||
title: bundle.inputData.title || "", | ||
}; | ||
|
||
const query = ` | ||
mutation ZapierAttachmentCreate( | ||
$issueId: String!, | ||
$url: String!, | ||
$title: String! | ||
) { | ||
attachmentCreate(input: { | ||
issueId: $issueId, | ||
url: $url, | ||
title: $title | ||
}) { | ||
attachment { | ||
id | ||
url | ||
title | ||
} | ||
success | ||
} | ||
}`; | ||
|
||
const response = await fetchFromLinear(z, bundle, query, variables); | ||
const data = response.json as AttachmentCreateResponse; | ||
|
||
if (data.errors && data.errors.length) { | ||
const error = data.errors[0]; | ||
throw new z.errors.Error( | ||
(error.extensions && error.extensions.userPresentableMessage) || error.message, | ||
"invalid_input", | ||
400 | ||
); | ||
} | ||
|
||
if (data.data && data.data.attachmentCreate && data.data.attachmentCreate.success) { | ||
return data.data.attachmentCreate.attachment; | ||
} else { | ||
const error = data.errors ? data.errors[0].message : "Something went wrong"; | ||
throw new z.errors.Error("Failed to create an attachment", error, 400); | ||
} | ||
}; | ||
|
||
export const createIssueAttachment = { | ||
key: "createIssueAttachment", | ||
display: { | ||
hidden: false, | ||
description: "Create a new issue URL attachment in Linear", | ||
label: "Create Issue Attachment", | ||
}, | ||
noun: "Attachment", | ||
operation: { | ||
perform: createAttachmentRequest, | ||
inputFields: [ | ||
{ | ||
required: true, | ||
label: "Issue", | ||
helpText: "The ID of the issue. Both UUID and issue identifier formats are accepted.", | ||
key: "issue", | ||
}, | ||
{ | ||
required: true, | ||
label: "URL", | ||
helpText: "The URL of this attachment.", | ||
key: "url", | ||
}, | ||
{ | ||
required: false, | ||
label: "Title", | ||
helpText: "The title of this attachment.", | ||
key: "title", | ||
}, | ||
], | ||
sample: { | ||
data: { | ||
attachmentCreate: { | ||
attachment: { id: "a25cce1b-510d-433f-af50-1373efc05a4a", url: "https://www.example.com", title: "My title" }, | ||
success: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters