Skip to content

Commit

Permalink
single source of truth for env var (#864)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarf authored Dec 7, 2023
1 parent a0563b0 commit eb9f3b0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 2 additions & 0 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ listener.route('/aria-at/:branch*').get(
// Conditionally initialize github workflow service, or mock automation scheduler
if (
process.env.ENVIRONMENT === 'production' ||
process.env.ENVIRONMENT === 'staging' ||
process.env.ENVIRONMENT === 'sandbox' ||
process.env.AUTOMATION_CALLBACK_FQDN
) {
require('./services/GithubWorkflowService').setup();
Expand Down
16 changes: 6 additions & 10 deletions server/models/services/CollectionJobService.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const { HttpQueryError } = require('apollo-server-core');
const { runnableTests } = require('../../resolvers/TestPlanReport');
const { default: axios } = require('axios');
const {
default: createGithubWorkflow
default: createGithubWorkflow,
isEnabled: isGithubWorkflowEnabled,
} = require('../../services/GithubWorkflowService');

const includeBrowserVersion = {
Expand Down Expand Up @@ -83,11 +84,6 @@ const axiosConfig = {
timeout: 1000
};

const automationSchedulerMockEnabled = !(
process.env.ENVRIONMENT == 'production' ||
process.env.AUTOMATION_CALLBACK_FQDN
);

/**
* @param {object} collectionJob - CollectionJob to be created
* @param {string} collectionJob.id - id for the CollectionJob
Expand Down Expand Up @@ -218,7 +214,10 @@ const triggerWorkflow = async (job, testIds, options) => {
const { testPlanVersion } = job.testPlanRun.testPlanReport;
const { gitSha, directory } = testPlanVersion;
try {
if (automationSchedulerMockEnabled) {
if (isGithubWorkflowEnabled()) {
// TODO: pass the reduced list of testIds along / deal with them somehow
await createGithubWorkflow({ job, directory, gitSha });
} else {
await axios.post(
`${process.env.AUTOMATION_SCHEDULER_URL}/jobs/new`,
{
Expand All @@ -229,9 +228,6 @@ const triggerWorkflow = async (job, testIds, options) => {
},
axiosConfig
);
} else {
// TODO: pass the reduced list of testIds along / deal with them somehow
await createGithubWorkflow({ job, directory, gitSha });
}
} catch (error) {
// TODO: What to do with the actual error (could be nice to have an additional "string" status field?)
Expand Down
1 change: 1 addition & 0 deletions server/services/GithubWorkflowService.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ exports.setup = async () => {
}
};

exports.isEnabled = () => privateKey && callbackUrlHostname;
// > 2. Get the ID of the installation that you want to authenticate as.
// >
// > If you are responding to a webhook event, the webhook payload will
Expand Down

0 comments on commit eb9f3b0

Please sign in to comment.