@relative-ci/agent
Version:
Send bundle stats and CI build information to RelativeCI
63 lines (59 loc) • 2.08 kB
JavaScript
;
var en = require('../locales/en.js');
var constants = require('../constants.js');
var getEnvVars = require('./get-env-vars.js');
var debug = require('./debug.js');
var maskObjectProperty = require('./mask-object-property.js');
var getCommitMessage = require('./get-commit-message.js');
/**
* Normalize ingest params based on:
* 1. pluign arguments
* 2. computed values
* 3. env-ci fallback
*/
function normalizeParams(pluginArgs, config) {
const envVars = getEnvVars.getEnvVars();
const params = {
slug: pluginArgs.slug || envVars.slug,
branch: pluginArgs.branch || envVars.branch,
pr: pluginArgs.pr || envVars.pr,
commit: pluginArgs.commit || envVars.commit,
build: envVars.build,
buildUrl: envVars.buildUrl,
service: envVars.service,
key: envVars.key,
endpoint: envVars.endpoint || constants.DEFAULT_ENDPOINT,
agentVersion: "4.3.0",
/**
* Get commit message using git if includeCommitMessage is set and
* the commitMessage plugin argument is missing
*/
commitMessage: pluginArgs.commitMessage
|| envVars.commitMessage
|| (config.includeCommitMessage ? getCommitMessage.getCommitMessage() : undefined),
};
debug.debug('normalized parameters', maskObjectProperty.maskObjectProperties(params, ['key']));
// Validate required parameters
if (!params.key) {
throw new Error(en.AGENT_MISSING_KEY_ERROR);
}
if (!params.slug) {
throw new Error(en.AGENT_MISSING_SLUG_ERROR);
}
if (!params.commit) {
throw new Error(en.AGENT_MISSING_COMMIT_ERROR);
}
if (!params.branch) {
throw new Error(en.AGENT_MISSING_BRANCH_ERROR);
}
// Explicitly pass required props to allow ts to infer correctly
return {
...params,
key: params.key,
slug: params.slug,
branch: params.branch,
commit: params.commit,
};
}
exports.normalizeParams = normalizeParams;
//# sourceMappingURL=normalize-params.js.map