Skip to content

Commit

Permalink
Merge pull request #38 from matt-ball/readd-func
Browse files Browse the repository at this point in the history
readd funcs
  • Loading branch information
matt-ball authored Oct 8, 2021
2 parents a3af3ea + cde832e commit b89a446
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 4 deletions.
59 changes: 58 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 || ''))
}
Expand Down
59 changes: 58 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 || ''))
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit b89a446

Please sign in to comment.