Skip to content

Commit cf6810a

Browse files
committed
Trello: Improve/Migrate legacy Trello components
1 parent a407a12 commit cf6810a

File tree

57 files changed

+1760
-1693
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

+1760
-1693
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: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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+
},
46+
mimeType: {
47+
propDefinition: [
48+
common.props.app,
49+
"mimeType",
50+
],
51+
},
52+
file: {
53+
propDefinition: [
54+
common.props.app,
55+
"file",
56+
],
57+
},
58+
setCover: {
59+
type: "boolean",
60+
label: "Set Cover?",
61+
description: "Determines whether to use the new attachment as a cover for the Card",
62+
default: false,
63+
},
64+
},
65+
methods: {
66+
...common.methods,
67+
addAttachmentToCard({
68+
cardId, ...args
69+
} = {}) {
70+
return this.app.post({
71+
path: `/cards/${cardId}/attachments`,
72+
...args,
73+
});
74+
},
75+
},
76+
async run({ $ }) {
77+
const {
78+
addAttachmentToCard,
79+
cardId,
80+
name,
81+
url,
82+
mimeType,
83+
setCover,
84+
file,
85+
} = this;
86+
87+
let response;
88+
const params = {
89+
name,
90+
mimeType,
91+
setCover,
92+
};
93+
94+
if (file && !file?.startsWith("/tmp")) {
95+
throw new ConfigurationError("The file path must be in the `/tmp` directory");
96+
}
97+
98+
if (file) {
99+
const form = new FormData();
100+
form.append("file", fs.createReadStream(file));
101+
102+
response = await addAttachmentToCard({
103+
$,
104+
cardId,
105+
params,
106+
headers: form.getHeaders(),
107+
data: form,
108+
});
109+
110+
} else {
111+
response = await addAttachmentToCard({
112+
$,
113+
cardId,
114+
params: {
115+
...params,
116+
url,
117+
},
118+
});
119+
}
120+
121+
$.export("$summary", `Successfully added attachement to card ${cardId}`);
122+
return response;
123+
},
124+
};
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)