Skip to content

Commit cdee3dc

Browse files
committed
update status messages
1 parent f3ec9fa commit cdee3dc

File tree

5 files changed

+65
-57
lines changed

5 files changed

+65
-57
lines changed

lib/models/apis/pullrequest.js

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,127 +7,139 @@ function PullRequest (githubToken) {
77
this.github = new Github({token: githubToken});
88
}
99

10-
PullRequest.prototype.buildStarted = function (repo, commit, targetUrl, cb) {
10+
PullRequest.prototype.buildStarted = function (pullRequestInfo, targetUrl, cb) {
1111
debug('buildStarted', formatArgs(arguments));
1212
if (process.env.ENABLE_GITHUB_PR_STATUSES !== 'true') {
1313
return cb(null);
1414
}
1515
var payload = {
1616
state: 'pending',
17-
description: 'A build has been started.',
17+
description: 'PR-' + pullRequestInfo.number + ' is building on Runnable.',
1818
// we use url to differentiate between several runnable builds
1919
context: targetUrl,
2020
target_url: targetUrl,
21-
sha: commit
21+
sha: pullRequestInfo.commit
2222
};
23-
this.github.createBuildStatus(repo, payload, cb);
23+
this.github.createBuildStatus(pullRequestInfo.repo, payload, cb);
2424
};
2525

26-
PullRequest.prototype.buildSucceeded = function (repo, commit, targetUrl, cb) {
26+
PullRequest.prototype.buildSucceeded = function (pullRequestInfo, targetUrl, cb) {
2727
debug('buildSucceeded', formatArgs(arguments));
2828
if (process.env.ENABLE_GITHUB_PR_STATUSES !== 'true') {
2929
return cb(null);
3030
}
3131
var payload = {
3232
state: 'success',
33-
description: 'A build has been completed.',
33+
description: 'PR-' + pullRequestInfo.number + ' is ready to run on Runnable.',
3434
// we use url to differentiate between several runnable builds
3535
context: targetUrl,
3636
target_url: targetUrl,
37-
sha: commit
37+
sha: pullRequestInfo.commit
3838
};
39-
this.github.createBuildStatus(repo, payload, cb);
39+
this.github.createBuildStatus(pullRequestInfo.repo, payload, cb);
4040
};
4141

42-
PullRequest.prototype.buildErrored = function (repo, commit, targetUrl, cb) {
42+
PullRequest.prototype.buildErrored = function (pullRequestInfo, targetUrl, cb) {
4343
debug('buildErrored', formatArgs(arguments));
4444
if (process.env.ENABLE_GITHUB_PR_STATUSES !== 'true') {
4545
return cb(null);
4646
}
4747
var payload = {
4848
state: 'error',
49-
description: 'A build has been completed with an error.',
49+
description: 'Select a server to build PR-' + pullRequestInfo.number,
5050
// we use url to differentiate between several runnable builds
5151
context: targetUrl,
52-
target_url: targetUrl
52+
target_url: targetUrl,
53+
sha: pullRequestInfo.commit
5354
};
54-
this.github.createBuildStatus(repo, commit, payload, cb);
55+
this.github.createBuildStatus(pullRequestInfo.repo, payload, cb);
5556
};
5657

57-
PullRequest.prototype.serverSelectionStatus = function (repo, commit, targetUrl, cb) {
58+
PullRequest.prototype.serverSelectionStatus = function (pullRequestInfo, targetUrl, cb) {
5859
debug('buildStarted', formatArgs(arguments));
5960
if (process.env.ENABLE_GITHUB_PR_STATUSES !== 'true') {
6061
return cb(null);
6162
}
6263
var payload = {
6364
state: 'pending',
64-
description: 'Select a server to run this Pull Request',
65+
description: 'PR-' + pullRequestInfo.number + ' is ready to run on Runnable.',
6566
// we use url to differentiate between several runnable builds
6667
context: targetUrl,
6768
target_url: targetUrl,
68-
sha: commit
69+
sha: pullRequestInfo.commit
6970
};
70-
this.github.createBuildStatus(repo, payload, cb);
71+
this.github.createBuildStatus(pullRequestInfo.repo, payload, cb);
7172
};
7273

7374

74-
PullRequest.prototype.createDeployment = function (repo, commit, payload, cb) {
75+
PullRequest.prototype.createDeployment = function (pullRequestInfo, serverName, payload, cb) {
7576
debug('createDeployment', formatArgs(arguments));
7677
if (process.env.ENABLE_GITHUB_PR_STATUSES !== 'true') {
7778
return cb(null);
7879
}
80+
var description = 'Deploying PR-' + pullRequestInfo.number + ' to ' +
81+
serverName + ' on Runnable.';
7982
var query = {
8083
auto_merge: false,
8184
environment: 'runnable',
82-
description: 'Deploying code to the runnable sandbox.',
83-
ref: commit,
85+
description: description,
86+
ref: pullRequestInfo.commit,
8487
payload: JSON.stringify(payload || {}),
8588
required_contexts: [] // we skip check on all `contexts` since we still can deploy
8689
};
87-
this.github.createDeployment(repo, query, cb);
90+
this.github.createDeployment(pullRequestInfo.repo, query, cb);
8891
};
8992

9093

91-
PullRequest.prototype.deploymentStarted = function (repo, deploymentId, targetUrl, cb) {
94+
PullRequest.prototype.deploymentStarted =
95+
function (pullRequestInfo, deploymentId, serverName, targetUrl, cb) {
9296
debug('deploymentStarted', formatArgs(arguments));
9397
if (process.env.ENABLE_GITHUB_PR_STATUSES !== 'true') {
9498
return cb(null);
9599
}
100+
var description = 'Deploying PR-' + pullRequestInfo.number + ' to ' +
101+
serverName + ' on Runnable.';
96102
var payload = {
97103
id: deploymentId,
98104
state: 'pending',
99105
target_url: targetUrl,
100-
description: 'Deployment has been started.'
106+
description: description
101107
};
102-
this.github.createDeploymentStatus(repo, payload, cb);
108+
this.github.createDeploymentStatus(pullRequestInfo.repo, payload, cb);
103109
};
104110

105-
PullRequest.prototype.deploymentSucceeded = function (repo, deploymentId, targetUrl, cb) {
111+
PullRequest.prototype.deploymentSucceeded =
112+
function (pullRequestInfo, deploymentId, serverName, targetUrl, cb) {
106113
debug('deploymentSucceeded', formatArgs(arguments));
107114
if (process.env.ENABLE_GITHUB_PR_STATUSES !== 'true') {
108115
return cb(null);
109116
}
117+
var description = 'Deployed PR-' + pullRequestInfo.number +
118+
' to ' + serverName + ' on Runnable.';
110119
var payload = {
111120
id: deploymentId,
112121
state: 'success',
113122
target_url: targetUrl,
114-
description: 'Deployment has been completed.'
123+
description: description
115124
};
116-
this.github.createDeploymentStatus(repo, payload, cb);
125+
this.github.createDeploymentStatus(pullRequestInfo.repo, payload, cb);
117126
};
118127

119-
PullRequest.prototype.deploymentErrored = function (repo, deploymentId, targetUrl, cb) {
128+
PullRequest.prototype.deploymentErrored =
129+
function (pullRequestInfo, deploymentId, serverName, targetUrl, cb) {
120130
debug('deploymentErrored', formatArgs(arguments));
121131
if (process.env.ENABLE_GITHUB_PR_STATUSES !== 'true') {
122132
return cb(null);
123133
}
134+
var description = 'Failed to deploy PR-' + pullRequestInfo.number +
135+
' to ' + serverName + ' on Runnable.';
124136
var payload = {
125137
id: deploymentId,
126138
state: 'error',
127139
target_url: targetUrl,
128-
description: 'Deployment has been completed with an error.'
140+
description: description
129141
};
130-
this.github.createDeploymentStatus(repo, payload, cb);
142+
this.github.createDeploymentStatus(pullRequestInfo.repo, payload, cb);
131143
};
132144

133145
module.exports = PullRequest;

lib/routes/actions/github.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ function notServersForPullRequest () {
143143
next();
144144
},
145145
pullRequest.create('versionCreator.accounts.github.accessToken'),
146-
pullRequest.model.serverSelectionStatus('githubPullRequest.repo',
147-
'githubPullRequest.commit', 'serverSelectionUrl'),
146+
pullRequest.model.serverSelectionStatus('githubPullRequest', 'serverSelectionUrl'),
148147
mw.res.status(201),
149148
mw.res.json('contextVersionIds')
150149
);
@@ -195,8 +194,7 @@ function followBranch (instancesKey) {
195194
mw.req('creatorGithubId').validate(validations.equalsKeypath('githubPullRequest.creator.id'))
196195
.then(
197196
pullRequest.create('instanceCreator.accounts.github.accessToken'),
198-
pullRequest.model.buildStarted('githubPullRequest.repo',
199-
'githubPullRequest.commit', 'targetUrl')
197+
pullRequest.model.buildStarted('githubPullRequest', 'targetUrl')
200198
),
201199
newContextVersion('contextVersion'), // replaces context version!
202200
flow.try(
@@ -255,8 +253,7 @@ function followBranch (instancesKey) {
255253
validations.equalsKeypath('githubPullRequest.creator.id'))
256254
.then(
257255
pullRequest.create('instanceCreator.accounts.github.accessToken'),
258-
pullRequest.model.buildErrored('githubPullRequest.repo',
259-
'githubPullRequest.commit', 'targetUrl')
256+
pullRequest.model.buildErrored('githubPullRequest', 'targetUrl')
260257
)
261258
)
262259
),
@@ -281,8 +278,7 @@ function followBranch (instancesKey) {
281278
var instanceCreator = infoObject.instanceCreator;
282279
var prData = req.githubPullRequest;
283280
pullRequest.create(instanceCreator.accounts.github.accessToken);
284-
pullRequest.model.buildErrored(prData.repo, prData.commit,
285-
infoObject.targetUrl)(req, res, next);
281+
pullRequest.model.buildErrored(prData, infoObject.targetUrl)(req, res, next);
286282
});
287283
}
288284
}),
@@ -302,18 +298,17 @@ function followBranch (instancesKey) {
302298
mw.req('creatorGithubId').validate(
303299
validations.equalsKeypath('githubPullRequest.creator.id'))
304300
.then(
305-
pullRequest.model.buildSucceeded('githubPullRequest.repo',
306-
'githubPullRequest.commit', 'targetUrl')
301+
pullRequest.model.buildSucceeded('githubPullRequest', 'targetUrl')
307302
),
308303
timers.create(),
309304
timers.model.startTimer('timerId'),
310-
pullRequest.model.createDeployment('githubPullRequest.repo', 'githubPullRequest.commit', {
305+
pullRequest.model.createDeployment('githubPullRequest', 'instance.name', {
311306
instanceId: 'instance._id.toString()',
312307
}),
313308
mw.req().set('deploymentId', 'pullrequestResult.id'),
314309
flow.try(
315-
pullRequest.model.deploymentStarted('githubPullRequest.repo',
316-
'deploymentId', 'targetUrl'),
310+
pullRequest.model.deploymentStarted('githubPullRequest',
311+
'deploymentId', 'instance.name', 'targetUrl'),
317312
// we cannot use pushSessionUser, bc patch requires token
318313
// we must reinstantiate runnable model for each call bc of a bug
319314
runnable.create({}, 'instanceCreator'),
@@ -323,12 +318,12 @@ function followBranch (instancesKey) {
323318
// we must reinstantiate runnable model for each call bc of a bug
324319
runnable.create({}, 'instanceCreator'),
325320
runnable.model.waitForInstanceDeployed('instance.shortHash'),
326-
pullRequest.model.deploymentSucceeded('githubPullRequest.repo',
327-
'deploymentId', 'targetUrl')
321+
pullRequest.model.deploymentSucceeded('githubPullRequest',
322+
'deploymentId', 'instance.name', 'targetUrl')
328323
).catch(
329324
error.logIfErrMw,
330-
pullRequest.model.deploymentErrored('githubPullRequest.repo',
331-
'deploymentId', 'targetUrl')
325+
pullRequest.model.deploymentErrored('githubPullRequest',
326+
'deploymentId', 'instance.name', 'targetUrl')
332327
),
333328
instanceAutoDeployDone()
334329
)

templates/github_pull_request_choose_server.hbs

Lines changed: 0 additions & 1 deletion
This file was deleted.

templates/github_pull_request_server_link.hbs

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/actions-github.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ describe('Github - /actions/github', function () {
184184
it('should set deployment status to error if error happened during instance update', {timeout: 6000},
185185
function (done) {
186186
var baseDeploymentId = 100000;
187-
PullRequest.createDeployment = function (repo, commit, payload, cb) {
187+
PullRequest.createDeployment = function (pullRequest, serverName, payload, cb) {
188188
cb(null, {id: baseDeploymentId});
189189
};
190190

@@ -193,8 +193,9 @@ describe('Github - /actions/github', function () {
193193
cb(Boom.notFound('Instance update failed'));
194194
};
195195

196-
PullRequest.prototype.deploymentErrored = function (repo, deploymentId, targetUrl) {
197-
expect(repo).to.exist();
196+
PullRequest.prototype.deploymentErrored = function (pullRequest, deploymentId, serverName, targetUrl) {
197+
expect(pullRequest).to.exist();
198+
expect(serverName).to.exist();
198199
expect(targetUrl).to.include('https://runnable.io/');
199200
done();
200201
};
@@ -221,7 +222,7 @@ describe('Github - /actions/github', function () {
221222
it('should set deployment status to error if error happened during instance deployment', {timeout: 6000},
222223
function (done) {
223224
var baseDeploymentId = 100000;
224-
PullRequest.createDeployment = function (repo, commit, payload, cb) {
225+
PullRequest.createDeployment = function (pullRequest, serverName, payload, cb) {
225226
cb(null, {id: baseDeploymentId});
226227
};
227228

@@ -230,8 +231,9 @@ describe('Github - /actions/github', function () {
230231
cb(Boom.notFound('Instance deploy failed'));
231232
};
232233

233-
PullRequest.prototype.deploymentErrored = function (repo, deploymentId, targetUrl) {
234-
expect(repo).to.exist();
234+
PullRequest.prototype.deploymentErrored = function (pullRequest, deploymentId, serverName, targetUrl) {
235+
expect(pullRequest).to.exist();
236+
expect(serverName).to.exist();
235237
expect(targetUrl).to.include('https://runnable.io/');
236238
done();
237239
};
@@ -276,7 +278,7 @@ describe('Github - /actions/github', function () {
276278
var spyOnClassMethod = require('function-proxy').spyOnClassMethod;
277279
var baseDeploymentId = 1234567;
278280
spyOnClassMethod(require('models/apis/pullrequest'), 'createDeployment',
279-
function (repo, commit, payload, cb) {
281+
function (pullRequest, serverName, payload, cb) {
280282
baseDeploymentId++;
281283
cb(null, {id: baseDeploymentId});
282284
});
@@ -301,8 +303,9 @@ describe('Github - /actions/github', function () {
301303
}));
302304
});
303305
spyOnClassMethod(require('models/apis/pullrequest'), 'deploymentSucceeded',
304-
function (repo, deploymentId, targetUrl) {
305-
expect(repo).to.exist();
306+
function (pullRequest, deploymentId, serverName, targetUrl) {
307+
expect(pullRequest).to.exist();
308+
expect(serverName).to.exist();
306309
expect([1234568, 1234569]).to.contain(deploymentId);
307310
expect(targetUrl).to.include('https://runnable.io/');
308311
count.next();

0 commit comments

Comments
 (0)