fix def is 0 or false error

This commit is contained in:
lizheming
2019-01-13 21:11:25 +08:00
parent 1fc4bd1275
commit a0ef9d4b26
2 changed files with 7 additions and 6 deletions
+5 -4
View File
@@ -2,20 +2,20 @@ const process = require('process');
const render = require('drone-render');
const request = require('request-promise-native');
function log(text) {
function log(...args) {
const debug = process.env.PLUGIN_DEBUG;
if (!debug) {
return;
}
// eslint-disable-next-line
console.log(text);
console.log(...args);
}
function configParser(configs) {
const ret = {};
for (const configName in configs) {
const { env, def } = configs[configName];
if (def) {
if (def !== undefined) {
ret[configName] = typeof def === 'function' ? def() : def;
}
env.split(/\s*,\s*/).some(envar => {
@@ -69,9 +69,10 @@ function sendMsgFromWork({
async function exec({ corpid, corp_secret, ...config }) {
try {
log('send notification to wechat start!');
log('config parse end, config except corpid and corp_secret:', config);
const access_token = await getAccessToken(corpid, corp_secret);
log('access_token request success!');
log('http request data:', config);
const resp = await sendMsgFromWork({ ...config, access_token });
log('send msg success, and http response content is:');
log(resp);
+2 -2
View File
@@ -65,7 +65,7 @@ test('send wechat with corp id', async t => {
PLUGIN_AGENT_ID: 1122
}
});
mock('request-promise-native', obj => {
mock('request-promise-native', function(obj) {
if (obj.url.includes('gettoken')) {
return Promise.resolve({ access_token: 1234 });
}
@@ -94,7 +94,7 @@ test('send wechat with corp id', async t => {
});
}
});
mock.reRequire('./index');
await mock.reRequire('./index');
mock.stopAll();
});