Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8bbcfda

Browse files
committed
allow travis to comment with deployed url after build succeded
1 parent 39581c7 commit 8bbcfda

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

scripts/now.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /usr/bin/env node
2-
2+
/* eslint-disable camelcase */
33
const github = require('octonode');
44
const normalizeUrl = require('normalize-url');
55
const spawn = require('cross-spawn');
@@ -26,6 +26,14 @@ if (!nowToken) {
2626

2727
const client = github.client(githubToken);
2828
const ghRepo = client.repo(process.env.TRAVIS_REPO_SLUG);
29+
let ghPR;
30+
31+
if (process.env.TRAVIS_PULL_REQUEST) {
32+
ghPR = client.pr(
33+
process.env.TRAVIS_REPO_SLUG,
34+
process.env.TRAVIS_PULL_REQUEST,
35+
);
36+
}
2937

3038
function noop() {}
3139

@@ -46,7 +54,15 @@ function deploy(context, sha) {
4654
noop,
4755
);
4856

49-
const args = ['--token', nowToken, '--no-clipboard'];
57+
const args = [
58+
'--token',
59+
nowToken,
60+
'--team',
61+
'coderplex',
62+
'--no-clipboard',
63+
'-n',
64+
'coderplex-app',
65+
];
5066
const alias = context === 'production' && process.env.NOW_ALIAS;
5167
let stdout = '';
5268

@@ -84,18 +100,34 @@ function deploy(context, sha) {
84100
});
85101

86102
child.on('close', () => {
87-
const targetUrl = alias || getUrl(stdout);
103+
const target_url = alias || getUrl(stdout);
88104

89105
ghRepo.status(
90106
sha,
91107
{
92108
context,
93-
targetUrl,
109+
target_url,
94110
state: 'success',
95111
description: `Δ Now ${context} deployment complete`,
96112
},
97113
noop,
98114
);
115+
if (ghPR) {
116+
const comment = `
117+
### Δ Now ${context} deployment complete
118+
- ✅ **Build Passed**
119+
- 🚀 **Staging URL** : ${target_url}
120+
---
121+
Note: **This is autogenerated through Travis build**
122+
`;
123+
ghPR.createComment(
124+
{
125+
body: comment,
126+
commit_id: process.env.TRAVIS_COMMIT,
127+
},
128+
noop,
129+
);
130+
}
99131
});
100132
}
101133

0 commit comments

Comments
 (0)