From cf33dce4f689ae775560ee4054e5591058e37cb3 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Thu, 30 Jan 2025 12:30:15 -0500 Subject: [PATCH 1/3] new components --- .../actions/add-note-alert/add-note-alert.mjs | 34 +++++++++++ .../actions/delete-alert/delete-alert.mjs | 26 ++++++++ components/opsgenie/common/constants.mjs | 1 + components/opsgenie/opsgenie.app.mjs | 59 +++++++++++++++++-- components/opsgenie/package.json | 2 +- 5 files changed, 115 insertions(+), 7 deletions(-) create mode 100644 components/opsgenie/actions/add-note-alert/add-note-alert.mjs create mode 100644 components/opsgenie/actions/delete-alert/delete-alert.mjs diff --git a/components/opsgenie/actions/add-note-alert/add-note-alert.mjs b/components/opsgenie/actions/add-note-alert/add-note-alert.mjs new file mode 100644 index 0000000000000..fc01dc48f01f4 --- /dev/null +++ b/components/opsgenie/actions/add-note-alert/add-note-alert.mjs @@ -0,0 +1,34 @@ +import opsgenie from "../../opsgenie.app.mjs"; + +export default { + key: "opsgenie-add-note-alert", + name: "Add Note to Alert", + description: "Adds a note to an existing alert in Opsgenie. [See the documentation](https://docs.opsgenie.com/docs/alert-api#add-note-to-alert)", + version: "0.0.1", + type: "action", + props: { + opsgenie, + alertId: { + propDefinition: [ + opsgenie, + "alertId", + ], + }, + note: { + type: "string", + label: "Note", + description: "Alert note to add", + }, + }, + async run({ $ }) { + const response = await this.opsgenie.addNoteToAlert({ + $, + alertId: this.alertId, + data: { + note: this.note, + }, + }); + $.export("$summary", `Successfully added note to alert with ID: ${this.alertId}`); + return response; + }, +}; diff --git a/components/opsgenie/actions/delete-alert/delete-alert.mjs b/components/opsgenie/actions/delete-alert/delete-alert.mjs new file mode 100644 index 0000000000000..33fe270945c8d --- /dev/null +++ b/components/opsgenie/actions/delete-alert/delete-alert.mjs @@ -0,0 +1,26 @@ +import opsgenie from "../../opsgenie.app.mjs"; + +export default { + key: "opsgenie-delete-alert", + name: "Delete Alert", + description: "Removes an existing alert from Opsgenie. [See the documentation](https://docs.opsgenie.com/docs/alert-api#delete-alert)", + version: "0.0.1", + type: "action", + props: { + opsgenie, + alertId: { + propDefinition: [ + opsgenie, + "alertId", + ], + }, + }, + async run({ $ }) { + const response = await this.opsgenie.deleteAlert({ + $, + alertId: this.alertId, + }); + $.export("$summary", `Successfully deleted alert with ID: ${this.alertId}`); + return response; + }, +}; diff --git a/components/opsgenie/common/constants.mjs b/components/opsgenie/common/constants.mjs index 6ff20bbfd8cd9..15af37ddffac1 100644 --- a/components/opsgenie/common/constants.mjs +++ b/components/opsgenie/common/constants.mjs @@ -1,4 +1,5 @@ export default { + DEFAULT_LIMIT: 20, PRIORITY_OPTIONS: [ "P1", "P2", diff --git a/components/opsgenie/opsgenie.app.mjs b/components/opsgenie/opsgenie.app.mjs index 3de6cf5940eff..a7b455d1330e0 100644 --- a/components/opsgenie/opsgenie.app.mjs +++ b/components/opsgenie/opsgenie.app.mjs @@ -5,6 +5,26 @@ export default { type: "app", app: "opsgenie", propDefinitions: { + alertId: { + type: "string", + label: "Alert ID", + description: "ID of the alert", + async options({ page }) { + const limit = constants.DEFAULT_LIMIT; + const { data } = await this.listAlerts({ + params: { + limit, + offset: page * limit, + }, + }); + return data?.map(({ + id: value, message: label, + }) => ({ + value, + label, + })) || []; + }, + }, user: { type: "string", label: "User ID", @@ -22,7 +42,7 @@ export default { }, message: { type: "string", - label: "message", + label: "Message", description: "The message of the alert", }, note: { @@ -56,7 +76,7 @@ export default { _baseUrl() { return `https://${this.$auth.instance_region}.opsgenie.com/v2`; }, - async _makeRequest(opts = {}) { + _makeRequest(opts = {}) { const { $ = this, path, @@ -66,14 +86,21 @@ export default { } = opts; return axios($, { ...otherOpts, - url: this._baseUrl() + path, + url: `${this._baseUrl()}${path}`, headers: { ...headers, Authorization: `GenieKey ${APIKey}`, }, }); }, - async createAlert(args = {}) { + listAlerts(opts = {}) { + return this._makeRequest({ + path: "/alerts", + APIKey: this.$auth.team_api_key, + ...opts, + }); + }, + createAlert(args = {}) { return this._makeRequest({ method: "post", path: "/alerts", @@ -81,7 +108,7 @@ export default { ...args, }); }, - async getAlertStatus({ + getAlertStatus({ requestId, ...args }) { return this._makeRequest({ @@ -90,12 +117,32 @@ export default { ...args, }); }, - async listUsers(args = {}) { + listUsers(args = {}) { return this._makeRequest({ path: "/users", APIKey: this.$auth.api_key, ...args, }); }, + addNoteToAlert({ + alertId, ...args + }) { + return this._makeRequest({ + method: "POST", + path: `/alerts/${alertId}/notes`, + APIKey: this.$auth.team_api_key, + ...args, + }); + }, + deleteAlert({ + alertId, ...args + }) { + return this._makeRequest({ + method: "DELETE", + path: `/alerts/${alertId}`, + APIKey: this.$auth.team_api_key, + ...args, + }); + }, }, }; diff --git a/components/opsgenie/package.json b/components/opsgenie/package.json index f5cce02322051..a18bfdf3a4315 100644 --- a/components/opsgenie/package.json +++ b/components/opsgenie/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/opsgenie", - "version": "0.1.0", + "version": "0.2.0", "description": "Pipedream Opsgenie Components", "main": "opsgenie.app.mjs", "keywords": [ From 90746f9354bca2fdc9fe16e93d64e4891578d77c Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Thu, 30 Jan 2025 12:35:21 -0500 Subject: [PATCH 2/3] pnpm-lock.yaml --- pnpm-lock.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3f5858a965ed2..15b4cebcd9e9e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -292,8 +292,7 @@ importers: specifier: ^3.0.1 version: 3.0.3 - components/adobe_document_generation_api: - specifiers: {} + components/adobe_document_generation_api: {} components/adobe_pdf_services: dependencies: @@ -10501,8 +10500,7 @@ importers: components/syncro: {} - components/synthflow: - specifiers: {} + components/synthflow: {} components/t2m_url_shortener: {} @@ -31754,6 +31752,8 @@ snapshots: '@putout/operator-filesystem': 5.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3)) '@putout/operator-json': 2.2.0 putout: 36.13.1(eslint@8.57.1)(typescript@5.6.3) + transitivePeerDependencies: + - supports-color '@putout/operator-regexp@1.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3))': dependencies: From d848a3d52693ef8e35ef4c4fa8b000bb55165b93 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Thu, 30 Jan 2025 12:49:07 -0500 Subject: [PATCH 3/3] versions --- components/opsgenie/actions/create-alert/create-alert.mjs | 2 +- .../opsgenie/actions/get-alert-status/get-alert-status.mjs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/opsgenie/actions/create-alert/create-alert.mjs b/components/opsgenie/actions/create-alert/create-alert.mjs index 59f06963bf366..8929af43cacc8 100644 --- a/components/opsgenie/actions/create-alert/create-alert.mjs +++ b/components/opsgenie/actions/create-alert/create-alert.mjs @@ -4,7 +4,7 @@ export default { key: "opsgenie-create-alert", name: "Create Alert", description: "Send a new Alert for processing. [See the documentation](https://www.postman.com/api-evangelist/opsgenie/request/zuj17nj/create-alert)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { app, diff --git a/components/opsgenie/actions/get-alert-status/get-alert-status.mjs b/components/opsgenie/actions/get-alert-status/get-alert-status.mjs index dba3c52e89a90..192bac3cf86c3 100644 --- a/components/opsgenie/actions/get-alert-status/get-alert-status.mjs +++ b/components/opsgenie/actions/get-alert-status/get-alert-status.mjs @@ -4,7 +4,7 @@ export default { key: "opsgenie-get-alert-status", name: "Get Alert Status", description: "Get the status of the alert with the specified ID. [See the documentation](https://www.postman.com/api-evangelist/opsgenie/request/03tcghu/get-request-status-of-alert)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { app,