forked from mobilecare/codebuild-sns-chat-webhook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
391 lines (362 loc) · 21.8 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
var https = require('https');
var util = require('util');
var moment = require('moment.js');
function generateCardForCodeBuild(json) {
var time = moment(json.tim).format('YYYY-MM-DDTHH:mm:ssZ');
var buildProjectName = json.detail['project-name'];
var buildProjectUrl = `https://console.aws.amazon.com/codesuite/codebuild/projects/${buildProjectName}`;
var buildId = json.detail['build-id'];
buildId = buildId.slice(buildId.lastIndexOf('/') + 1);
var buildDetailsUrl = `${buildProjectUrl}/details?region=${json.region}`;
var buildUrl = `${buildProjectUrl}/build/${buildId}?region=${json.region}`;
var buildState = json.detail['build-status'];
var style = 'default';
if(buildState == 'SUCCEEDED') {
style = 'good';
} else if(buildState == 'FAILED') {
style = 'attention';
}
return {
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"contentUrl": null,
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.5",
"body": [
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": "CodeBuild: Build Stage Changed",
"weight": "bolder",
"size": "medium"
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "Image",
"url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAEE5JREFUeJztnHl4VEW6h9863enOCiEkgRDZVwVRHJ9BkAHlAoK4sKh3cB11dAbEDTSCikrggjo4cAXuqMPgctVRXAZEkU2UQfF60ZlRERGQgJIFEkIgSXc66e6aP7rTfbbuPicEjEo9D09TnTrfV997frWcquojLpi4QyIEACL8aZoXACL8p9h5RAI7TbErRLP5RiS2Y/Qd266ClCAlADL8aZqXoc/QV+E8xjwygR0zuyZ2NHkpE5ex6NtKDEbfse0q0UAsBIsFhz8ziIo2kFNKtAtRMQZySol2ICrmgZxSolWISkzjp5RoCaISP5BTSkwE0dgHNgUiFhz+RCGa94FNgfgzVWLsPrApELEQ7E8MooKtQE4pUZ93SgkCGXrGk6FPKWXoWU+XX/JfnenbOxV1+vTzWgrmFRuuCTkQCCFBChDGPFIgMfdlmsfcjiaPBEGz+EZKJPHtKBGyFtSghwfQr0/Kz1qJTiRRsgmUCBAISEZc9TUul8K6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571m6sYOzonGgFYqxI9+mZypY153DSk1SNzif/eJu2zLhL2vPw/b1QFMGSp/ax/IUDqj4sWmG177IyH4caO/6TmAIByY7d3sZK2VKisQ+0o0R1kpLGKc64S/O49+7uCAGLlhbx6uulka2LaHGjr+oaPxOu/Vy775Fgn0MINPsiketi5ROV0c8TEyjR2g+u496RCBKQkgmX51EwrQdCwMLFe3n1tRLVNUaIx+fbfIpzXH2iqm+0okTFcgViGSNa9JpJp1EwrQcACxbtYcUbJSbXYLTdEiGGbSaCaOsH1+aBhNL113Tk9indCAYlc+d/wxt/KzV1GAX4I4BIHF+NCrRdARMgqakObpscgjd77k7eebcsehfjNvkfAcQESrT9g+tYj17BoKRw7k7Wrj+ocmYSLGpz9iEmalKRGKzatarEGL7NV6TtQAzDm/HAV7y7rswkMH2wEYRGiLLpgcTMn2CIsY92ICMrIDGPdoTtKorg8fk2fzcnMZ8ekPhUGDLxNKNJB6UsnEjT+7b1g2v9Hamr87Pzm2p74IDPvzhq9PUjVaIY0H+1bJaJqpUJL+GJbMIyCXyp8lg4VGTbrg3f8Y+3HfcUxyxvQzE/AiUm2JX7gSFiv0mdbIjWjredUmLMMtaPt51SomkZ1WuQWzjEFqpE3WuQWzjEFqhEk9cgt3CILUyJMV6D3MIhtiAlxnkNcguH2EKUmOA1yC0cYgtQooXXILdwiD+wEv8NUMMXeNQ2Dc8AAAAASUVORK5CYII=",
"altText": "CodeBuild",
"size": "medium",
"style": "person"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": buildProjectName,
"weight": "bolder"
},
{
"type": "TextBlock",
"spacing": "none",
"text": "@ {{DATE(" + time + ", SHORT)}} {{TIME(" + time + ")}}",
"isSubtle": true
}
]
}
]
}
]
},
{
"type": "Container",
"style": style,
"items": [
{
"type": "FactSet",
"facts": [
{
"title": "Build ID:",
"value": buildId
},
{
"title": "Status:",
"value": buildState
}
]
}
]
}
],
"actions": [
{
"type": "Action.OpenUrl",
"title": "View Build",
"url": buildUrl
},
{
"type": "Action.OpenUrl",
"title": "View Build Details",
"url": buildDetailsUrl
},
{
"type": "Action.OpenUrl",
"title": "View Project",
"url": buildProjectUrl
}
]
}
}
]
};
};
function generateCardForCodePipeline(json) {
var time = moment(json.tim).format('YYYY-MM-DDTHH:mm:ssZ');
var pipelineName = json.detail.pipeline;
var pipelineUrl = `https://console.aws.amazon.com/codesuite/codepipeline/pipelines/${json.detail.pipeline}/view?region=${json.region}`;
var pipelineExecutionId = json.detail['execution-id'];
var pipelineExecutionUrl = `${pipelineUrl}/executions/${pipelineExecutionId}/timeline?region=${json.region}`
var pipelineExecutionState = json.detail.state;
var style = 'accent';
if(pipelineExecutionState == 'SUCCEEDED') {
style = 'good';
} else if(pipelineExecutionState == 'FAILED') {
style = 'attention';
}
return {
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"contentUrl": null,
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.5",
"body": [
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": "CodePipeline: Execution Stage Changed",
"weight": "bolder",
"size": "medium"
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "Image",
"url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAACmBJREFUeJztnGuQFNUZhp/umdkre+e23Ba5GwpRQFlLCQJKDGjAIga1KmX5JxW1kIoVjJEAFkQQMJQkMRax8sMiVYkpLaVAICFgEbASAgJKWIJcFrkIgV0WWJaZ2Z2Zkx9z65m+ne5tdmdx+8/Umen+vvM+8/Y501+faeWBOXUCRQFASbwathUAJfGReRvFJo6buIriWW4U+zj63OZxVYQAIQAQiVfDtoi/xt9KtNG3ETZxjOIaxMloC2G/j2RuGQ363OZ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HOcYg56ESDxyDnOMQcc6LJY5BzHGIOOdHiMcg5DjFHnGjzGOQch5gDTpR4DHKOQ+xkJ/4flA+C+dLSmDIAAAAASUVORK5CYII=",
"altText": "CodePipeline",
"size": "medium",
"style": "person"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": pipelineName,
"weight": "bolder"
},
{
"type": "TextBlock",
"spacing": "none",
"text": "@ {{DATE(" + time + ", SHORT)}} {{TIME(" + time + ")}}",
"isSubtle": true
}
]
}
]
}
]
},
{
"type": "Container",
"style": style,
"items": [
{
"type": "FactSet",
"facts": [
{
"title": "Execution ID:",
"value": pipelineExecutionId
},
{
"title": "Status:",
"value": pipelineExecutionState
}
]
}
]
}
],
"actions": [
{
"type": "Action.OpenUrl",
"title": "View Execution",
"url": pipelineUrl
},
{
"type": "Action.OpenUrl",
"title": "View Pipeline",
"url": pipelineExecutionUrl
}
]
}
}
]
};
};
function generateCardForCodePipelineApproval(json) {
var expiryDate = moment(json.approval.expires).format('YYYY-MM-DDTHH:mm:ssZ');
var pipelineName = json.approval.pipelineName;
var pipelineUrl = json.consoleLink;
var pipelineStageName = json.approval.stageName;
var pipelineActionName = json.approval.actionName;
var pipelineApprovalLink = json.approval.approvalReviewLink;
return {
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"contentUrl": null,
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.5",
"body": [
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": "CodePipeline: Approval Required",
"weight": "bolder",
"size": "medium"
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "Image",
"url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAACmBJREFUe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5zW2pIdUvzuUzuREwzDfpqTLuFpLp6UyDajUspDUZx3ULEHKKrP1xbQkS7q0OIwr0Quy8nq2OeQUw/dMLhoGw2uCe3Pbsnk7ObkSawn1gSr9qJxdUfrq2cePDzqx3CwM32RV2LzXjn3InKXXdsFFZLw6SXpdksMUu3nSwf82Z5m+O4DnJbL2/zcHbOtTHRKyfaL2/rTIi4H9w7CqLc8rZuJ5ruI7+8rduJhvtoHoOc4xBz1IlZj0HOcYg56ESDxyDnOMQcc6LJY5BzHGIOOdHiMcg5DjFHnGjzGOQch5gDTpR4DHKOQ+xkJ/4flA+C+dLSmDIAAAAASUVORK5CYII=",
"altText": "CodePipeline",
"size": "medium",
"style": "person"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": pipelineName,
"weight": "bolder"
},
{
"type": "TextBlock",
"spacing": "none",
"text": "Expires {{DATE(" + expiryDate + ", SHORT)}} {{TIME(" + expiryDate + ")}}",
"isSubtle": true
}
]
}
]
}
]
},
{
"type": "Container",
"style": "default",
"items": [
{
"type": "FactSet",
"facts": [
{
"title": "Stage:",
"value": pipelineStageName
},
{
"title": "Action:",
"value": pipelineActionName
}
]
}
]
}
],
"actions": [
{
"type": "Action.OpenUrl",
"title": "Approve",
"tooltip": "Please click here to approve or refuse.",
"url": pipelineApprovalLink
},
{
"type": "Action.OpenUrl",
"title": "View Pipeline",
"url": pipelineUrl
}
]
}
}
]
};
};
exports.handler = function(event, context) {
console.log(JSON.stringify(event, null, 2));
console.log('From SNS:', event.Records[0].Sns.Message);
var message = event.Records[0].Sns.Message;
var jsonMessage = JSON.parse(message);
var card;
if(message.includes('approval')) {
card = generateCardForCodePipelineApproval(jsonMessage);
} else {
if(jsonMessage.source.includes('aws.codepipeline')) {
card = generateCardForCodePipeline(jsonMessage);
}
else {
card = generateCardForCodeBuild(jsonMessage);
}
}
var cardJson = JSON.stringify(card);
console.log(cardJson);
var options = {
method: 'POST',
hostname: 'itipsorg.webhook.office.com',
port: 443,
path: process.env.CHAT_API_PATH
};
var req = https.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', (d) => {
console.log(d);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.write(cardJson);
req.end();
};