This repository has been archived by the owner on Apr 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.js
136 lines (107 loc) · 3.77 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
/* jshint node: true */
'use strict';
var RSVP = require('rsvp');
var DeployPluginBase = require('ember-cli-deploy-plugin');
var Notify = require('./lib/notify');
var Service = require('./lib/service');
var _ = require('lodash');
var merge = _.merge;
var pick = _.pick;
var intersection = _.intersection;
var forIn = _.forIn;
function notificationHook(hookName) {
return function(context) {
var preConfig = this.readConfig('configuredServices');
var userConfig = this.readConfig('services');
var promises = [];
for (var key in userConfig) {
var defaults = preConfig[key] || {};
var user = userConfig[key] || {};
var hook = userConfig[key][hookName] || {};
var service = new Service({
defaults: defaults,
user: user,
hook: hook
});
if (service.serviceOptions[hookName]) {
var notify = new Notify({
plugin: this
});
var opts = service.buildServiceCall(context);
promises.push(notify.send(key, opts));
}
}
return RSVP.all(promises);
}
}
module.exports = {
name: require('./package').name,
createDeployPlugin: function(options) {
var DeployPlugin = DeployPluginBase.extend({
name: options.name,
defaultConfig: {
configuredServices: function(context) {
return {
bugsnag: {
url: 'http://notify.bugsnag.com/deploy',
method: 'POST',
headers: {},
body: function() {
var apiKey = this.apiKey;
if (!apiKey) { return; }
return {
apiKey: this.apiKey,
releaseStage: process.env.DEPLOY_TARGET
}
}
},
slack: {
url: function() {
return this.webhookURL;
},
method: 'POST',
headers: {}
}
}
},
httpClient: function(context) {
return context.notifyHTTPClient;
}
},
setup: function(context) {
var services = this.readConfig('services');
var hooks = [
'willDeploy', 'willBuild', 'build', 'didBuild', 'willPrepare', 'prepare',
'didPrepare', 'willUpload', 'upload', 'didUpload', 'willActivate',
'activate', 'didActivate', 'didDeploy', 'teardown', 'fetchRevisions',
'displayRevisions', 'didFail'
];
var servicesWithNoHooksConfigured = pick(services, function(service) {
return _.intersection(Object.keys(service), hooks).length === 0;
});
_.forIn(servicesWithNoHooksConfigured, function(value, key) {
this.log('Warning! '+key+' - Service configuration found but no hook specified in deploy configuration. Service will not be notified.', { color: 'yellow' });
}, this);
},
willDeploy: notificationHook('willDeploy'),
willBuild: notificationHook('willBuild'),
build: notificationHook('build'),
didBuild: notificationHook('didBuild'),
willPrepare: notificationHook('willPrepare'),
prepare: notificationHook('prepare'),
didPrepare: notificationHook('didPrepare'),
willUpload: notificationHook('willUpload'),
upload: notificationHook('upload'),
didUpload: notificationHook('didUpload'),
willActivate: notificationHook('willActivate'),
activate: notificationHook('activate'),
didActivate: notificationHook('didActivate'),
didDeploy: notificationHook('didDeploy'),
teardown: notificationHook('teardown'),
fetchRevisions: notificationHook('fetchRevisions'),
displayRevisions: notificationHook('displayRevisions'),
didFail: notificationHook('didFail')
});
return new DeployPlugin();
}
};