-
Notifications
You must be signed in to change notification settings - Fork 5.8k
jira_service_desk: add attachment write tools #21869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2992611
jira_service_desk: add attachment write tools
michelle0927 33be378
jira_service_desk: fix form-data lockfile specifier
michelle0927 198fb76
jira_service_desk: bump component versions per PR review
michelle0927 950c7ef
jira_service_desk: correct create-request version to 1.0.3
michelle0927 e1a1605
jira_service_desk: address review findings on attachment tools
michelle0927 d0a60e2
jira_service_desk: surface delete failures in manage-request-attachment
michelle0927 e3aac8c
add ai: "optimized"
michelle0927 10f62aa
Merge branch 'master' into mcp/jira_service_desk
michelle0927 f049215
jira_service_desk: fix attachmentId description, add/update response …
michelle0927 bbf8c6d
jira_service_desk: bump component versions
michelle0927 39d43b8
Merge branch 'master' into mcp/jira_service_desk
michelle0927 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
173 changes: 173 additions & 0 deletions
173
components/jira_service_desk/actions/manage-request-attachment/manage-request-attachment.mjs
This file contains hidden or 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,173 @@ | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
| import jiraServiceDesk from "../../jira_service_desk.app.mjs"; | ||
| import constants from "../../common/constants.mjs"; | ||
|
|
||
| export default { | ||
| key: "jira_service_desk-manage-request-attachment", | ||
| name: "Manage Request Attachment", | ||
| description: | ||
| "Adds, replaces, or deletes a single attachment on a customer request (ticket) that already exists." | ||
| + " To attach file(s) while creating a brand-new request, use **Create Request**'s `attachments` prop instead — use this tool only for requests that already exist." | ||
| + " Set `operation` to `add` to attach a new file, `update` to replace an existing attachment with a different file (there's no in-place replace in the API, so this uploads the new file and only deletes the old one once the new one is confirmed attached), or `delete` to remove an attachment." | ||
| + " `add` and `update` require `serviceDeskId` (the temp-file upload step is scoped by service desk, not by issue) — use **List Service Desks** to find it, or read it off the response of the request that created the ticket." | ||
| + " `update` and `delete` require `attachmentId`, the numeric ID of the attachment being replaced or removed; the `add`/`update` response doesn't expose this as a plain field, so use **List Issue Attachments** on the same request to look it up." | ||
| + " Worked example: to replace an attachment `10050` on request `HD-12` with a new file, call with Operation `update`, Issue ID Or Key `HD-12`, Service Desk ID `1`, Attachment ID `10050`, and File `/tmp/revised-report.pdf`." | ||
| + " For `update`, if the new file attaches successfully but removing the old attachment then fails, the response includes a `deleteError` string alongside the successful attachment data — the request ends up with both files rather than losing either one, and the error is never masked as a full failure." | ||
| + " By default the attachment is visible to the customer who raised the request (`public: true`); set `public` to `false` to attach an internal-only file." | ||
| + " [See the documentation](https://developer.atlassian.com/cloud/jira/service-desk/rest/api-group-request/#api-rest-servicedeskapi-request-issueidorkey-attachment-post)", | ||
| version: "0.0.1", | ||
| annotations: { | ||
| destructiveHint: true, | ||
| openWorldHint: true, | ||
| readOnlyHint: false, | ||
| }, | ||
| type: "action", | ||
| ai: "optimized", | ||
| props: { | ||
| jiraServiceDesk, | ||
| cloudId: { | ||
| propDefinition: [ | ||
| jiraServiceDesk, | ||
| "cloudId", | ||
| ], | ||
| }, | ||
| operation: { | ||
| type: "string", | ||
| label: "Operation", | ||
| description: "Whether to add a new attachment, replace (`update`) an existing one, or delete one.", | ||
| options: [ | ||
| "add", | ||
| "update", | ||
| "delete", | ||
| ], | ||
| }, | ||
| issueIdOrKey: { | ||
| propDefinition: [ | ||
| jiraServiceDesk, | ||
| "issueIdOrKey", | ||
| ], | ||
| }, | ||
| serviceDeskId: { | ||
| propDefinition: [ | ||
| jiraServiceDesk, | ||
| "serviceDeskId", | ||
| ], | ||
| description: "Required for `add` and `update`. The service desk the request belongs to. Use **List Service Desks** to find valid IDs (e.g. `1`).", | ||
| optional: true, | ||
| }, | ||
| file: { | ||
| type: "string", | ||
| label: "File", | ||
| description: "Required for `add` and `update`. The file to attach, as a file URL or a path to a file in the /tmp directory (e.g. `/tmp/myFile.pdf`).", | ||
| format: "file-ref", | ||
| optional: true, | ||
| }, | ||
| attachmentId: { | ||
| type: "string", | ||
| label: "Attachment ID", | ||
| description: "Required for `update` and `delete`. The numeric ID of the attachment being replaced or removed, e.g. `10050`. The `add`/`update` response doesn't expose this as a plain field — the ID is only embedded in a `_links.jiraRest` URL nested under `attachments.values[]`. Use **List Issue Attachments** instead, which extracts the ID for you.", | ||
| optional: true, | ||
| }, | ||
| public: { | ||
| type: "boolean", | ||
| label: "Public", | ||
| description: "Whether the attached file is visible to the customer who raised the request. Defaults to `true`; set to `false` to attach an internal-only file. Only applies to `add` and `update`.", | ||
| optional: true, | ||
| default: true, | ||
| }, | ||
| syncDir: { | ||
| type: "dir", | ||
| accessMode: "read", | ||
| sync: true, | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| jiraServiceDesk, | ||
| cloudId, | ||
| operation, | ||
| issueIdOrKey, | ||
| serviceDeskId, | ||
| file, | ||
| attachmentId, | ||
| public: isPublic, | ||
| } = this; | ||
|
|
||
| const verifyAttachmentBelongsToRequest = async () => { | ||
| const { attachments } = await jiraServiceDesk.getIssueAttachments({ | ||
| $, | ||
| cloudId, | ||
| issueIdOrKey, | ||
| maxResults: constants.MAX_RESULTS_MAX, | ||
| }); | ||
| if (!attachments.some(({ id }) => id === attachmentId)) { | ||
| throw new ConfigurationError(`Attachment ID "${attachmentId}" was not found on request "${issueIdOrKey}". Run List Issue Attachments to confirm the ID and issue match.`); | ||
| } | ||
| }; | ||
|
|
||
| if (operation === "delete") { | ||
| if (!attachmentId) { | ||
| throw new ConfigurationError("Attachment ID is required to delete an attachment."); | ||
| } | ||
| await verifyAttachmentBelongsToRequest(); | ||
| await jiraServiceDesk.deleteAttachment({ | ||
| $, | ||
| cloudId, | ||
| attachmentId, | ||
| }); | ||
| $.export("$summary", `Deleted attachment ${attachmentId} from request ${issueIdOrKey}`); | ||
| return { | ||
| deleted: true, | ||
| attachmentId, | ||
| }; | ||
| } | ||
|
|
||
| if (!serviceDeskId) { | ||
| throw new ConfigurationError("Service Desk ID is required to add or update an attachment."); | ||
| } | ||
| if (!file) { | ||
| throw new ConfigurationError("File is required to add or update an attachment."); | ||
| } | ||
| if (operation === "update") { | ||
| if (!attachmentId) { | ||
| throw new ConfigurationError("Attachment ID is required to update (replace) an attachment."); | ||
| } | ||
| await verifyAttachmentBelongsToRequest(); | ||
| } | ||
|
|
||
| const attachResponse = await jiraServiceDesk.attachFilesToRequestFromSource({ | ||
| $, | ||
| cloudId, | ||
| serviceDeskId, | ||
| issueIdOrKey, | ||
| files: [ | ||
| file, | ||
| ], | ||
| isPublic, | ||
| }); | ||
|
|
||
| // The new attachment must succeed before the old one is removed — deleting first | ||
| // would leave the request with no attachment at all if the upload then failed. | ||
| if (operation === "update") { | ||
| try { | ||
| await jiraServiceDesk.deleteAttachment({ | ||
| $, | ||
| cloudId, | ||
| attachmentId, | ||
| }); | ||
| } catch (error) { | ||
| $.export("$summary", `Added the new attachment on request ${issueIdOrKey}, but the old attachment (${attachmentId}) could not be removed: ${error.message}`); | ||
| return { | ||
| ...attachResponse, | ||
| deleteError: error.message, | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| $.export("$summary", `${operation === "update" | ||
| ? "Replaced" | ||
| : "Added"} attachment on request ${issueIdOrKey}`); | ||
| return attachResponse; | ||
| }, | ||
| }; | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.