-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
244 lines (215 loc) · 6.6 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
const NO_PIPELINE_PROJECTS = ["app-qaft", "iwe-app-dsl", "functionnal-tests", "k8s-deploy", "iwe", "app-admin"];
const IWE_LOGO =
"https://iwecloud.com/wp-content/uploads/2020/06/logo-application-web-outil-collaboration-low-code-parcours-processus-client-digital.svg";
TrelloPowerUp.initialize({
"card-buttons": function (t, options) {
return t
.card("customFieldItems", "id", "members", "url", "name", "labels")
.then(async function ({
customFieldItems,
id,
members,
url,
name: title,
labels
}) {
const platformBranchName = getCustomFieldValue(
customFieldItems,
"66a7b730211062b563b92f53"
);
const deliveryBranchName = getCustomFieldValue(
customFieldItems,
"6784dcdd88cdd86ab7ab309a"
);
const branchName = platformBranchName || deliveryBranchName;
if (!branchName) {
return null;
}
const platformMyTickets = getCustomFieldValue(customFieldItems, '6593ebbb699e895d318adbfa')?.replace(' ', '') ?? '';
const deliveryMyTickets = getCustomFieldValue(customFieldItems, '678f661e6b95b0f4b69998c7')?.replace(' ', '') ?? '';
const myTickets = platformMyTickets || deliveryMyTickets;
const isBugfix = labels.some((label) => label.name.includes('Bug') || label.name.includes('HotFix'));
const buttons = await Promise.all([
generateBranchNameButton(branchName, t),
generateCreateMergeRequestsButton(
branchName,
id,
members[0].fullName,
url,
title
),
generatePatchedVersionsButton(branchName),
generateLaunchPipelinesButton(branchName),
generateReleaseDocumentButton(branchName, id, title, isBugfix, myTickets)
]);
return buttons.filter(Boolean);
});
},
"card-detail-badges": function (t, options) {
return t
.card("customFieldItems")
.then(async function ({ customFieldItems }) {
const platformBranchName = getCustomFieldValue(
customFieldItems,
"66a7b730211062b563b92f53"
);
const deliveryBranchName = getCustomFieldValue(
customFieldItems,
"6784dcdd88cdd86ab7ab309a"
);
const branchName = platformBranchName || deliveryBranchName;
if (!branchName) {
return null;
}
const gitlabAndJenkinsBadges = await generateGitlabAndJenkinsBadges(branchName);
return gitlabAndJenkinsBadges.map((badge) => ({ title: badge.title, text: badge.text, color: badge.color, ...(badge.url ? {
callback: (t) => {
window
.open(
badge.url,
"_blank"
)
.focus();
}} : {})}));
});
},
});
// Helper function to get custom field value
function getCustomFieldValue(customFieldItems, customFieldId) {
const field = customFieldItems.find(
(item) => item.idCustomField === customFieldId
);
return field ? field.value.text : null;
}
// Helper function to generate release document button
async function generateReleaseDocumentButton(
branchName,
id,
title,
isBugfix,
myTickets) {
const params = new URLSearchParams({
branchName,
cardId: id,
title,
isBugfix,
myTickets
});
const endpoint = sanitize(
`https://n8n.tools.i-we.io/webhook/0cc6fe98-a97e-4b2e-a42d-50c9ceee6d13?${params.toString()}`
);
return {
icon: IWE_LOGO,
text: "iWE - Release doc",
callback: async function (t) {
await fetch(endpoint, { method: "POST" });
return t.alert({
message: "Release document has been generated and attached !",
});
},
};
}
// Helper function to generate Branch Name button
async function generateBranchNameButton(branchName) {
return {
icon: IWE_LOGO,
text: "iWE - Branche",
callback: (t) => {
window
.open(
sanitize(
`https://i-we.github.io/trello-powerup/copy-and-close.html?value=${branchName}`
),
"_blank"
)
.focus();
return t.alert({
message: "Branch name has been copied to your clipboard!",
});
},
};
}
// Helper function to generate GitLab badges
async function generateGitlabAndJenkinsBadges(branchName) {
const params = new URLSearchParams({
branch: branchName,
});
const response = await fetch(`https://n8n.tools.i-we.io/webhook/9d86d521-93c9-4e2f-90b5-7e4187c2cc9c?${params.toString()}`);
const badges = await response.json();
return badges;
}
// Helper function to generate patched versions button
async function generatePatchedVersionsButton(branchName) {
const params = new URLSearchParams({
branch: branchName,
});
const response = await fetch(
sanitize(
`https://n8n.tools.i-we.io/webhook/b9ff3b81-0713-480a-96ed-ccd8fedc3c64?${params.toString()}`
)
);
const {patchedVersions} = await response.json();
return {
icon: IWE_LOGO,
text: 'iWE - Patched Versions',
callback: (t) => {
window
.open(
sanitize(
`https://i-we.github.io/trello-powerup/copy-and-close.html?value=${patchedVersions}`
),
"_blank"
)
.focus();
return t.alert({
message: "Patched versions have been copied to your clipboard!",
});
}
}
}
async function generateCreateMergeRequestsButton(
branchName,
id,
userFullName,
url,
title
) {
const params = new URLSearchParams({
branch: branchName,
title,
cardId: id,
trelloUserFullName: userFullName,
url,
});
const endpoint = sanitize(
`https://n8n.tools.i-we.io/webhook/c35dfd4a-f501-4435-83f7-81b2040da473?${params.toString()}`
);
return {
icon: IWE_LOGO,
text: "iWE - Merge Requests",
callback: async function (t) {
await fetch(endpoint, { method: "POST" });
return t.alert({
message: "Merge requests are being created on GitLab...",
});
},
};
}
function sanitize(str) {
return str.replace(/%E2%80%8C/g, "").trim();
}
async function generateLaunchPipelinesButton(branchName) {
const params = new URLSearchParams({branch: branchName});
const response = await fetch(`https://n8n.tools.i-we.io/webhook/92beefb2-760b-4a3a-837d-5788a2c340e7?${params.toString()}`);
const repositories = await response.json();
return {
icon: IWE_LOGO,
text: "iWE - Jenkins",
callback: function (t) {
return t.popup({
title: "iWE - Jenkins",
url: `jenkins.html?branch=${branchName}&repositories=${repositories.map((item) => item.repository).join(',')}`,
});
},
};
}