Skip to content

Commit 4c12cb3

Browse files
committed
Trello: Improve/Migrate legacy Trello components
1 parent 81df5b5 commit 4c12cb3

File tree

57 files changed

+1640
-1646
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1640
-1646
lines changed

components/trello/actions/add-attachment-to-card-via-url/add-attachment-to-card-via-url.mjs

Lines changed: 0 additions & 73 deletions
This file was deleted.
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import fs from "fs";
3+
import FormData from "form-data";
4+
import common from "../common.mjs";
5+
6+
export default {
7+
...common,
8+
key: "trello-add-attachment-to-card",
9+
name: "Add Attachment To Card",
10+
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)",
11+
version: "0.0.1",
12+
type: "action",
13+
props: {
14+
...common.props,
15+
board: {
16+
propDefinition: [
17+
common.props.app,
18+
"board",
19+
],
20+
},
21+
cardId: {
22+
propDefinition: [
23+
common.props.app,
24+
"cards",
25+
(c) => ({
26+
board: c.board,
27+
}),
28+
],
29+
type: "string",
30+
label: "Card",
31+
description: "The ID of the Card to add the Attachment to",
32+
optional: false,
33+
},
34+
name: {
35+
propDefinition: [
36+
common.props.app,
37+
"name",
38+
],
39+
},
40+
url: {
41+
propDefinition: [
42+
common.props.app,
43+
"url",
44+
],
45+
optional: true,
46+
},
47+
mimeType: {
48+
propDefinition: [
49+
common.props.app,
50+
"mimeType",
51+
],
52+
},
53+
setCover: {
54+
type: "boolean",
55+
label: "Set Cover?",
56+
description: "Determines whether to use the new attachment as a cover for the Card",
57+
default: false,
58+
},
59+
file: {
60+
type: "string",
61+
label: "File Path",
62+
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.",
63+
optional: true,
64+
},
65+
},
66+
methods: {
67+
...common.methods,
68+
addAttachmentToCard({
69+
cardId, ...args
70+
} = {}) {
71+
return this.app.post({
72+
path: `/cards/${cardId}/attachments`,
73+
...args,
74+
});
75+
},
76+
},
77+
async run({ $ }) {
78+
const {
79+
addAttachmentToCard,
80+
cardId,
81+
name,
82+
url,
83+
mimeType,
84+
setCover,
85+
file,
86+
} = this;
87+
let response;
88+
89+
if (file && !file?.startsWith("/tmp")) {
90+
throw new ConfigurationError("The file path must be in the `/tmp` directory");
91+
}
92+
93+
if (file) {
94+
const data = new FormData();
95+
data.append("file", fs.createReadStream(file));
96+
97+
response = await addAttachmentToCard({
98+
$,
99+
cardId,
100+
params: {
101+
name,
102+
mimeType,
103+
setCover,
104+
},
105+
headers: {
106+
"Content-Type": `multipart/form-data; boundary=${data.getBoundary()}`,
107+
...data.getHeaders(),
108+
},
109+
data,
110+
});
111+
112+
} else {
113+
response = await addAttachmentToCard({
114+
$,
115+
cardId,
116+
params: {
117+
url,
118+
name,
119+
mimeType,
120+
setCover,
121+
},
122+
});
123+
}
124+
125+
$.export("$summary", `Successfully added attachement to card ${cardId}`);
126+
return response;
127+
},
128+
};
Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,86 @@
1-
// legacy_hash_id: a_WYieM3
2-
import { axios } from "@pipedream/platform";
1+
import app from "../../trello.app.mjs";
32

43
export default {
54
key: "trello-add-checklist",
65
name: "Create a Checklist",
7-
description: "Adds a new checklist to a card.",
8-
version: "0.1.3",
6+
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).",
7+
version: "0.2.0",
98
type: "action",
109
props: {
11-
trello: {
12-
type: "app",
13-
app: "trello",
10+
app,
11+
boardId: {
12+
propDefinition: [
13+
app,
14+
"board",
15+
],
1416
},
15-
id: {
17+
cardId: {
1618
type: "string",
19+
label: "Card ID",
1720
description: "The ID of the card.",
21+
optional: false,
22+
propDefinition: [
23+
app,
24+
"cards",
25+
({ boardId }) => ({
26+
board: boardId,
27+
}),
28+
],
1829
},
1930
name: {
2031
type: "string",
32+
label: "Checklist Name",
2133
description: "The name of the checklist.",
2234
optional: true,
2335
},
2436
idChecklistSource: {
25-
type: "string",
26-
description: "The ID of a source checklist to copy into the new one.",
2737
optional: true,
38+
propDefinition: [
39+
app,
40+
"checklist",
41+
({ boardId }) => ({
42+
board: boardId,
43+
}),
44+
],
2845
},
2946
pos: {
3047
type: "string",
48+
label: "Position",
3149
description: "The position of the checklist on the card. One of: top, bottom, or a positive number.",
3250
optional: true,
3351
},
3452
},
53+
methods: {
54+
addChecklist({
55+
cardId, ...args
56+
} = {}) {
57+
return this.app.post({
58+
path: `/cards/${cardId}/checklists`,
59+
...args,
60+
});
61+
},
62+
},
3563
async run({ $ }) {
36-
const oauthSignerUri = this.trello.$auth.oauth_signer_uri;
37-
38-
let id = this.id;
39-
const trelloParams = [
40-
"name",
41-
"idChecklistSource",
42-
"pos",
43-
];
44-
let p = this;
45-
46-
const queryString = trelloParams.filter((param) => p[param]).map((param) => `${param}=${p[param]}`)
47-
.join("&");
48-
49-
const config = {
50-
url: `https://api.trello.com/1/cards/${id}/checklists?${queryString}`,
51-
method: "POST",
52-
data: "",
53-
};
64+
const {
65+
addChecklist,
66+
cardId,
67+
name,
68+
idChecklistSource,
69+
pos,
70+
} = this;
5471

55-
const token = {
56-
key: this.trello.$auth.oauth_access_token,
57-
secret: this.trello.$auth.oauth_refresh_token,
58-
};
72+
const response = await addChecklist({
73+
$,
74+
cardId,
75+
params: {
76+
name,
77+
idChecklistSource,
78+
pos,
79+
},
80+
});
5981

60-
const signConfig = {
61-
token,
62-
oauthSignerUri,
63-
};
82+
$.export("$summary", "Successfully added checklist.");
6483

65-
const resp = await axios($, config, signConfig);
66-
return resp;
84+
return response;
6785
},
6886
};

0 commit comments

Comments
 (0)