Skip to content

Commit b89a446

Browse files
authored
Merge pull request #38 from matt-ball/readd-func
readd funcs
2 parents a3af3ea + cde832e commit b89a446

File tree

4 files changed

+118
-4
lines changed

4 files changed

+118
-4
lines changed

dist/index.js

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254210,11 +254210,49 @@ async function init () {
254210254210
try {
254211254211
const get = core.getInput
254212254212
const required = { required: true }
254213+
const apiBase = 'https://api.postman.com'
254214+
const idRegex = /^[0-9]{7,}-\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/
254213254215

254214254216
const options = {
254217+
apiKey: '?apikey=' + get('apiKey'),
254215254218
collection: get('collection', required),
254216254219
environment: get('environment'),
254217-
reporters: 'cli'
254220+
globals: get('globals'),
254221+
iterationCount: Number(get('iterationCount')),
254222+
iterationData: get('iterationData'),
254223+
folder: split(get('folder')),
254224+
workingDir: get('workingDir'),
254225+
insecureFileRead: safeParse(get('insecureFileRead')),
254226+
timeout: Number(get('timeout')),
254227+
timeoutRequest: Number(get('timeoutRequest')),
254228+
timeoutScript: Number(get('timeoutScript')),
254229+
delayRequest: Number(get('delayRequest')),
254230+
ignoreRedirects: safeParse(get('ignoreRedirects')),
254231+
insecure: safeParse(get('insecure')),
254232+
bail: safeParse(get('bail')),
254233+
suppressExitCode: safeParse(get('suppressExitCode')),
254234+
reporters: split(get('reporters')),
254235+
reporter: safeParse(get('reporter')),
254236+
color: get('color'),
254237+
sslClientCert: get('sslClientCert'),
254238+
sslClientKey: get('sslClientKey'),
254239+
sslClientPassphrase: get('sslClientPassphrase'),
254240+
sslClientCertList: split(get('sslClientCertList')),
254241+
sslExtraCaCerts: get('sslExtraCaCerts'),
254242+
requestAgents: safeParse(get('requestAgents')),
254243+
cookieJar: get('cookieJar')
254244+
}
254245+
254246+
if (!options.apiKey) {
254247+
core.warning('No Postman API key provided.')
254248+
}
254249+
254250+
if (options.collection.match(idRegex)) {
254251+
options.collection = `${apiBase}/collections/${options.collection}${options.apiKey}`
254252+
}
254253+
254254+
if (options.environment.match(idRegex)) {
254255+
options.environment = `${apiBase}/environments/${options.environment}${options.apiKey}`
254218254256
}
254219254257

254220254258
runNewman(options)
@@ -254223,8 +254261,27 @@ async function init () {
254223254261
}
254224254262
}
254225254263

254264+
function safeParse (obj) {
254265+
if (obj) {
254266+
try {
254267+
return JSON.parse(obj)
254268+
} catch (e) {
254269+
core.warning('Bad object passed in config!')
254270+
}
254271+
}
254272+
254273+
return null
254274+
}
254275+
254276+
function split (str) {
254277+
return str.split(',')
254278+
}
254279+
254226254280
function runNewman (options) {
254281+
console.log('options')
254282+
console.log(options)
254227254283
newman.run(options).on('done', (err, summary) => {
254284+
console.log(err)
254228254285
if (!options.suppressExitCode && (err || summary.run.failures.length)) {
254229254286
core.setFailed('Newman run failed!' + (err || ''))
254230254287
}

index.js

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,49 @@ async function init () {
77
try {
88
const get = core.getInput
99
const required = { required: true }
10+
const apiBase = 'https://api.postman.com'
11+
const idRegex = /^[0-9]{7,}-\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/
1012

1113
const options = {
14+
apiKey: '?apikey=' + get('apiKey'),
1215
collection: get('collection', required),
1316
environment: get('environment'),
14-
reporters: 'cli'
17+
globals: get('globals'),
18+
iterationCount: Number(get('iterationCount')),
19+
iterationData: get('iterationData'),
20+
folder: split(get('folder')),
21+
workingDir: get('workingDir'),
22+
insecureFileRead: safeParse(get('insecureFileRead')),
23+
timeout: Number(get('timeout')),
24+
timeoutRequest: Number(get('timeoutRequest')),
25+
timeoutScript: Number(get('timeoutScript')),
26+
delayRequest: Number(get('delayRequest')),
27+
ignoreRedirects: safeParse(get('ignoreRedirects')),
28+
insecure: safeParse(get('insecure')),
29+
bail: safeParse(get('bail')),
30+
suppressExitCode: safeParse(get('suppressExitCode')),
31+
reporters: split(get('reporters')),
32+
reporter: safeParse(get('reporter')),
33+
color: get('color'),
34+
sslClientCert: get('sslClientCert'),
35+
sslClientKey: get('sslClientKey'),
36+
sslClientPassphrase: get('sslClientPassphrase'),
37+
sslClientCertList: split(get('sslClientCertList')),
38+
sslExtraCaCerts: get('sslExtraCaCerts'),
39+
requestAgents: safeParse(get('requestAgents')),
40+
cookieJar: get('cookieJar')
41+
}
42+
43+
if (!options.apiKey) {
44+
core.warning('No Postman API key provided.')
45+
}
46+
47+
if (options.collection.match(idRegex)) {
48+
options.collection = `${apiBase}/collections/${options.collection}${options.apiKey}`
49+
}
50+
51+
if (options.environment.match(idRegex)) {
52+
options.environment = `${apiBase}/environments/${options.environment}${options.apiKey}`
1553
}
1654

1755
runNewman(options)
@@ -20,8 +58,27 @@ async function init () {
2058
}
2159
}
2260

61+
function safeParse (obj) {
62+
if (obj) {
63+
try {
64+
return JSON.parse(obj)
65+
} catch (e) {
66+
core.warning('Bad object passed in config!')
67+
}
68+
}
69+
70+
return null
71+
}
72+
73+
function split (str) {
74+
return str.split(',')
75+
}
76+
2377
function runNewman (options) {
78+
console.log('options')
79+
console.log(options)
2480
newman.run(options).on('done', (err, summary) => {
81+
console.log(err)
2582
if (!options.suppressExitCode && (err || summary.run.failures.length)) {
2683
core.setFailed('Newman run failed!' + (err || ''))
2784
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "newman-action",
3-
"version": "0.3.5",
3+
"version": "0.3.6",
44
"description": "Run Postman collections with Newman as a GitHub Action",
55
"main": "dist/index.js",
66
"repository": {

0 commit comments

Comments
 (0)