The conventional-gitlab-releaser package creates GitLab releases from git metadata using conventional changelog patterns. It integrates with conventional-changelog to parse commit messages and generate structured release notes, supporting both GitLab.com and self-hosted GitLab instances with API v3 and v4 compatibility.
Creates GitLab releases from conventional commits with GitLab-specific features.
/**
* Creates GitLab releases from conventional commits
* @param {Object} auth - Authentication configuration
* @param {string} auth.token - GitLab Personal Access Token or API token
* @param {string} [auth.url] - GitLab instance URL, defaults to 'https://gitlab.com'
* @param {Object} [changelogOpts] - Changelog generation options
* @param {string} [changelogOpts.preset] - Commit convention preset (angular, atom, codemirror, ember, eslint, express, jquery, jscs, jshint)
* @param {number} [changelogOpts.releaseCount=1] - Number of releases to generate (0 = regenerate all)
* @param {string} [changelogOpts.config] - Path to config script file
* @param {Object} [changelogOpts.pkg] - Package configuration
* @param {string} [changelogOpts.pkg.path] - Path to package.json file
* @param {Function} [changelogOpts.debug] - Debug logging function
* @param {Function} [changelogOpts.warn] - Warning logging function
* @param {Object} [context] - Template context variables
* @param {string} context.owner - GitLab namespace/user/group
* @param {string} context.repository - GitLab project name
* @param {Object} [gitRawCommitsOpts] - Git commit parsing options
* @param {string} [gitRawCommitsOpts.from] - Starting commit/tag (based on releaseCount by default)
* @param {string} [gitRawCommitsOpts.to] - Ending commit/tag (defaults to latest semver tag)
* @param {Object} [parserOpts] - Commit message parser options
* @param {Object} [writerOpts] - Changelog writer options
* @param {Function} callback - Callback function (err, responses) => {}
* @returns {void} Results returned via callback
*/
function conventionalGitlabReleaser(
auth,
changelogOpts,
context,
gitRawCommitsOpts,
parserOpts,
writerOpts,
callback
);Usage Examples:
const conventionalGitlabReleaser = require('conventional-gitlab-releaser');
// Minimal usage with required parameters
conventionalGitlabReleaser({
token: process.env.GITLAB_TOKEN
}, {
preset: 'angular'
}, (err, responses) => {
if (err) throw err;
console.log(`Created ${responses.length} releases`);
});
// Advanced usage with GitLab.com
conventionalGitlabReleaser({
token: process.env.GITLAB_TOKEN,
url: 'https://gitlab.com'
}, {
preset: 'angular',
releaseCount: 3,
pkg: { path: './package.json' },
debug: console.log,
warn: console.warn
}, {
owner: 'mygroup',
repository: 'myproject'
}, {
from: 'v1.0.0',
to: 'v2.0.0'
}, null, {
includeDetails: true,
headerPartial: ''
}, (err, responses) => {
if (err) {
console.error('Release creation failed:', err);
return;
}
responses.forEach((response, index) => {
console.log(`Release ${index + 1}:`, response.body.web_url);
});
});
// Self-hosted GitLab instance
conventionalGitlabReleaser({
token: process.env.GITLAB_TOKEN,
url: 'https://gitlab.company.com'
}, {
preset: 'angular'
}, (err, responses) => {
if (err) {
console.error('Release creation failed:', err);
return;
}
console.log('Successfully created releases on self-hosted GitLab');
});Full-featured CLI providing access to all library functionality.
# Usage: conventional-gitlab-releaser [options]
#
# Options:
# -u, --url <url> GitLab instance URL (default: 'https://gitlab.com')
# -t, --token <token> GitLab authentication token
# -p, --preset <preset> Commit convention preset (angular, atom, codemirror, ember, eslint, express, jquery, jscs, jshint)
# -k, --pkg <path> Path to package.json file
# -r, --release-count <number> Number of releases to generate (default: 1, 0 = regenerate all)
# -v, --verbose Enable verbose output for debugging
# -n, --config <path> Path to config script file
# -c, --context <path> Path to context variables scriptEnvironment Variables:
CONVENTIONAL_GITLAB_RELEASER_TOKEN: GitLab auth token (alternative to --token)CONVENTIONAL_GITLAB_URL: GitLab URL (alternative to --url)Usage Examples:
# Basic usage with angular preset
conventional-gitlab-releaser -p angular -t your-gitlab-token
# Generate all releases from git history
conventional-gitlab-releaser -p angular -r 0
# Verbose output for debugging
conventional-gitlab-releaser -p angular -v
# Custom package.json location
conventional-gitlab-releaser -p angular -k ./packages/my-package/package.json
# Using environment variables
export CONVENTIONAL_GITLAB_RELEASER_TOKEN="your-token"
conventional-gitlab-releaser -p angular
# Self-hosted GitLab instance
conventional-gitlab-releaser -p angular -u https://gitlab.company.com
# Using custom config file
conventional-gitlab-releaser -n ./my-config.js -c ./my-context.jsProcesses git commit chunks to extract version information and format dates (identical to GitHub releaser).
/**
* Transforms git commit chunks for changelog processing
* @param {Object} chunk - Git commit chunk object
* @param {string} chunk.gitTags - Git tag information from git log
* @param {string} chunk.committerDate - Commit date
* @param {Function} callback - Node.js style callback (err, transformedChunk) => {}
* @returns {void} Results returned via callback
*/
function transform(chunk, callback);Usage Example:
const transform = require('conventional-gitlab-releaser/src/transform');
const gitChunk = {
gitTags: ' (tag: v1.2.3, origin/master)',
committerDate: 'June 8, 2012'
};
transform(gitChunk, (err, transformedChunk) => {
if (err) throw err;
console.log(transformedChunk.version); // 'v1.2.3'
console.log(transformedChunk.committerDate); // '2012-06-08'
});/**
* GitLab authentication configuration object
*/
interface GitLabAuthConfig {
/** GitLab Personal Access Token or API token */
token: string;
/** GitLab instance URL, defaults to 'https://gitlab.com' */
url?: string;
}
/**
* GitLab-specific changelog generation options
*/
interface GitLabChangelogOptions {
/** Commit convention preset name */
preset?: 'angular' | 'atom' | 'codemirror' | 'ember' | 'eslint' | 'express' | 'jquery' | 'jscs' | 'jshint';
/** Number of releases to generate (0 = regenerate all) */
releaseCount?: number;
/** Path to config script file */
config?: string;
/** Package configuration */
pkg?: {
/** Path to package.json file */
path?: string;
};
/** Debug logging function */
debug?: Function;
/** Warning logging function */
warn?: Function;
}
/**
* GitLab API response for release creation
*/
interface GitLabReleaseResponse {
/** HTTP status code */
statusCode: number;
/** Response body containing release data */
body: {
/** Tag name */
tag_name: string;
/** Description */
description: string;
/** Release name */
name: string;
/** Created date */
created_at: string;
/** Release URL */
web_url?: string;
/** Commit SHA */
commit?: {
id: string;
short_id: string;
title: string;
author_name: string;
author_email: string;
authored_date: string;
committer_name: string;
committer_email: string;
committed_date: string;
message: string;
web_url: string;
};
};
}
/**
* Callback function type for GitLab release operations
*/
type GitLabReleaseCallback = (
err: Error | null,
responses?: GitLabReleaseResponse[]
) => void;# Library usage
npm install conventional-gitlab-releaser
# Global CLI usage
npm install -g conventional-gitlab-releaserThe tool requires a GitLab Personal Access Token or API token with appropriate permissions:
api scope for full access or read_api + read_repository + write_repository for minimal permissions# Environment variable (recommended)
export CONVENTIONAL_GITLAB_RELEASER_TOKEN="your-token-here"
# Or via CLI flag
conventional-gitlab-releaser -t your-token-here -p angularYour repository must have:
v1.0.0, v1.2.3)The tool automatically detects and adapts to GitLab API versions:
This ensures compatibility with both modern and legacy GitLab instances.
Works seamlessly with self-hosted GitLab instances:
conventionalGitlabReleaser({
token: process.env.GITLAB_TOKEN,
url: 'https://gitlab.company.com'
}, options, callback);# CLI
conventional-gitlab-releaser -p angular -u https://gitlab.company.comThe tool properly handles GitLab project paths with special characters by URL-encoding namespace/project combinations:
mygroup/myproject → mygroup%2Fmyprojectuser.name/project-name → user.name%2Fproject-nameGitLab releases are created by:
The release description contains the generated changelog content from conventional commits.
The GitLab releaser handles several types of errors:
Required Parameter Errors:
Error('Expected an auth object') if auth parameter is missingError('Expected an callback') if callback parameter is missingGit Repository Errors:
Error('No semver tags found') via callback if repository has no semantic version tagsGitLab API Errors:
Configuration Errors:
Example Error Handling:
conventionalGitlabReleaser(auth, options, (err, responses) => {
if (err) {
switch (err.message) {
case 'No semver tags found':
console.error('Repository needs semantic version tags (e.g., v1.0.0)');
break;
default:
if (err.statusCode === 401) {
console.error('Invalid GitLab token or insufficient permissions');
} else if (err.statusCode === 403) {
console.error('Access denied - check project permissions');
} else if (err.statusCode === 404) {
console.error('Project not found or access denied');
} else if (err.statusCode === 429) {
console.error('GitLab API rate limit exceeded');
} else {
console.error('Unexpected error:', err.message);
}
}
return;
}
// Process successful responses
console.log(`Successfully created ${responses.length} releases`);
});The GitLab CLI doesn't include:
-d, --draft flag (not supported by GitLab)https://gitlab.com vs https://api.github.com)CONVENTIONAL_GITLAB_* vs CONVENTIONAL_GITHUB_*)