Skip to content

Commit

Permalink
Trello: Improve/Migrate legacy Trello components
Browse files Browse the repository at this point in the history
  • Loading branch information
jcortes committed Sep 17, 2024
1 parent 81df5b5 commit 4c12cb3
Show file tree
Hide file tree
Showing 57 changed files with 1,640 additions and 1,646 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { ConfigurationError } from "@pipedream/platform";
import fs from "fs";
import FormData from "form-data";
import common from "../common.mjs";

export default {
...common,
key: "trello-add-attachment-to-card",
name: "Add Attachment To Card",
description: "Adds a file attachment on a card. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-attachments-post)",
version: "0.0.1",
type: "action",
props: {
...common.props,
board: {
propDefinition: [
common.props.app,
"board",
],
},
cardId: {
propDefinition: [
common.props.app,
"cards",
(c) => ({
board: c.board,
}),
],
type: "string",
label: "Card",
description: "The ID of the Card to add the Attachment to",
optional: false,
},
name: {
propDefinition: [
common.props.app,
"name",
],
},
url: {
propDefinition: [
common.props.app,
"url",
],
optional: true,
},
mimeType: {
propDefinition: [
common.props.app,
"mimeType",
],
},
setCover: {
type: "boolean",
label: "Set Cover?",
description: "Determines whether to use the new attachment as a cover for the Card",
default: false,
},
file: {
type: "string",
label: "File Path",
description: "The path to the file saved to the `/tmp` directory (e.g. `/tmp/example.pdf`). [See the documentation](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory). If you provide a file path, the **File Attachment URL** field will be ignored.",
optional: true,
},
},
methods: {
...common.methods,
addAttachmentToCard({
cardId, ...args
} = {}) {
return this.app.post({
path: `/cards/${cardId}/attachments`,
...args,
});
},
},
async run({ $ }) {
const {
addAttachmentToCard,
cardId,
name,
url,
mimeType,
setCover,
file,
} = this;
let response;

if (file && !file?.startsWith("/tmp")) {
throw new ConfigurationError("The file path must be in the `/tmp` directory");
}

if (file) {
const data = new FormData();
data.append("file", fs.createReadStream(file));

response = await addAttachmentToCard({
$,
cardId,
params: {
name,
mimeType,
setCover,
},
headers: {
"Content-Type": `multipart/form-data; boundary=${data.getBoundary()}`,
...data.getHeaders(),
},
data,
});

} else {
response = await addAttachmentToCard({
$,
cardId,
params: {
url,
name,
mimeType,
setCover,
},
});
}

$.export("$summary", `Successfully added attachement to card ${cardId}`);
return response;
},
};
94 changes: 56 additions & 38 deletions components/trello/actions/add-checklist/add-checklist.mjs
Original file line number Diff line number Diff line change
@@ -1,68 +1,86 @@
// legacy_hash_id: a_WYieM3
import { axios } from "@pipedream/platform";
import app from "../../trello.app.mjs";

export default {
key: "trello-add-checklist",
name: "Create a Checklist",
description: "Adds a new checklist to a card.",
version: "0.1.3",
description: "Adds a new checklist to a card. [See the documentation](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-checklists-post).",
version: "0.2.0",
type: "action",
props: {
trello: {
type: "app",
app: "trello",
app,
boardId: {
propDefinition: [
app,
"board",
],
},
id: {
cardId: {
type: "string",
label: "Card ID",
description: "The ID of the card.",
optional: false,
propDefinition: [
app,
"cards",
({ boardId }) => ({
board: boardId,
}),
],
},
name: {
type: "string",
label: "Checklist Name",
description: "The name of the checklist.",
optional: true,
},
idChecklistSource: {
type: "string",
description: "The ID of a source checklist to copy into the new one.",
optional: true,
propDefinition: [
app,
"checklist",
({ boardId }) => ({
board: boardId,
}),
],
},
pos: {
type: "string",
label: "Position",
description: "The position of the checklist on the card. One of: top, bottom, or a positive number.",
optional: true,
},
},
methods: {
addChecklist({
cardId, ...args
} = {}) {
return this.app.post({
path: `/cards/${cardId}/checklists`,
...args,
});
},
},
async run({ $ }) {
const oauthSignerUri = this.trello.$auth.oauth_signer_uri;

let id = this.id;
const trelloParams = [
"name",
"idChecklistSource",
"pos",
];
let p = this;

const queryString = trelloParams.filter((param) => p[param]).map((param) => `${param}=${p[param]}`)
.join("&");

const config = {
url: `https://api.trello.com/1/cards/${id}/checklists?${queryString}`,
method: "POST",
data: "",
};
const {
addChecklist,
cardId,
name,
idChecklistSource,
pos,
} = this;

const token = {
key: this.trello.$auth.oauth_access_token,
secret: this.trello.$auth.oauth_refresh_token,
};
const response = await addChecklist({
$,
cardId,
params: {
name,
idChecklistSource,
pos,
},
});

const signConfig = {
token,
oauthSignerUri,
};
$.export("$summary", "Successfully added checklist.");

const resp = await axios($, config, signConfig);
return resp;
return response;
},
};
Loading

0 comments on commit 4c12cb3

Please sign in to comment.