-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
107 lines (92 loc) · 2.9 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
'use strict';
const GitHubApi = require('github');
const DeployPluginBase = require('ember-cli-deploy-plugin');
module.exports = {
name: 'ember-cli-deploy-github-deployments',
createDeployPlugin(options) {
var DeployPlugin = DeployPluginBase.extend({
name: options.name,
requiredConfig: ['publicURL', 'token', 'username', 'reporname', 'commit'],
willDeploy(context) {
return this.notifyPullRequestOfDeployPending(context);
},
didDeploy(context) {
return this.notifyPullRequestOfDeploySuccess(context);
},
didFail(context) {
return this.notifyPullRequestOfDeployError(context);
},
notifyPullRequestOfDeployError(context) {
let github = new GitHubApi();
github.authenticate({
type: 'oauth',
token: this.readConfig('token'),
});
return new Promise((resolve, reject) => {
github.repos.createStatus({
owner: this.readConfig('username'),
repo: this.readConfig('reporname'),
sha: this.readConfig('commit'),
state: 'error',
description: 'Build failed!',
context: 'ember-cli-deploy',
}, (error, result) => {
if (error) {
reject(error);
} else {
resolve(result);
}
});
});
},
notifyPullRequestOfDeployPending(context) {
let github = new GitHubApi();
github.authenticate({
type: 'oauth',
token: this.readConfig('token'),
});
return new Promise((resolve, reject) => {
github.repos.createStatus({
owner: this.readConfig('username'),
repo: this.readConfig('reporname'),
sha: this.readConfig('commit'),
state: 'pending',
description: 'Building application!',
context: 'ember-cli-deploy',
}, (error, result) => {
if (error) {
reject(error);
} else {
resolve(result);
}
});
});
},
notifyPullRequestOfDeploySuccess(context) {
let github = new GitHubApi();
github.authenticate({
type: 'oauth',
token: this.readConfig('token'),
});
return new Promise((resolve, reject) => {
github.repos.createStatus({
owner: this.readConfig('username'),
repo: this.readConfig('reporname'),
sha: this.readConfig('commit'),
state: 'success',
description: 'Complete build!',
target_url: this.readConfig('publicURL'),
context: 'ember-cli-deploy',
}, (error, result) => {
if (error) {
reject(error);
} else {
resolve(result);
}
});
});
},
});
return new DeployPlugin();
},
};