New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gitlab-releaser

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gitlab-releaser - npm Package Compare versions

Comparing version 2.0.4 to 3.0.0

LICENSE

12

bin/gitlab-releaser.js

@@ -8,8 +8,8 @@ #!/usr/bin/env node

const { getReleaseCliCommand, saveReleaseCliScript } = require('..');
const { schemaTypes } = require('../lib/schema');
const { SchemaTypes } = require('../lib/schema');
const gitlabDirectory = '.gitlab';
const fileNames = {
[schemaTypes.release]: 'release.json',
[schemaTypes.gitlabReleaser]: 'gitlab-releaser.json'
[SchemaTypes.release]: 'release.json',
[SchemaTypes.gitlabReleaser]: 'gitlab-releaser.json'
};

@@ -19,8 +19,8 @@ const releaseScriptName = 'release.sh';

program.version(pkg.version)
.option('-s, --schema <schema>', 'the schema type of the JSON input file', schemaTypes.gitlabReleaser)
.option('-t, --tag <tag>', `the tag used to retrieve release data, required if schema type is ${schemaTypes.gitlabReleaser} or if release pulls data from a CHANGELOG (default: "$CI_COMMIT_TAG")`, env.ci.commit.tag)
.option('-s, --schema <schema>', 'the schema type of the JSON input file', SchemaTypes.gitlabReleaser)
.option('-r, --release <release>', `the reference used to retrieve release data, required if schema type is ${SchemaTypes.gitlabReleaser} or if release pulls data from a CHANGELOG (default: "$CI_COMMIT_TAG")`, env.ci.commit.tag)
.parse(process.argv);
const options = program.opts();
const command = getReleaseCliCommand(gitlabDirectory, fileNames[options.schema], options.schema, options.tag);
const command = getReleaseCliCommand(gitlabDirectory, fileNames[options.schema], options.schema, options.release);
saveReleaseCliScript(gitlabDirectory, releaseScriptName, command);

@@ -13,3 +13,3 @@ 'use strict';

const { usesChangelog, processChangelogData } = require('./lib/changelog');
const { isValidGitLabReleaser, isValidRelease, isValidSchemaType, schemaTypes } = require('./lib/schema');
const { isValidGitLabReleaser, isValidRelease, isValidSchemaType, SchemaTypes } = require('./lib/schema');
const cli = require('./lib/cli-args');

@@ -19,2 +19,9 @@

/**
* Gets a ci-logger formatted message object for error with exit code 1.
*
* @private
* @param {string} message The error message.
* @returns {object} A ci-logger formatted message object.
*/
const getErrorLogEntry = (message) => {

@@ -24,4 +31,11 @@ return { message, level: logger.levels.error, exitOnError: true, errorCode: 1 };

const verifyTagExists = (tag, message) => {
if (!tag) {
/**
* Checks for a valid release name and logs error and exits if not specified.
*
* @private
* @param {string} releaseName The given release name.
* @param {string} message The error message if no release specified.
*/
const validateReleaseName = (releaseName, message) => {
if (!releaseName) {
logger.log(getErrorLogEntry(message));

@@ -31,25 +45,15 @@ }

const processTag = (data, tag) => {
// Ensure tag_name is included in release data, if available. If tag
// specified via CLI, it overrides tag_name from file.
if (tag) {
if (data.tag_name && data.tag_name !== tag) {
// Log warning since overriding data from release file
logger.log({
message: `Overwriting tag_name "${data.tag_name}" from release with tag "${tag}" from CLI`,
level: logger.levels.warn
});
}
// eslint-disable-next-line camelcase -- name specified in release-cli
data.tag_name = tag;
}
return data;
};
const processReleaseData = (data, tag) => {
/**
* Updates release data with any applicable CHANGELOG data.
*
* @private
* @param {object} data The release data.
* @param {string} releaseName The given release name.
* @returns {object} Release data including any applicable CHANGELOG data.
*/
const processReleaseData = (data, releaseName) => {
let processedData;
if (usesChangelog(data)) {
verifyTagExists(tag, 'Tag must be specified to process CHANGELOG data');
processedData = processChangelogData(data, tag);
validateReleaseName(releaseName, 'Release must be specified to process CHANGELOG data');
processedData = processChangelogData(data, releaseName);
}

@@ -60,14 +64,29 @@ else {

const args = cli.getArgsString(processTag(processedData, tag));
const args = cli.getArgumentsString(processedData);
return `${createReleaseCommand}${args}`;
};
const getReleaseFromGitLabReleaser = (data, tag) => {
const releaseData = data.releases && Object.keys(data.releases).includes(tag) ? data.releases[tag] : {};
return Object.assign(Object.create(null), data.defaults, releaseData);
/**
* Gets a release object from a gitlab-releaser file for a given release.
*
* @private
* @param {object} data The gitlab-releaser data.
* @param {string} releaseName The given release name.
* @returns {object} The applicable release object.
*/
const getReleaseFromGitLabReleaser = (data, releaseName) => {
const releaseData = data.releases && Object.keys(data.releases).includes(releaseName)
? data.releases[releaseName] : {};
return { ...data.defaults, ...releaseData };
};
/**
* Validates that the schema type is valid.
*
* @private
* @param {string} type The file schema type.
*/
const validateSchemaType = (type) => {
if (!isValidSchemaType(type)) {
logger.log(getErrorLogEntry(`Schema type "${type}" is invalid, must be one of '${Object.values(schemaTypes).join('\', \'')}'`));
logger.log(getErrorLogEntry(`Schema type "${type}" is invalid, must be one of '${Object.values(SchemaTypes).join('\', \'')}'`));
}

@@ -80,2 +99,3 @@ };

*
* @public
* @static

@@ -87,7 +107,7 @@ * @param {string} directory The directory where the release file

* gitlab-releaser).
* @param {string} tag The tag to use to find release data
* in the CHANGELOG.
* @param {string} releaseName The name to use to find release data
* in the CHANGELOG and gitlab-releaser file.
* @returns {string} The release-cli command.
*/
const getReleaseCliCommand = (directory, releaseFileName, type, tag) => {
const getReleaseCliCommand = (directory, releaseFileName, type, releaseName) => {
validateSchemaType(type);

@@ -99,8 +119,8 @@

let release;
if (type === schemaTypes.gitlabReleaser) {
if (type === SchemaTypes.gitlabReleaser) {
if (!isValidGitLabReleaser(data)) {
logger.log(getErrorLogEntry(`"${releaseFile}" is invalid gitlab-releaser file`));
}
verifyTagExists(tag, 'Tag must be specified if schema type is gitlab-releaser');
release = getReleaseFromGitLabReleaser(data, tag);
validateReleaseName(releaseName, 'Release must be specified if schema type is gitlab-releaser');
release = getReleaseFromGitLabReleaser(data, releaseName);
}

@@ -114,3 +134,3 @@ else {

}
return processReleaseData(release, tag);
return processReleaseData(release, releaseName);
};

@@ -123,2 +143,3 @@

*
* @public
* @static

@@ -138,4 +159,4 @@ * @param {string} directory The destination directory to save

}
catch (err) {
logger.log(getErrorLogEntry(`Error saving file\n${err.message}`));
catch (error) {
logger.log(getErrorLogEntry(`Error saving file\n${error.message}`));
}

@@ -142,0 +163,0 @@ };

@@ -20,2 +20,3 @@ 'use strict';

*
* @public
* @static

@@ -35,2 +36,3 @@ * @param {object} data The release object to check.

*
* @public
* @static

@@ -62,2 +64,3 @@ * @param {string} tag The tag to find in the CHANGELOG.

*
* @public
* @static

@@ -64,0 +67,0 @@ * @param {object} data The release.

@@ -11,12 +11,28 @@ 'use strict';

const getOption = (value, optionName) => {
/**
* Get the CLI argument string with escaped value if a value is specified.
*
* @private
* @param {string} value The value of the CLI argument.
* @param {string} optionName The name of the CLI argument.
* @returns {string} The CLI argument with escaped value.
*/
const getArgument = (value, optionName) => {
return value ? ` ${optionName} ${escapeString(value)}` : '';
};
const getArrayOptions = (values, optionName) => {
/**
* Gets CLI argument string where there may be multiple values.
*
* @private
* @param {string[]} values Array of CLI argument values.
* @param {string} optionName The name of the CLI argument.
* @returns {string} The CLI argument with escaped value.
*/
const getArrayArguments = (values, optionName) => {
let result = '';
if (values) {
values.forEach(value => {
result += getOption(value, optionName);
});
for (const value of values) {
result += getArgument(value, optionName);
}
}

@@ -26,2 +42,9 @@ return result;

/**
* Get CLI argument for assets with JSON string as value.
*
* @private
* @param {object} assets The release asset object.
* @returns {string} The CLI argument with escaped value.
*/
const getAssetLinks = (assets) => {

@@ -31,5 +54,5 @@ const optionName = '--assets-link';

if (assets) {
assets.links.forEach(link => {
result += getOption(JSON.stringify(link), optionName);
});
for (const link of assets.links) {
result += getArgument(JSON.stringify(link), optionName);
}
}

@@ -43,2 +66,3 @@ return result;

*
* @public
* @static

@@ -49,14 +73,14 @@ * @param {object} release A release object with applicable parameters

*/
const getArgsString = (release) => {
const getArgumentsString = (release) => {
let command = '';
command += getOption(release.name, '--name');
command += getOption(release.description, '--description');
command += getOption(release.tag_name, '--tag-name');
command += getOption(release.ref, '--ref');
command += getArgument(release.name, '--name');
command += getArgument(release.description, '--description');
command += getArgument(release.tag_name, '--tag-name');
command += getArgument(release.ref, '--ref');
command += getAssetLinks(release.assets);
command += getArrayOptions(release.milestones, '--milestone');
command += getOption(release.released_at, '--released-at');
command += getArrayArguments(release.milestones, '--milestone');
command += getArgument(release.released_at, '--released-at');
return command;
};
module.exports.getArgsString = getArgsString;
module.exports.getArgumentsString = getArgumentsString;

@@ -13,6 +13,14 @@ 'use strict';

const schemaTypes = {
/**
* Enum for schema type.
*
* @enum {string}
* @readonly
* @public
* @static
*/
const SchemaTypes = Object.freeze({
release: 'release',
gitlabReleaser: 'gitlab-releaser'
};
});

@@ -29,2 +37,3 @@ const schemaDirectory = 'schemas';

*
* @public
* @static

@@ -35,5 +44,16 @@ * @param {string} value The schema type to check.

const isValidSchemaType = (value) => {
return Object.values(schemaTypes).includes(value);
return Object.values(SchemaTypes).includes(value);
};
/**
* Common function to validate data against a JSON schema, includes
* cases with child schemas that must be loaded.
*
* @private
* @param {string[]} schemaFiles The JSON schema files to load.
* @param {string} schemaId The ID for the parent schema.
* @param {object} data The data to validate against the schema.
* @returns {boolean} True if the data is valid for the given
* schema, otherwise false.
*/
const validateDataAgainstSchema = (schemaFiles, schemaId, data) => {

@@ -48,2 +68,3 @@ const schemas = schemaFiles.map(schemaFile => JSON.parse(fs.readFileSync(path.join(__dirname, '..', schemaDirectory, schemaFile))));

*
* @public
* @static

@@ -60,2 +81,3 @@ * @param {object} data The release object to check.

*
* @public
* @static

@@ -72,2 +94,2 @@ * @param {object} data The release object to check.

module.exports.isValidSchemaType = isValidSchemaType;
module.exports.schemaTypes = schemaTypes;
module.exports.SchemaTypes = SchemaTypes;

@@ -21,4 +21,4 @@ 'use strict';

// e.g. 'My ${value}' becomes 'My '"${value}"''
const varRegex = /(\$\{[^}]*\})/g;
const varRegexReplace = '\'"$1"\'';
const variableRegex = /(\${[^}]*})/g;
const variableRegexReplace = '\'"$1"\'';

@@ -30,3 +30,3 @@ // The following regex matches strings with only

// but uses linux shell standards and adds "."
const unquotedRegex = /^[A-Za-z0-9._/-]+$/;
const unquotedRegex = /^[\w./-]+$/;

@@ -37,2 +37,3 @@ /**

*
* @public
* @static

@@ -47,7 +48,6 @@ * @param {string} value The string to be formatted.

// then remove any double single quotes.
return `'${value.replace(quoteRegex, quoteRegexReplace).replace(varRegex, varRegexReplace)}'`.replace(/''/g, '');
return `'${value.replace(quoteRegex, quoteRegexReplace).replace(variableRegex, variableRegexReplace)}'`.replace(/''/g, '');
}
return value;
};
module.exports.escapeString = escapeString;
{
"name": "gitlab-releaser",
"version": "2.0.4",
"version": "3.0.0",
"description": "Generate arguments for GitLab release-cli command",

@@ -38,18 +38,18 @@ "bin": "./bin/gitlab-releaser.js",

},
"homepage": "https://gitlab.com/gitlab-ci-utils/gitlab-releaser#readme",
"homepage": "https://gitlab.com/gitlab-ci-utils/gitlab-releaser",
"devDependencies": {
"@aarongoldenthal/eslint-config-standard": "^11.0.0",
"@aarongoldenthal/eslint-config-standard": "^12.0.2",
"bin-tester": "^2.0.1",
"eslint": "^8.7.0",
"jest": "^27.4.7",
"eslint": "^8.12.0",
"jest": "^27.5.1",
"jest-junit": "^13.0.0",
"markdownlint-cli": "^0.30.0"
"markdownlint-cli": "^0.31.1"
},
"dependencies": {
"ajv": "^8.9.0",
"ajv": "^8.11.0",
"ci-logger": "^4.0.1",
"commander": "^8.3.0",
"commander": "^9.1.0",
"gitlab-ci-env": "^4.5.0",
"releaselog": "^2.1.2"
"releaselog": "^2.1.4"
}
}

@@ -40,3 +40,3 @@ # GitLab Releaser

GitLab Releaser can accept a GitLab Releaser file at `.gitlab/gitlab-releaser.json` which can contain default values applicable to all releases and overrides for multiple specific releases denoted by tag, for example:
GitLab Releaser can accept a GitLab Releaser file at `.gitlab/gitlab-releaser.json` which can contain default values applicable to all releases and overrides for multiple specific releases denoted by release name, for example:

@@ -75,3 +75,3 @@ ```json

A tag must be specified via the CLI to pull the appropriate release information. For example, tag `1.0.0` would result in the following equivalent `release.json` file.
A release name must be specified via the CLI to pull the appropriate release information. For example, `--release 1.0.0` would result in the following equivalent `release.json` file.

@@ -110,3 +110,3 @@ ```json

The [`releaselog`](https://www.npmjs.com/package/releaselog) module is used to pull this data and has details on CHANGELOG formatting requirements. The data is retrieved by the tag specified via the CLI, if specified, otherwise the value of `CI_COMMIT_TAG` is used. Either a tag or the default value must be specified via the CLI if the release used CHANGELOG data.
The [`releaselog`](https://www.npmjs.com/package/releaselog) module is used to pull this data and has details on CHANGELOG formatting requirements. The data is retrieved by the tag specified via the CLI, if specified, otherwise the value of `CI_COMMIT_TAG` is used. Either a release name or the default value must be specified via the CLI if the release uses CHANGELOG data.

@@ -144,11 +144,9 @@ If either `name` or `description` specifies pulling data from the CHANGELOG, but that data cannot be found in the CHANGELOG, the job will report the error and fail.

Options:
-V, --version output the version number
-s, --schema <schema> the schema type of the JSON input file (default: "gitlab-releaser")
-t, --tag <tag> the tag used to retrieve release data, required if schema type is gitlab-releaser or if
release pulls data from a CHANGELOG (default: "$CI_COMMIT_TAG")
-h, --help display help for command
-V, --version output the version number
-s, --schema <schema> the schema type of the JSON input file (default: "gitlab-releaser")
-r, --release <release> the reference used to retrieve release data, required if schema type is
gitlab-releaser or if release pulls data from a CHANGELOG (default: "$CI_COMMIT_TAG")
-h, --help display help for command
```
If a tag or its default value are specified it will override any `tag_name` value found in the release file (of either type).
### GitLab CI Usage

@@ -189,3 +187,3 @@

The `prepare_release` job uses a Node.js container image and installs and runs `gitlab-releaser` to generate the shell script to prepare the release, saved as `.gitlab/release.sh`. For the example `release.json` file above, or the `gitlab-releaser.json` for tag `1.0.0`, the following shell script will be generated:
The `prepare_release` job uses a Node.js container image and installs and runs `gitlab-releaser` to generate the shell script to prepare the release, saved as `.gitlab/release.sh`. For the example `release.json` file above, or the `gitlab-releaser.json` for release `1.0.0`, the following shell script will be generated:

@@ -192,0 +190,0 @@ ```sh

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc