Skip to content
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

[FEATURE] Trello: Improve/Migrate legacy Trello components #13970

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
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",
],
},
mimeType: {
propDefinition: [
common.props.app,
"mimeType",
],
},
file: {
propDefinition: [
common.props.app,
"file",
],
},
setCover: {
type: "boolean",
label: "Set Cover?",
description: "Determines whether to use the new attachment as a cover for the Card",
default: false,
},
},
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;
const params = {
name,
mimeType,
setCover,
};

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

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

response = await addAttachmentToCard({
$,
cardId,
params,
headers: form.getHeaders(),
data: form,
});

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

$.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
Loading