Skip to content

Commit 8102037

Browse files
authored
Merge pull request #21 from bkono/feature/codedeploy
Adding CodeDeploy parser
2 parents b7abf44 + b98ca05 commit 8102037

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

build/release.zip

963 Bytes
Binary file not shown.

src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function processIncoming(event) {
1313
require("./parsers/aws-health"),
1414
require("./parsers/inspector"),
1515
require("./parsers/codebuild"),
16+
require("./parsers/codedeploy"),
1617
require("./parsers/ses-received"),
1718
require("./parsers/codecommit/pullrequest"),
1819
require("./parsers/codecommit/repository"),

src/parsers/codedeploy.js

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
"use strict";
2+
3+
const BbPromise = require("bluebird"),
4+
_ = require("lodash"),
5+
Slack = require("../slack");
6+
7+
class CodeDeployParser {
8+
9+
parse(event) {
10+
return BbPromise.try(() => _.isObject(event) ? event : JSON.parse(event))
11+
.catch(_.noop) // ignore JSON errors
12+
.then(event => {
13+
if (_.get(event, "source") !== "aws.codedeploy") {
14+
return BbPromise.resolve(false);
15+
}
16+
17+
const time = new Date(_.get(event, "time"));
18+
const deployState = _.get(event, "detail.state");
19+
const deploymentGroup = _.get(event, "detail.deploymentGroup");
20+
const deploymentId = _.get(event, "detail.deploymentId");
21+
const app = _.get(event, "detail.application");
22+
const statusUrl = `https://console.aws.amazon.com/codedeploy/home?region=${event.region}#/deployments/${deploymentId}`;
23+
const fields = [];
24+
25+
let color = Slack.COLORS.neutral;
26+
const baseTitle = `CodeDeploy Application ${app}`;
27+
let title = baseTitle;
28+
if (deployState === "SUCCESS") {
29+
title = `<${statusUrl}|${baseTitle}> has finished`;
30+
color = Slack.COLORS.ok;
31+
}
32+
else if (deployState === "STOP") {
33+
title = `<${statusUrl}|${baseTitle}> was stopped`;
34+
color = Slack.COLORS.warning;
35+
}
36+
else if (deployState === "FAILURE") {
37+
title = `<${statusUrl}|${baseTitle}> has failed`;
38+
color = Slack.COLORS.critical;
39+
}
40+
else if (deployState === "START") {
41+
title = `<${statusUrl}|${baseTitle}> has started deploying`;
42+
}
43+
44+
if (deployState) {
45+
fields.push({
46+
title: "Status",
47+
value: deployState,
48+
short: true
49+
});
50+
}
51+
52+
fields.push({
53+
title: "DeploymentGroup",
54+
value: `${deploymentGroup}`,
55+
short: true
56+
});
57+
58+
const slackMessage = {
59+
attachments: [{
60+
author_name: "AWS CodeDeploy Notification",
61+
fallback: `${baseTitle} ${deployState}`,
62+
color: color,
63+
title: title,
64+
fields: fields,
65+
mrkdwn_in: [ "title", "text" ],
66+
ts: Slack.toEpochTime(time)
67+
}]
68+
};
69+
return BbPromise.resolve(slackMessage);
70+
});
71+
}
72+
}
73+
74+
module.exports = CodeDeployParser;

0 commit comments

Comments
 (0)