From b85f3cd880f420e98676b7cd877f0162e1320689 Mon Sep 17 00:00:00 2001 From: Jorge Cortes Date: Thu, 27 Jun 2024 18:42:54 -0500 Subject: [PATCH] New action component create-custom-field-options-context Added docs link Fixed path Fixed parsing --- .../add-attachment-to-issue.mjs | 2 +- .../add-comment-to-issue.mjs | 2 +- .../add-multiple-attachments-to-issue.mjs | 2 +- .../add-watcher-to-issue.mjs | 2 +- .../actions/assign-issue/assign-issue.mjs | 2 +- .../create-custom-field-options-context.mjs | 83 +++++++++++++ .../actions/create-issue/create-issue.mjs | 2 +- .../actions/create-version/create-version.mjs | 2 +- .../actions/delete-project/delete-project.mjs | 2 +- .../get-all-projects/get-all-projects.mjs | 2 +- .../jira/actions/get-issue/get-issue.mjs | 2 +- components/jira/actions/get-task/get-task.mjs | 2 +- .../get-transitions/get-transitions.mjs | 2 +- components/jira/actions/get-user/get-user.mjs | 2 +- .../jira/actions/get-users/get-users.mjs | 2 +- .../list-issue-comments.mjs | 2 +- .../transition-issue/transition-issue.mjs | 2 +- .../actions/update-comment/update-comment.mjs | 2 +- .../actions/update-issue/update-issue.mjs | 2 +- components/jira/common/constants.mjs | 3 + components/jira/common/utils.mjs | 24 ++++ components/jira/jira.app.mjs | 111 +++++++++++++++++- components/jira/package.json | 2 +- components/jira/sources/events/events.mjs | 2 +- .../sources/issue-created/issue-created.mjs | 2 +- .../sources/issue-deleted/issue-deleted.mjs | 2 +- .../sources/issue-updated/issue-updated.mjs | 2 +- 27 files changed, 243 insertions(+), 24 deletions(-) create mode 100644 components/jira/actions/create-custom-field-options-context/create-custom-field-options-context.mjs diff --git a/components/jira/actions/add-attachment-to-issue/add-attachment-to-issue.mjs b/components/jira/actions/add-attachment-to-issue/add-attachment-to-issue.mjs index b53c9e1b9ca57..473bfbdd01053 100644 --- a/components/jira/actions/add-attachment-to-issue/add-attachment-to-issue.mjs +++ b/components/jira/actions/add-attachment-to-issue/add-attachment-to-issue.mjs @@ -8,7 +8,7 @@ export default { key: "jira-add-attachment-to-issue", name: "Add Attachment To Issue", description: "Adds an attachment to an issue, [See the docs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-rest-api-3-issue-issueidorkey-attachments-post)", - version: "0.2.10", + version: "0.2.11", type: "action", props: { jira, diff --git a/components/jira/actions/add-comment-to-issue/add-comment-to-issue.mjs b/components/jira/actions/add-comment-to-issue/add-comment-to-issue.mjs index 8b329e3fadec7..4077feaa542d6 100644 --- a/components/jira/actions/add-comment-to-issue/add-comment-to-issue.mjs +++ b/components/jira/actions/add-comment-to-issue/add-comment-to-issue.mjs @@ -5,7 +5,7 @@ export default { key: "jira-add-comment-to-issue", name: "Add Comment To Issue", description: "Adds a new comment to an issue, [See the docs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-comments/#api-rest-api-3-issue-issueidorkey-comment-post)", - version: "0.1.8", + version: "0.1.9", type: "action", props: { jira, diff --git a/components/jira/actions/add-multiple-attachments-to-issue/add-multiple-attachments-to-issue.mjs b/components/jira/actions/add-multiple-attachments-to-issue/add-multiple-attachments-to-issue.mjs index 84fe52d74ea64..940407a16f5df 100644 --- a/components/jira/actions/add-multiple-attachments-to-issue/add-multiple-attachments-to-issue.mjs +++ b/components/jira/actions/add-multiple-attachments-to-issue/add-multiple-attachments-to-issue.mjs @@ -8,7 +8,7 @@ export default { key: "jira-add-multiple-attachments-to-issue", name: "Add Multiple Attachments To Issue", description: "Adds multiple attachments to an issue, [See the docs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-rest-api-3-issue-issueidorkey-attachments-post)", - version: "0.0.8", + version: "0.0.9", type: "action", props: { jira, diff --git a/components/jira/actions/add-watcher-to-issue/add-watcher-to-issue.mjs b/components/jira/actions/add-watcher-to-issue/add-watcher-to-issue.mjs index 0bffe8eeac9e4..c16026baeef1c 100644 --- a/components/jira/actions/add-watcher-to-issue/add-watcher-to-issue.mjs +++ b/components/jira/actions/add-watcher-to-issue/add-watcher-to-issue.mjs @@ -3,7 +3,7 @@ import jira from "../../jira.app.mjs"; export default { key: "jira-add-watcher-to-issue", name: "Add Watcher To Issue", - version: "0.0.7", + version: "0.0.8", description: "Adds a user as a watcher of an issue by passing the account ID of the user, For example, `5b10ac8d82e05b22cc7d4ef5`, If no user is specified the calling user is added. [See the docs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-watchers/#api-rest-api-3-issue-issueidorkey-watchers-post)", type: "action", props: { diff --git a/components/jira/actions/assign-issue/assign-issue.mjs b/components/jira/actions/assign-issue/assign-issue.mjs index 65a5964e6b6d3..4050b2b4a1f2f 100644 --- a/components/jira/actions/assign-issue/assign-issue.mjs +++ b/components/jira/actions/assign-issue/assign-issue.mjs @@ -3,7 +3,7 @@ import jira from "../../jira.app.mjs"; export default { key: "jira-assign-issue", name: "Assign Issue", - version: "0.0.7", + version: "0.0.8", description: "Assigns an issue to a user. [See the docs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-assignee-put)", type: "action", props: { diff --git a/components/jira/actions/create-custom-field-options-context/create-custom-field-options-context.mjs b/components/jira/actions/create-custom-field-options-context/create-custom-field-options-context.mjs new file mode 100644 index 0000000000000..2d5a9561430c0 --- /dev/null +++ b/components/jira/actions/create-custom-field-options-context/create-custom-field-options-context.mjs @@ -0,0 +1,83 @@ +import app from "../../jira.app.mjs"; +import utils from "../../common/utils.mjs"; + +export default { + key: "jira-create-custom-field-options-context", + name: "Create Custom Field Options (Context)", + description: "Create a context for custom field options. [See the documentation here](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-custom-field-options/#api-rest-api-3-field-fieldid-context-contextid-option-post).", + version: "0.0.1", + type: "action", + props: { + app, + cloudId: { + propDefinition: [ + app, + "cloudId", + ], + }, + fieldId: { + propDefinition: [ + app, + "fieldId", + ({ cloudId }) => ({ + cloudId, + params: { + type: [ + "custom", + ], + }, + }), + ], + }, + contextId: { + propDefinition: [ + app, + "contextId", + ({ + cloudId, fieldId, + }) => ({ + cloudId, + fieldId, + }), + ], + }, + options: { + type: "string[]", + label: "Options", + description: "Options to create. Each option should be a JSON object with the following structure as an example: `{ \"value\": \"Manhattan\", \"optionId\": \"1000\", \"disabled\": true }` where the only required field is `value`.", + }, + }, + methods: { + createCustomFieldOptionsContext({ + fieldId, contextId, ...args + }) { + return this.app._makeRequest({ + method: "POST", + path: `/field/${fieldId}/context/${contextId}/option`, + ...args, + }); + }, + }, + async run({ $ }) { + const { + createCustomFieldOptionsContext, + cloudId, + fieldId, + contextId, + options, + } = this; + + const response = await createCustomFieldOptionsContext({ + $, + cloudId, + fieldId, + contextId, + data: { + options: utils.parseArray(options).map(utils.parseOne), + }, + }); + + $.export("$summary", `Successfully created custom field options for field \`${fieldId}\` and context \`${contextId}\``); + return response; + }, +}; diff --git a/components/jira/actions/create-issue/create-issue.mjs b/components/jira/actions/create-issue/create-issue.mjs index 77e55be454157..641a4018d95ea 100644 --- a/components/jira/actions/create-issue/create-issue.mjs +++ b/components/jira/actions/create-issue/create-issue.mjs @@ -7,7 +7,7 @@ export default { key: "jira-create-issue", name: "Create Issue", description: "Creates an issue or, where the option to create subtasks is enabled in Jira, a subtask, [See the docs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-rest-api-3-issue-post)", - version: "0.1.16", + version: "0.1.17", type: "action", props: { ...common.props, diff --git a/components/jira/actions/create-version/create-version.mjs b/components/jira/actions/create-version/create-version.mjs index 90e5dcc135a90..603ddbd2519d4 100644 --- a/components/jira/actions/create-version/create-version.mjs +++ b/components/jira/actions/create-version/create-version.mjs @@ -4,7 +4,7 @@ export default { key: "jira-create-version", name: "Create Jira Version in project", description: "Creates a project version., [See the docs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-project-versions/#api-rest-api-3-version-post)", - version: "0.1.8", + version: "0.1.9", type: "action", props: { jira, diff --git a/components/jira/actions/delete-project/delete-project.mjs b/components/jira/actions/delete-project/delete-project.mjs index 87cc46808bbd0..ee9b52b94e2d4 100644 --- a/components/jira/actions/delete-project/delete-project.mjs +++ b/components/jira/actions/delete-project/delete-project.mjs @@ -4,7 +4,7 @@ export default { key: "jira-delete-project", name: "Delete Project", description: "Deletes a project, [See the docs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-projects/#api-rest-api-3-project-projectidorkey-delete)", - version: "0.1.8", + version: "0.1.9", type: "action", props: { jira, diff --git a/components/jira/actions/get-all-projects/get-all-projects.mjs b/components/jira/actions/get-all-projects/get-all-projects.mjs index 966bfd1d1c5a1..740ae0bcb85b1 100644 --- a/components/jira/actions/get-all-projects/get-all-projects.mjs +++ b/components/jira/actions/get-all-projects/get-all-projects.mjs @@ -4,7 +4,7 @@ export default { key: "jira-get-all-projects", name: "Get All Projects", description: "Gets metadata on all projects, [See the docs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-rest-api-3-project-get)", - version: "0.1.9", + version: "0.1.10", type: "action", props: { jira, diff --git a/components/jira/actions/get-issue/get-issue.mjs b/components/jira/actions/get-issue/get-issue.mjs index 7ff8e32388ee1..ec25689806e02 100644 --- a/components/jira/actions/get-issue/get-issue.mjs +++ b/components/jira/actions/get-issue/get-issue.mjs @@ -4,7 +4,7 @@ export default { key: "jira-get-issue", name: "Get Issue", description: "Gets the details for an issue. [See the docs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-get)", - version: "0.1.10", + version: "0.1.11", type: "action", props: { jira, diff --git a/components/jira/actions/get-task/get-task.mjs b/components/jira/actions/get-task/get-task.mjs index 831a1836c4717..46f0dd702527d 100644 --- a/components/jira/actions/get-task/get-task.mjs +++ b/components/jira/actions/get-task/get-task.mjs @@ -4,7 +4,7 @@ export default { key: "jira-get-task", name: "Get Task", description: "Gets the status of a long-running asynchronous task, [See the docs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-tasks/#api-rest-api-3-task-taskid-get)", - version: "0.1.8", + version: "0.1.9", type: "action", props: { jira, diff --git a/components/jira/actions/get-transitions/get-transitions.mjs b/components/jira/actions/get-transitions/get-transitions.mjs index fbd06aa6ab6a7..2105bda67dd03 100644 --- a/components/jira/actions/get-transitions/get-transitions.mjs +++ b/components/jira/actions/get-transitions/get-transitions.mjs @@ -4,7 +4,7 @@ export default { key: "jira-get-transitions", name: "Get Transitions", description: "Gets either all transitions or a transition that can be performed by the user on an issue, based on the issue's status, [See the docs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-transitions-get)", - version: "0.1.8", + version: "0.1.9", type: "action", props: { jira, diff --git a/components/jira/actions/get-user/get-user.mjs b/components/jira/actions/get-user/get-user.mjs index f6debc37b3699..d6dbe3afa9d72 100644 --- a/components/jira/actions/get-user/get-user.mjs +++ b/components/jira/actions/get-user/get-user.mjs @@ -4,7 +4,7 @@ export default { key: "jira-get-user", name: "Get User", description: "Gets details of user, [See the docs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-users/#api-rest-api-3-user-get)", - version: "0.1.8", + version: "0.1.9", type: "action", props: { jira, diff --git a/components/jira/actions/get-users/get-users.mjs b/components/jira/actions/get-users/get-users.mjs index 3a826f638d923..e22bf77314658 100644 --- a/components/jira/actions/get-users/get-users.mjs +++ b/components/jira/actions/get-users/get-users.mjs @@ -4,7 +4,7 @@ export default { key: "jira-get-users", name: "Get Users", description: "Gets details of a list of users. [See docs here](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-users/#api-rest-api-3-users-search-get)", - version: "0.0.3", + version: "0.0.4", type: "action", props: { jira, diff --git a/components/jira/actions/list-issue-comments/list-issue-comments.mjs b/components/jira/actions/list-issue-comments/list-issue-comments.mjs index 919e05440a99f..d43366bd5c3e3 100644 --- a/components/jira/actions/list-issue-comments/list-issue-comments.mjs +++ b/components/jira/actions/list-issue-comments/list-issue-comments.mjs @@ -4,7 +4,7 @@ export default { key: "jira-list-issue-comments", name: "List Issue Comments", description: "Lists all comments for an issue, [See the docs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-comments/#api-rest-api-3-issue-issueidorkey-comment-get)", - version: "0.1.8", + version: "0.1.9", type: "action", props: { jira, diff --git a/components/jira/actions/transition-issue/transition-issue.mjs b/components/jira/actions/transition-issue/transition-issue.mjs index 255bce88f3904..28e7f498f7faa 100644 --- a/components/jira/actions/transition-issue/transition-issue.mjs +++ b/components/jira/actions/transition-issue/transition-issue.mjs @@ -5,7 +5,7 @@ export default { key: "jira-transition-issue", name: "Transition Issue", description: "Performs an issue transition and, if the transition has a screen, updates the fields from the transition screen, [See the docs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-transitions-post)", - version: "0.1.10", + version: "0.1.11", type: "action", props: { jira, diff --git a/components/jira/actions/update-comment/update-comment.mjs b/components/jira/actions/update-comment/update-comment.mjs index ec782e8e28601..fb4b149a1790c 100644 --- a/components/jira/actions/update-comment/update-comment.mjs +++ b/components/jira/actions/update-comment/update-comment.mjs @@ -5,7 +5,7 @@ export default { key: "jira-update-comment", name: "Update Comment", description: "Updates a comment, [See the docs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-comments/#api-rest-api-3-issue-issueidorkey-comment-id-put)", - version: "0.1.8", + version: "0.1.9", type: "action", props: { jira, diff --git a/components/jira/actions/update-issue/update-issue.mjs b/components/jira/actions/update-issue/update-issue.mjs index 48f0f611fd266..51b0009f8f541 100644 --- a/components/jira/actions/update-issue/update-issue.mjs +++ b/components/jira/actions/update-issue/update-issue.mjs @@ -8,7 +8,7 @@ export default { key: "jira-update-issue", name: "Update Issue", description: "Updates an issue. A transition may be applied and issue properties updated as part of the edit, [See the docs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-put)", - version: "0.2.10", + version: "0.2.11", type: "action", props: { ...common.props, diff --git a/components/jira/common/constants.mjs b/components/jira/common/constants.mjs index c227606cccb0e..e9d12c30fa197 100644 --- a/components/jira/common/constants.mjs +++ b/components/jira/common/constants.mjs @@ -34,9 +34,12 @@ const SCHEMA = { }, }; +const DEFAULT_LIMIT = 50; + export default { TYPE, FIELD_KEY, FIELD_TYPE, SCHEMA, + DEFAULT_LIMIT, }; diff --git a/components/jira/common/utils.mjs b/components/jira/common/utils.mjs index 9752e1b44b080..6e52c8570349c 100644 --- a/components/jira/common/utils.mjs +++ b/components/jira/common/utils.mjs @@ -1,3 +1,5 @@ +import { ConfigurationError } from "@pipedream/platform"; + function addProperty({ src, predicate, addition, }) { @@ -20,6 +22,28 @@ export default { console.log(`Error when trying to parse: ${str}`, err); } }, + parseArray(value) { + try { + if (!value) { + return []; + } + + if (Array.isArray(value)) { + return value; + } + + const parsedValue = JSON.parse(value); + + if (!Array.isArray(parsedValue)) { + throw new Error("Not an array"); + } + + return parsedValue; + + } catch (e) { + throw new ConfigurationError("Make sure the custom expression contains a valid array object"); + } + }, parseOne(obj) { let parsed; try { diff --git a/components/jira/jira.app.mjs b/components/jira/jira.app.mjs index c31a35d25a157..6e5205770d50e 100644 --- a/components/jira/jira.app.mjs +++ b/components/jira/jira.app.mjs @@ -1,6 +1,7 @@ import { ConfigurationError, axios, } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; export default { type: "app", @@ -213,8 +214,102 @@ export default { description: "List of issue screen fields to update, specifying the sub-field to update and its value for each field. This field provides a straightforward option when setting a sub-field. When multiple sub-fields or other operations are required, use `update`. Fields included in here cannot be included in `update`. (.i.e for Fields \"fields\": {\"summary\":\"Completed orders still displaying in pending\",\"customfield_10010\":1,}) [see doc](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-put)", optional: true, }, - }, + fieldId: { + type: "string", + label: "Field ID", + description: "The ID of the field.", + useQuery: true, + async options({ + query, + prevContext: { + hasMore, + startAt = 0, + }, + cloudId, + params = { + type: [ + "custom", + "system", + ], + }, + }) { + if (hasMore === false) { + return []; + } + + const { + isLast, + values, + } = await this.getFieldsPaginated({ + cloudId, + params: { + ...params, + query, + maxResults: constants.DEFAULT_LIMIT, + startAt, + }, + }); + + return { + options: values.map(({ + id: value, name: label, + }) => ({ + label, + value, + })), + context: { + hasMore: !isLast, + startAt: startAt + constants.DEFAULT_LIMIT, + }, + }; + }, + }, + contextId: { + type: "string", + label: "Context ID", + description: "The ID of the context.", + async options({ + prevContext: { + hasMore, + startAt = 0, + }, + cloudId, + fieldId, + params = { + isAnyIssueType: true, + }, + }) { + if (hasMore === false) { + return []; + } + const { + isLast, + values, + } = await this.getCustomFieldContexts({ + cloudId, + fieldId, + params: { + ...params, + startAt, + maxResults: constants.DEFAULT_LIMIT, + }, + }); + return { + options: values.map(({ + id: value, name: label, + }) => ({ + label, + value, + })), + context: { + hasMore: !isLast, + startAt: startAt + constants.DEFAULT_LIMIT, + }, + }; + }, + }, + }, methods: { _getHeaders(headers = {}) { return { @@ -474,6 +569,20 @@ export default { ...args, }); }, + getFieldsPaginated(args = {}) { + return this._makeRequest({ + path: "/field/search", + ...args, + }); + }, + getCustomFieldContexts({ + fieldId, ...args + } = {}) { + return this._makeRequest({ + path: `/field/${fieldId}/context`, + ...args, + }); + }, async *getResourcesStream({ cloudId, resourceFn, diff --git a/components/jira/package.json b/components/jira/package.json index 4503615813d9a..bf79ab58616a8 100644 --- a/components/jira/package.json +++ b/components/jira/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/jira", - "version": "0.0.16", + "version": "0.1.0", "description": "Pipedream Jira Components", "main": "jira.app.mjs", "keywords": [ diff --git a/components/jira/sources/events/events.mjs b/components/jira/sources/events/events.mjs index ed5807c1a7cc7..2331c35d109ed 100644 --- a/components/jira/sources/events/events.mjs +++ b/components/jira/sources/events/events.mjs @@ -5,7 +5,7 @@ export default { key: "jira-events", name: "New Event", description: "Emit new event when an event with subscribed event source triggered, [See the docs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-webhooks/#api-rest-api-3-webhook-post)", - version: "0.0.8", + version: "0.0.9", type: "source", dedupe: "unique", ...common, diff --git a/components/jira/sources/issue-created/issue-created.mjs b/components/jira/sources/issue-created/issue-created.mjs index 09c86c2784a0a..b696d3acd974a 100644 --- a/components/jira/sources/issue-created/issue-created.mjs +++ b/components/jira/sources/issue-created/issue-created.mjs @@ -4,7 +4,7 @@ export default { key: "jira-issue-created", name: "New Issue Created Event", description: "Emit new event when an issue is created. Note that Jira supports only one webhook, if more sources are needed please use `New Event` source and select multiple events.", - version: "0.0.8", + version: "0.0.9", type: "source", dedupe: "unique", ...common, diff --git a/components/jira/sources/issue-deleted/issue-deleted.mjs b/components/jira/sources/issue-deleted/issue-deleted.mjs index 9dc774691ad5d..b8e73b78554ae 100644 --- a/components/jira/sources/issue-deleted/issue-deleted.mjs +++ b/components/jira/sources/issue-deleted/issue-deleted.mjs @@ -4,7 +4,7 @@ export default { key: "jira-issue-deleted", name: "New Issue Deleted Event", description: "Emit new event when an issue is deleted. Note that Jira supports only one webhook, if more sources are needed please use `New Event` source and select multiple events.", - version: "0.0.8", + version: "0.0.9", type: "source", dedupe: "unique", ...common, diff --git a/components/jira/sources/issue-updated/issue-updated.mjs b/components/jira/sources/issue-updated/issue-updated.mjs index 10857d60f4359..6ce2287dfafc8 100644 --- a/components/jira/sources/issue-updated/issue-updated.mjs +++ b/components/jira/sources/issue-updated/issue-updated.mjs @@ -4,7 +4,7 @@ export default { key: "jira-issue-updated", name: "New Issue Updated Event", description: "Emit new event when an issue is updated. Note that Jira supports only one webhook, if more sources are needed please use `New Event` source and select multiple events.", - version: "0.0.8", + version: "0.0.9", type: "source", dedupe: "unique", ...common,