From cde832e59a5473ee0810c1e2a6f7a54ab46a0d5f Mon Sep 17 00:00:00 2001 From: Matt Ball Date: Fri, 8 Oct 2021 12:00:35 +0100 Subject: [PATCH] readd funcs --- dist/index.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++- index.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++- package-lock.json | 2 +- package.json | 2 +- 4 files changed, 118 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 78963419..1c07d5f5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -254210,11 +254210,49 @@ async function init () { try { const get = core.getInput const required = { required: true } + const apiBase = 'https://api.postman.com' + const idRegex = /^[0-9]{7,}-\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/ const options = { + apiKey: '?apikey=' + get('apiKey'), collection: get('collection', required), environment: get('environment'), - reporters: 'cli' + globals: get('globals'), + iterationCount: Number(get('iterationCount')), + iterationData: get('iterationData'), + folder: split(get('folder')), + workingDir: get('workingDir'), + insecureFileRead: safeParse(get('insecureFileRead')), + timeout: Number(get('timeout')), + timeoutRequest: Number(get('timeoutRequest')), + timeoutScript: Number(get('timeoutScript')), + delayRequest: Number(get('delayRequest')), + ignoreRedirects: safeParse(get('ignoreRedirects')), + insecure: safeParse(get('insecure')), + bail: safeParse(get('bail')), + suppressExitCode: safeParse(get('suppressExitCode')), + reporters: split(get('reporters')), + reporter: safeParse(get('reporter')), + color: get('color'), + sslClientCert: get('sslClientCert'), + sslClientKey: get('sslClientKey'), + sslClientPassphrase: get('sslClientPassphrase'), + sslClientCertList: split(get('sslClientCertList')), + sslExtraCaCerts: get('sslExtraCaCerts'), + requestAgents: safeParse(get('requestAgents')), + cookieJar: get('cookieJar') + } + + if (!options.apiKey) { + core.warning('No Postman API key provided.') + } + + if (options.collection.match(idRegex)) { + options.collection = `${apiBase}/collections/${options.collection}${options.apiKey}` + } + + if (options.environment.match(idRegex)) { + options.environment = `${apiBase}/environments/${options.environment}${options.apiKey}` } runNewman(options) @@ -254223,8 +254261,27 @@ async function init () { } } +function safeParse (obj) { + if (obj) { + try { + return JSON.parse(obj) + } catch (e) { + core.warning('Bad object passed in config!') + } + } + + return null +} + +function split (str) { + return str.split(',') +} + function runNewman (options) { + console.log('options') + console.log(options) newman.run(options).on('done', (err, summary) => { + console.log(err) if (!options.suppressExitCode && (err || summary.run.failures.length)) { core.setFailed('Newman run failed!' + (err || '')) } diff --git a/index.js b/index.js index f18ee4bf..e7542feb 100644 --- a/index.js +++ b/index.js @@ -7,11 +7,49 @@ async function init () { try { const get = core.getInput const required = { required: true } + const apiBase = 'https://api.postman.com' + const idRegex = /^[0-9]{7,}-\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/ const options = { + apiKey: '?apikey=' + get('apiKey'), collection: get('collection', required), environment: get('environment'), - reporters: 'cli' + globals: get('globals'), + iterationCount: Number(get('iterationCount')), + iterationData: get('iterationData'), + folder: split(get('folder')), + workingDir: get('workingDir'), + insecureFileRead: safeParse(get('insecureFileRead')), + timeout: Number(get('timeout')), + timeoutRequest: Number(get('timeoutRequest')), + timeoutScript: Number(get('timeoutScript')), + delayRequest: Number(get('delayRequest')), + ignoreRedirects: safeParse(get('ignoreRedirects')), + insecure: safeParse(get('insecure')), + bail: safeParse(get('bail')), + suppressExitCode: safeParse(get('suppressExitCode')), + reporters: split(get('reporters')), + reporter: safeParse(get('reporter')), + color: get('color'), + sslClientCert: get('sslClientCert'), + sslClientKey: get('sslClientKey'), + sslClientPassphrase: get('sslClientPassphrase'), + sslClientCertList: split(get('sslClientCertList')), + sslExtraCaCerts: get('sslExtraCaCerts'), + requestAgents: safeParse(get('requestAgents')), + cookieJar: get('cookieJar') + } + + if (!options.apiKey) { + core.warning('No Postman API key provided.') + } + + if (options.collection.match(idRegex)) { + options.collection = `${apiBase}/collections/${options.collection}${options.apiKey}` + } + + if (options.environment.match(idRegex)) { + options.environment = `${apiBase}/environments/${options.environment}${options.apiKey}` } runNewman(options) @@ -20,8 +58,27 @@ async function init () { } } +function safeParse (obj) { + if (obj) { + try { + return JSON.parse(obj) + } catch (e) { + core.warning('Bad object passed in config!') + } + } + + return null +} + +function split (str) { + return str.split(',') +} + function runNewman (options) { + console.log('options') + console.log(options) newman.run(options).on('done', (err, summary) => { + console.log(err) if (!options.suppressExitCode && (err || summary.run.failures.length)) { core.setFailed('Newman run failed!' + (err || '')) } diff --git a/package-lock.json b/package-lock.json index b0f21a8d..4cda06c5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "newman-action", - "version": "0.3.5", + "version": "0.3.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 2ef380af..27b54fac 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "newman-action", - "version": "0.3.5", + "version": "0.3.6", "description": "Run Postman collections with Newman as a GitHub Action", "main": "dist/index.js", "repository": {