plan_id now successfully grabbed from run details API

This commit is contained in:
worm 2023-01-02 14:04:02 -08:00
parent d7ef2e7d3a
commit dddeebd133
2 changed files with 16 additions and 5 deletions

2
log
View file

@ -1 +1 @@
RUN ID VALUE FOR CONFIG:undefined
plan-TienGBHfydZB6str

19
main.js
View file

@ -3,17 +3,28 @@ import { get_run_details } from "./tfc-api-functions.mjs";
const my_config = await normalized_config;
// verify that a run_id was provided to the program
const runid_provided = run_id => {
return (run_id ? true : false);
}
// Add negation function for readability (no 'unless' in js)
const runidNotProvided = run_id => {
return !runid_provided(run_id);
}
if(runidNotProvided(my_config.run_id)){
console.log(`RUN ID VALUE FOR CONFIG:${my_config.run_id}`);
throw new Error("RunID must be provided");
// Check for prefix indicating a valid run id
const startsWithRun = run_id => {
return run_id.startsWith("run-");
}
const response = await get_run_details(my_config.base_url, process.argv.slice(2), my_config.token);
if(runidNotProvided(my_config.run_id) || !startsWithRun(my_config.run_id)){
throw new Error("A valid RunID must be provided. Please check that the supplied runID is valid");
}
// TODO: Add error handling for `data: { errors: [ { status: '404', title: 'not found' } ] }`
const run_details = await get_run_details(my_config.base_url, process.argv.slice(2), my_config.token);
const plan_id = run_details.data.data.relationships.plan.data.id;
console.log(plan_id);