@gitlab/semantic-release-merge-request-analyzer
Version:
Semantic release plugin to determine version based on GitLab merge request labels
66 lines (56 loc) • 2.06 kB
JavaScript
import SemanticReleaseError from "@semantic-release/error";
import AggregateError from "aggregate-error";
/**
* Verify that the environment variables required for GitLab API access are present.
*
* @param {Object} pluginConfig The plugin configuration.
* @param {Object} context The semantic-release context.
* @returns {Promise<void>} A Promise that resolves if the verification is successful.
* @throws {AggregateError} If any required configuration is missing.
*/
export async function verifyConditions(pluginConfig, context) {
const { env, logger } = context;
const errors = [];
logger.log("Verifying GitLab environment configuration");
// Check if CI_PROJECT_ID is set
if (!env.CI_PROJECT_ID) {
errors.push(
new SemanticReleaseError(
"No GitLab Project ID found.",
"ENOGLPROJECTID",
"The GitLab project ID is required to analyze commits and generate release notes. " +
"Please make sure the CI_PROJECT_ID environment variable is set.",
),
);
}
// Also check for GitLab token (needed for API access)
if (!env.GITLAB_TOKEN) {
errors.push(
new SemanticReleaseError(
"No GitLab Token found.",
"ENOGLTOKEN",
"A GitLab personal access token with API access is required. " +
"Please make sure the GITLAB_TOKEN environment variable is set.",
),
);
}
// Verify label configuration if provided
if (pluginConfig && pluginConfig.labels) {
const { labels } = pluginConfig;
if (!labels || typeof labels !== "object") {
errors.push(
new SemanticReleaseError(
"Invalid label configuration.",
"EINVALIDLABELCONFIG",
'The "labels" option must be an object with release types as keys and arrays of label names as values.',
),
);
}
}
// Throw any errors we accumulated during the validation
if (errors.length > 0) {
throw new AggregateError(errors);
}
logger.success("GitLab environment configuration verified");
}
export default verifyConditions;