diff --git a/README.md b/README.md index 1e68f18..64f2aca 100644 --- a/README.md +++ b/README.md @@ -35,4 +35,11 @@ In the above snippet, the `project_id` and `api_key` are being fetched from the `check_interval`: The interval in **seconds** of which the action should check the status of running tests. (Recommended to not make this too short so you will not be spamming TestProject APIs) -`wait_for_tests`: Whether the action should wait for the tests to complete (pass/fail) or if it should just start them and complete the action. (Default = `true`) \ No newline at end of file +`wait_for_tests`: Whether the action should wait for the tests to complete (pass/fail) or if it should just start them and complete the action. (Default = `true`) + +### More optional params for changing targeted application url. Use these two params together (useful for devs who build PR / dynamic envs for testing phase): + +`api_id`: appId for application associated with project_id. Use in conjunction with app_url below. (Default = `0`) + +`app_url`: Update appId with new url to target. (Default = `` empty string) + diff --git a/action.yml b/action.yml index dac0bad..1506208 100644 --- a/action.yml +++ b/action.yml @@ -18,8 +18,15 @@ inputs: wait_for_tests: description: 'Should the action wait for tests to finish before continuing' required: false - default: 'true' - + default: true + app_id: + description: 'Application ID so we can update/pass target app url' + required: false + default: '0' + app_url: + description: 'app url (target)' + required: false + default: '' branding: icon: 'check-circle' - color: 'green' \ No newline at end of file + color: 'green' diff --git a/execute-tests.js b/execute-tests.js index 3ea86c1..0fe5078 100644 --- a/execute-tests.js +++ b/execute-tests.js @@ -10,10 +10,25 @@ const API_HEADER = { const CHECK_INTERVAL = parseInt(strip(process.env.INPUT_CHECK_INTERVAL)) * 1000 const WAIT_FOR_TESTS = strip(process.env.INPUT_WAIT_FOR_TESTS) === 'true' || strip(process.env.INPUT_WAIT_FOR_TESTS) === true +const API_URL_APP = `https://api.testproject.io/v2/projects/${ strip(process.env.INPUT_PROJECT_ID) }/applications/${ strip(process.env.INPUT_APP_ID) }` + // Keep track of all jobs const jobsStatus = [] async function main() { + + //update application url if optional defaults changed - SteveDevOps + if ( parseInt(strip(process.env.INPUT_APP_ID)) != 0 && strip(process.env.INPUT_APP_URL) != '' ) { + + core.info(`Attempting to change application url to ${ strip(process.env.INPUT_APP_URL) } for appId ${ strip(process.env.INPUT_APP_ID) }`) + + await updateAppUrl().catch( err => { + core.setFailed(`Unable to update appId with new url.`) + console.log(err) + return + }) + + } core.info(`Getting a list of all jobs in project ${ strip(process.env.INPUT_PROJECT_ID) }`) @@ -52,6 +67,33 @@ async function getJobs() { return jobs.data } + +/** + * updates application url for project_id if INPUT_APP_ID AND INPUT_APP_URL are passed - SteveDevOps + */ + +async function updateAppUrl() { + + const params = JSON.stringify({ + + "url": strip(process.env.INPUT_APP_URL), + + }); + + await axios ({ + method: 'put', + url: API_URL_APP, + headers: API_HEADER, + body: params + }).catch( err => { + core.setFailed(`Execution failed for changing appId via post to ${ API_URL_APP } `) + console.log(err) + return + }) + +} + + /** * Executes all the jobs passed in the parameter and adds them to the `jobsStatus` array * @param {*} jobs Array of jobs to execute