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 4.0.4 to 5.0.0

37

bin/gitlab-releaser.js

@@ -12,4 +12,4 @@ #!/usr/bin/env node

const fileNames = {
[SchemaTypes.release]: 'release.json',
[SchemaTypes.gitlabReleaser]: 'gitlab-releaser.json'
[SchemaTypes.Release]: 'release.json',
[SchemaTypes.GitlabReleaser]: 'gitlab-releaser.json'
};

@@ -23,18 +23,35 @@ const releaseScriptName = 'release.sh';

'the schema type of the JSON input file',
SchemaTypes.gitlabReleaser
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")`,
`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
)
.option(
'-c, --changelog <changelog>',
`the path to the CHANGELOG to check if the release pulls data from the ` +
`CHANGELOG`,
'.'
)
.option(
'-a, --allow-empty-changelog-desc',
`allow an empty description when pulled from the CHANGELOG`,
false
)
.parse(process.argv);
const options = program.opts();
const command = getReleaseCliCommand(
gitlabDirectory,
fileNames[options.schema],
options.schema,
options.release
);
const releaseCliOptions = {
releaseDirectory: gitlabDirectory,
releaseFileName: fileNames[options.schema],
releaseType: options.schema,
releaseName: options.release,
changelogPath: options.changelog,
allowEmptyChangelogDesc: options.allowEmptyChangelogDesc
};
const command = getReleaseCliCommand(releaseCliOptions);
saveReleaseCliScript(gitlabDirectory, releaseScriptName, command);

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

*/
const fs = require('fs');

@@ -56,15 +57,19 @@ const path = require('path');

*
* @param {object} data The release data.
* @param {string} releaseName The given release name.
* @returns {object} Release data including any applicable CHANGELOG data.
* @param {object} data The release data.
* @param {object} options The options used to create the release command.
* @param {string} options.releaseName The name to use to find release data
* in the CHANGELOG and gitlab-releaser file.
* @param {string} options.changelogPath The path to the CHANGELOG directory or file.
* @param {boolean} options.allowEmptyChangelogDesc Allow an empty description from the CHANGELOG.
* @returns {object} Release data including any applicable CHANGELOG data.
* @private
*/
const processReleaseData = (data, releaseName) => {
const processReleaseData = (data, options) => {
let processedData;
if (usesChangelog(data)) {
validateReleaseName(
releaseName,
options.releaseName,
'Release must be specified to process CHANGELOG data'
);
processedData = processChangelogData(data, releaseName);
processedData = processChangelogData(data, options);
} else {

@@ -116,27 +121,28 @@ processedData = data;

*
* @param {string} directory The directory where the release file
* is located.
* @param {string} releaseFileName The release file name.
* @param {string} type The type fo file (release or
* gitlab-releaser).
* @param {string} releaseName The name to use to find release data
* in the CHANGELOG and gitlab-releaser file.
* @returns {string} The release-cli command.
* @param {object} options The options used to create the release command.
* @param {string} options.releaseDirectory The directory where the release file
* is located.
* @param {string} options.releaseFileName The release file name.
* @param {string} options.releaseType The type fo file (release or
* gitlab-releaser).
* @param {string} options.releaseName The name to use to find release data
* in the CHANGELOG and gitlab-releaser file.
* @param {string} options.changelogPath The path to the CHANGELOG directory or file.
* @param {boolean} options.allowEmptyChangelogDesc Allow an empty description from the CHANGELOG.
* @returns {string} The release-cli command.
* @static
* @public
*/
// eslint-disable-next-line max-lines-per-function
const getReleaseCliCommand = (
directory,
releaseFileName,
type,
releaseName
) => {
validateSchemaType(type);
// eslint-disable-next-line max-lines-per-function -- formatting
const getReleaseCliCommand = (options) => {
validateSchemaType(options.releaseType);
const releaseFile = path.join(directory, releaseFileName);
const releaseFile = path.join(
options.releaseDirectory,
options.releaseFileName
);
const data = JSON.parse(fs.readFileSync(releaseFile));
let release;
if (type === SchemaTypes.gitlabReleaser) {
if (options.releaseType === SchemaTypes.GitlabReleaser) {
if (!isValidGitLabReleaser(data)) {

@@ -150,6 +156,6 @@ logger.log(

validateReleaseName(
releaseName,
options.releaseName,
'Release must be specified if schema type is gitlab-releaser'
);
release = getReleaseFromGitLabReleaser(data, releaseName);
release = getReleaseFromGitLabReleaser(data, options.releaseName);
} else {

@@ -164,3 +170,3 @@ release = data;

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

@@ -167,0 +173,0 @@

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

const fs = require('fs');
const logger = require('ci-logger');

@@ -33,4 +34,41 @@ const releaselog = require('releaselog');

// eslint-disable-next-line jsdoc/require-returns-check -- throws instead of returning
// eslint-disable-next-line jsdoc/require-returns-check -- exits instead of returning
/**
* Checks a path, which could be a file or directory, to determine the
* CHANGELOG file path. If the path is a valid file path, it is returned. If
* it is a directory, it is checked using releaselog to find the appropriate
* CHANGELOG. If the path does not exist, or a CHANGELOG is not found,
* it will log error and exit.
*
* @param {string} path The path to check.
* @returns {string} The full path to the CHANGELOG.
* @static
* @private
*/
const getChangelogFilePath = (path) => {
try {
const stats = fs.statSync(path);
const changelogFileName = stats.isFile()
? path
: releaselog.findChangelog(path);
if (changelogFileName) {
logger.log({
message: `Found changelog file "${changelogFileName}"`
});
return changelogFileName;
}
logger.log({
message: `Changelog not found in path "${path}"`,
level: logger.Levels.Error
});
} catch {
logger.log({
message: `Invalid changelog path "${path}", no file or directory found`,
level: logger.Levels.Error
});
}
};
// eslint-disable-next-line jsdoc/require-returns-check -- exits instead of returning
/**
* Gets release data from a CHANGELOG file. Will log error and exit

@@ -40,6 +78,8 @@ * process if no CHANGELOG is found or the release cannot be found in

*
* @param {string} releaseName The release name to find in the CHANGELOG.
* @param {string} changelogPath The directory to find the CHANGELOG.
* @returns {object} The release name/description from
* the CHANGELOG.
* @param {object} options The options used to create the release command.
* @param {string} options.releaseName The name to use to find release data
* in the CHANGELOG and gitlab-releaser file.
* @param {string} options.changelogPath The path to the CHANGELOG directory or file.
* @returns {object} The release name/description from
* the CHANGELOG.
* @static

@@ -49,3 +89,3 @@ * @public

// eslint-disable-next-line max-lines-per-function
const getReleaseDataFromChangelog = (releaseName, changelogPath = './') => {
const getReleaseDataFromChangelog = ({ releaseName, changelogPath }) => {
if (!releaseName) {

@@ -58,25 +98,25 @@ logger.log({

}
const changelog = releaselog.findChangelog(changelogPath);
let releaseDataFromChangelog;
if (changelog) {
releaseDataFromChangelog = releaselog.getReleaseDetails(
changelog,
releaseName
);
if (releaseDataFromChangelog) {
logger.log({
message: `Found release "${releaseDataFromChangelog.title}" in "${changelog}"`
});
return {
name: releaseDataFromChangelog.title,
description: releaseDataFromChangelog.notes
};
}
if (!changelogPath) {
logger.log({
message: `Release not found in changelog "${changelog}" for release name "${releaseName}"`,
message:
'Changelog path not specified, but required to process changelog data',
level: logger.Levels.Error
});
}
const changelog = getChangelogFilePath(changelogPath);
const releaseDataFromChangelog = releaselog.getReleaseDetails(
changelog,
releaseName
);
if (releaseDataFromChangelog) {
logger.log({
message: `Found release "${releaseDataFromChangelog.title}" in "${changelog}"`
});
return {
name: releaseDataFromChangelog.title,
description: releaseDataFromChangelog.notes
};
}
logger.log({
message: `Changelog not found in directory "${changelogPath}"`,
message: `Release name "${releaseName}" not found in changelog "${changelog}"`,
level: logger.Levels.Error

@@ -89,15 +129,27 @@ });

*
* @param {object} data The release.
* @param {string} releaseName The release name to find in the CHANGELOG.
* @returns {object} The release updated with CHANGELOG data.
* @param {object} data The release.
* @param {object} options The options used to create the release command.
* @param {string} options.releaseName The name to use to find release data
* in the CHANGELOG and gitlab-releaser file.
* @param {string} options.changelogPath The path to the CHANGELOG directory or file.
* @param {boolean} options.allowEmptyChangelogDesc Allow an empty description from the CHANGELOG.
* @returns {object} The release updated with CHANGELOG data.
* @static
* @public
*/
const processChangelogData = (data, releaseName) => {
const changelogData = getReleaseDataFromChangelog(releaseName);
const processChangelogData = (data, options) => {
const changelogData = getReleaseDataFromChangelog(options);
const processedData = data;
if (data.name === changelogKeyword) {
logger.log({ message: 'Retrieved release name from changelog' });
processedData.name = changelogData.name;
}
if (data.description === changelogKeyword) {
if (!changelogData.description && !options.allowEmptyChangelogDesc) {
logger.log({
message: `No description found for release name "${options.releaseName}"`,
level: logger.Levels.Error
});
}
logger.log({ message: 'Retrieved release description from changelog' });
processedData.description = changelogData.description;

@@ -104,0 +156,0 @@ }

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

const SchemaTypes = Object.freeze({
release: 'release',
gitlabReleaser: 'gitlab-releaser'
Release: 'release',
GitlabReleaser: 'gitlab-releaser'
});

@@ -26,0 +26,0 @@

{
"name": "gitlab-releaser",
"version": "4.0.4",
"version": "5.0.0",
"description": "Generate arguments for GitLab release-cli command",

@@ -20,3 +20,3 @@ "bin": "./bin/gitlab-releaser.js",

"type": "git",
"url": "git+https://gitlab.com/gitlab-ci-utils/gitlab-releaser.git"
"url": "https://gitlab.com/gitlab-ci-utils/gitlab-releaser.git"
},

@@ -44,17 +44,17 @@ "keywords": [

"devDependencies": {
"@aarongoldenthal/eslint-config-standard": "^19.0.1",
"@aarongoldenthal/eslint-config-standard": "^20.0.0",
"bin-tester": "^3.0.0",
"eslint": "^8.31.0",
"jest": "^29.3.1",
"eslint": "^8.33.0",
"jest": "^29.4.1",
"jest-junit": "^15.0.0",
"markdownlint-cli": "^0.32.2",
"prettier": "^2.8.1"
"markdownlint-cli": "^0.33.0",
"prettier": "^2.8.3"
},
"dependencies": {
"ajv": "^8.11.2",
"ajv": "^8.12.0",
"ci-logger": "^5.1.0",
"commander": "^9.4.1",
"commander": "^10.0.0",
"gitlab-ci-env": "^7.0.0",
"releaselog": "^3.0.2"
"releaselog": "^3.0.3"
}
}

@@ -108,6 +108,8 @@ # GitLab Releaser

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.
The [`releaselog`](https://www.npmjs.com/package/releaselog) module is used to locate the CHANGELOG file, and by default looks in the current working directory and has logic to locate the CHANGELOG or determine which to use if multiple are found. A different CHANGELOG directory, or a specific file path, can alternatively be specified via the CLI. The [`releaselog`](https://www.npmjs.com/package/releaselog) module is also used to pull data from the CHANGELOG 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.
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.
If either `name` or `description` specifies pulling data from the CHANGELOG and either the CHANGELOG cannot be found or the release data cannot be found in the CHANGELOG the job will report the error and fail.
Also, if the `description` retrieved from the CHANGELOG is empty the job will report the error and fail. This is almost always a CHANGELOG formatting or content issue, but there is a CLI option to allow an empty description if required.
### Environment Variables

@@ -142,7 +144,12 @@

Options:
-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
-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")
-c, --changelog <changelog> the path to the CHANGELOG to check if the release pulls data from
the CHANGELOG (default: ".")
-a, --allow-empty-changelog-desc allow an empty description when pulled from the CHANGELOG
(default: false)
-h, --help display help for command
```

@@ -149,0 +156,0 @@

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