Skip to content

Commit

Permalink
conditially use api or file
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-ball committed Sep 13, 2019
1 parent 0d3df89 commit f809305
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ inputs:
environment:
description: 'Postman environment to use'
default: 'postman_environment.json'
reporters:
description: 'Reporters to use'
default: 'cli'
runs:
using: 'node12'
main: 'index.js'
26 changes: 17 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
const core = require('@actions/core')
const newman = require('newman')
const fs = require('fs')

run()

async function run () {
try {
const apiKey = core.getInput('postmanApiKey')
const collectionId = core.getInput('collection')
const environmentId = core.getInput('environment')

if (!apiKey) {
core.warn('No Postman API key provided.')
}

let collection = core.getInput('collection')
let environment = core.getInput('environment')
const reporters = core.getInput('reporters')

const apiParam = `?apikey=${apiKey}`
const apiBase = 'https://api.getpostman.com'
const idRegex = /^[0-9]{7}-\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/

console.log(collectionId)
console.log(fs.readFileSync('postman_collection.json'))
if (collection.match(idRegex)) {
collection = `${apiBase}/collections/${collection}${apiParam}`
}

const options = {
reporters: 'cli',
collection: `${apiBase}/collections/${collectionId}${apiParam}`,
environment: `${apiBase}/environments/${environmentId}${apiParam}`
if (environment.match(idRegex)) {
environment = `${apiBase}/environments/${environment}${apiParam}`
}

const options = { reporters, collection, environment }

runNewman(options)
} catch (error) {
core.setFailed(error.message)
Expand Down

0 comments on commit f809305

Please sign in to comment.