@deskpro/apps-ci-tools
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -5,4 +5,7 @@ { | ||
}, | ||
"scripts": { | ||
"version": "version-changelog CHANGELOG.md && changelog-verify CHANGELOG.md && git add CHANGELOG.md" | ||
}, | ||
"name": "@deskpro/apps-ci-tools", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "various command line tools used during the build process by deskpro apps", | ||
@@ -17,7 +20,12 @@ "main": "src/dpbuild.js", | ||
"commander": "^2.18.0", | ||
"https": "^1.0.0" | ||
"https": "^1.0.0", | ||
"node-fetch": "^2.2.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"devDependencies": { | ||
"changelog-verify": "^1.1.0", | ||
"version-changelog": "^3.1.0" | ||
} | ||
} |
"use strict"; | ||
const program = require("commander"); | ||
const https = require("https"); | ||
const fetch = require("node-fetch"); | ||
const utils = require("./utils"); | ||
@@ -9,5 +10,4 @@ /** | ||
* @param {{}} opts | ||
* @param {function} done | ||
*/ | ||
function githubPRComment(travisEnv, opts, done) | ||
function githubPRComment(travisEnv, opts) | ||
{ | ||
@@ -20,48 +20,22 @@ if ( travisEnv.TRAVIS_PULL_REQUEST === "false" ) { | ||
if (! travisEnv.ARTIFACTS_BUCKET) { | ||
console.log('skip adding artifact download url.is artifact uploading to s3 turned on in .travis.yml ?'); | ||
console.log('skip adding artifact download url. is artifact uploading to s3 turned on in .travis.yml ?'); | ||
return ; | ||
} | ||
const requestBody = JSON.stringify({ | ||
body: `TRAVIS-CI: download build from https://s3.amazonaws.com/${travisEnv.ARTIFACTS_BUCKET}${opts.s3TargetPath}/dist/app.zip` | ||
}); | ||
const url = `https://api.github.com/repos/${travisEnv.TRAVIS_REPO_SLUG}/issues/${travisEnv.TRAVIS_PULL_REQUEST}/comments`; | ||
const comment = `TRAVIS-CI: download build from https://s3.amazonaws.com/${travisEnv.ARTIFACTS_BUCKET}${opts.s3TargetPath}/dist/app.zip` | ||
const requestOptions = { | ||
hostname: "api.github.com", | ||
return fetch(url, { | ||
method: "POST", | ||
path: `/repos/${travisEnv.TRAVIS_REPO_SLUG}/issues/${travisEnv.TRAVIS_PULL_REQUEST}/comments`, | ||
headers: { | ||
'Content-Length': Buffer.byteLength(requestBody), | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
'Authorization': `token ${travisEnv.GITHUB_TOKEN}`, | ||
'User-Agent': travisEnv.TRAVIS_REPO_SLUG | ||
} | ||
}; | ||
}, | ||
body: comment | ||
}).then(function (response) { | ||
const request = https.request(requestOptions, (res) => { | ||
res.setEncoding('utf8'); | ||
if (opts.debug) { | ||
console.log('statusCode:', res.statusCode); | ||
console.log('headers:', res.headers); | ||
} | ||
// need to add a data event listener so that the end event is triggered | ||
res.on('data', (chunk) => { | ||
if (opts.debug) { | ||
console.log(`BODY: ${chunk}`); | ||
} | ||
}); | ||
res.on('end', () => { | ||
done(); | ||
}); | ||
response.ok ? console.log(`PR COMMENT SUCCESS`) : console.log(`PR COMMENT FAILURE`); | ||
return response.text().then(console.log); | ||
}); | ||
request.on('error', (e) => { | ||
console.error(e); | ||
done(); | ||
}); | ||
request.write(requestBody); | ||
request.end(); | ||
} | ||
@@ -73,5 +47,4 @@ | ||
* @param {Command} cmd | ||
* @param {function} done | ||
*/ | ||
function action(subcommand, path, cmd, done) | ||
function action(subcommand, path, cmd) | ||
{ | ||
@@ -82,3 +55,3 @@ if (subcommand === 'pr-comment') { | ||
console.error('ERROR: missing required argument: --s3-target-path'); | ||
process.exit(1); | ||
return Promise.reject('ERROR: missing required argument: --s3-target-path') | ||
} | ||
@@ -88,8 +61,7 @@ | ||
const opts = { debug: !!cmd.debug, s3TargetPath: cmd.s3target }; | ||
githubPRComment(process.env, opts, done); | ||
return ; | ||
return githubPRComment(process.env, opts); | ||
} | ||
console.warn('skip adding comment on pull request. no vcs configuration detected'); | ||
done(); | ||
return Promise.resolve('skip adding comment on pull request. no vcs configuration detected') | ||
} | ||
@@ -106,3 +78,3 @@ | ||
.option("-d, --debug [debug]", "turn on debugging") | ||
.action(action) | ||
.action(utils.createAsyncAction(action)) | ||
.parse(process.argv); |
@@ -7,3 +7,3 @@ #!/usr/bin/env node | ||
.version("0.1.0", "-V, --version") | ||
.command("travis <path>", "process a travis build step") | ||
.command("travis <subcommand> <path>", "process a travis build step") | ||
.parse(process.argv); |
function createAsyncAction(action) | ||
{ | ||
return async function () { | ||
const results = await action(); | ||
return results; | ||
const args = [].slice.call(arguments); | ||
return await action.apply(null, args); | ||
} | ||
@@ -7,0 +7,0 @@ } |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
16683
8
4
2
78
+ Addednode-fetch@^2.2.0
+ Addednode-fetch@2.7.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)