or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

github-releaser.mdgitlab-releaser.mdindex.md
tile.json

github-releaser.mddocs/

GitHub Releaser

The conventional-github-releaser package creates GitHub releases from git metadata using conventional changelog patterns. It integrates with conventional-changelog to parse commit messages and generate structured release notes, supporting multiple commit conventions with customizable templates and filtering.

Capabilities

Release Creation

Creates GitHub releases from conventional commits with full customization options.

/**
 * Creates GitHub releases from conventional commits
 * @param {Object} auth - Authentication configuration
 * @param {string} auth.token - GitHub Personal Access Token with repo scope
 * @param {string} [auth.url] - GitHub API URL, defaults to 'https://api.github.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 {boolean} [changelogOpts.draft=false] - Create draft releases instead of published
 * @param {string} [changelogOpts.name] - Custom name for the release (defaults to version tag)
 * @param {string} [changelogOpts.targetCommitish] - Specific target_commitish for GitHub release
 * @param {Function} [changelogOpts.transform] - Custom transform function
 * @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 - GitHub repository owner
 * @param {string} context.repository - GitHub repository 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 conventionalGithubReleaser(
  auth,
  changelogOpts,
  context,
  gitRawCommitsOpts,
  parserOpts,
  writerOpts,
  callback
);

Usage Examples:

const conventionalGithubReleaser = require('conventional-github-releaser');

// Minimal usage with required parameters
conventionalGithubReleaser({
  token: process.env.GITHUB_TOKEN
}, {
  preset: 'angular'
}, (err, responses) => {
  if (err) throw err;
  console.log(`Created ${responses.length} releases`);
});

// Advanced usage with custom configuration
conventionalGithubReleaser({
  token: process.env.GITHUB_TOKEN,
  url: 'https://api.github.com'
}, {
  preset: 'angular',
  releaseCount: 3,
  draft: true,
  name: 'Custom Release Name',
  pkg: { path: './package.json' },
  debug: console.log,
  warn: console.warn
}, {
  owner: 'myorg',
  repository: 'myrepo'
}, {
  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.html_url);
  });
});

// Error handling example
conventionalGithubReleaser({
  token: 'invalid-token'
}, {
  preset: 'angular'
}, (err, responses) => {
  if (err) {
    if (err.message.includes('No semver tags found')) {
      console.error('Repository has no semantic version tags');
    } else if (err.statusCode === 401) {
      console.error('Invalid GitHub token or insufficient permissions');
    } else {
      console.error('Unexpected error:', err.message);
    }
    return;
  }
  // Handle success
});

Command Line Interface

Full-featured CLI providing access to all library functionality.

# Usage: conventional-github-releaser [options]
# 
# Options:
#   -u, --url <url>              GitHub API URL (default: 'https://api.github.com')
#   -t, --token <token>          GitHub 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 script
#   -d, --draft                  Create draft releases instead of published

Environment Variables:

  • CONVENTIONAL_GITHUB_RELEASER_TOKEN: GitHub auth token (alternative to --token)
  • CONVENTIONAL_GITHUB_URL: GitHub URL (alternative to --url)

Usage Examples:

# Basic usage with angular preset
conventional-github-releaser -p angular -t your-github-token

# Generate all releases from git history
conventional-github-releaser -p angular -r 0

# Create draft releases for review before publishing
conventional-github-releaser -p angular -d

# Verbose output for debugging
conventional-github-releaser -p angular -v

# Custom package.json location
conventional-github-releaser -p angular -k ./packages/my-package/package.json

# Using environment variables
export CONVENTIONAL_GITHUB_RELEASER_TOKEN="your-token"
conventional-github-releaser -p angular

# Custom GitHub Enterprise instance
conventional-github-releaser -p angular -u https://github.company.com/api/v3

# Using custom config file
conventional-github-releaser -n ./my-config.js -c ./my-context.js

Git Commit Transform

Processes git commit chunks to extract version information and format dates.

/**
 * 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-github-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'
});

Types

/**
 * GitHub authentication configuration object
 */
interface GitHubAuthConfig {
  /** GitHub Personal Access Token with repo scope permissions */
  token: string;
  /** GitHub API URL, defaults to 'https://api.github.com' */
  url?: string;
}

/**
 * GitHub-specific changelog generation options
 */
interface GitHubChangelogOptions {
  /** Commit convention preset name */
  preset?: 'angular' | 'atom' | 'codemirror' | 'ember' | 'eslint' | 'express' | 'jquery' | 'jscs' | 'jshint';
  /** Number of releases to generate (0 = regenerate all) */
  releaseCount?: number;
  /** Create draft releases instead of published */
  draft?: boolean;
  /** Custom name for the release (defaults to version tag) */
  name?: string;
  /** Specific target_commitish for GitHub release */
  targetCommitish?: string;
  /** Custom transform function for processing commits */
  transform?: Function;
  /** Package configuration */
  pkg?: {
    /** Path to package.json file */
    path?: string;
  };
  /** Debug logging function */
  debug?: Function;
  /** Warning logging function */
  warn?: Function;
}

/**
 * GitHub API response for release creation
 */
interface GitHubReleaseResponse {
  /** HTTP status code */
  statusCode: number;
  /** Response body containing release data */
  body: {
    /** Release ID */
    id: number;
    /** Release URL */
    html_url: string;
    /** Release tag name */
    tag_name: string;
    /** Release name */
    name: string;
    /** Release body/description */
    body: string;
    /** Whether release is a draft */
    draft: boolean;
    /** Whether release is a prerelease */
    prerelease: boolean;
    /** Created date */
    created_at: string;
    /** Published date */
    published_at: string;
    /** Target commitish */
    target_commitish: string;
  };
}

/**
 * Callback function type for GitHub release operations
 */
type GitHubReleaseCallback = (
  err: Error | null,
  responses?: GitHubReleaseResponse[]
) => void;

Installation and Setup

NPM Package Installation

# Library usage
npm install conventional-github-releaser

# Global CLI usage
npm install -g conventional-github-releaser

GitHub Token Setup

The tool requires a GitHub Personal Access Token with repo scope permissions:

  1. Go to GitHub Settings → Developer settings → Personal access tokens
  2. Generate new token with repo scope
  3. Set token via environment variable or CLI flag:
# Environment variable (recommended)
export CONVENTIONAL_GITHUB_RELEASER_TOKEN="your-token-here"

# Or via CLI flag
conventional-github-releaser -t your-token-here -p angular

Repository Requirements

Your repository must have:

  • Semantic version tags (e.g., v1.0.0, v1.2.3)
  • Conventional commit messages following chosen preset format
  • Proper git history with tagged releases

Error Handling

The GitHub releaser handles several types of errors:

Required Parameter Errors:

  • Throws Error('Expected an auth object') if auth parameter is missing
  • Throws Error('Expected an callback') if callback parameter is missing

Git Repository Errors:

  • Returns Error('No semver tags found') via callback if repository has no semantic version tags

GitHub API Errors:

  • Returns HTTP error responses for authentication failures (401)
  • Returns network errors for connectivity issues
  • Returns API rate limiting errors (403)
  • Returns repository access errors (404)

Configuration Errors:

  • Returns file system errors when config or context files cannot be loaded
  • Returns parsing errors for invalid configuration files

Example Error Handling:

conventionalGithubReleaser(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 GitHub token or insufficient permissions');
        } else if (err.statusCode === 403) {
          console.error('GitHub API rate limit exceeded');
        } else if (err.statusCode === 404) {
          console.error('Repository not found or access denied');
        } else {
          console.error('Unexpected error:', err.message);
        }
    }
    return;
  }
  
  // Process successful responses
  console.log(`Successfully created ${responses.length} releases`);
});

GitHub-specific Features

Draft Releases

GitHub supports draft releases that can be reviewed before publishing:

conventionalGithubReleaser({
  token: process.env.GITHUB_TOKEN
}, {
  preset: 'angular',
  draft: true  // Create as draft
}, callback);
# CLI
conventional-github-releaser -p angular -d

Target Commitish

Specify a particular commit or branch for the release:

conventionalGithubReleaser({
  token: process.env.GITHUB_TOKEN
}, {
  preset: 'angular',
  targetCommitish: 'develop'  // Release from develop branch
}, callback);

Prerelease Detection

The tool automatically detects prereleases based on semantic version format:

  • v1.0.0-alpha.1 → prerelease: true
  • v1.0.0-beta.2 → prerelease: true
  • v1.0.0 → prerelease: false

GitHub Enterprise Support

Works with GitHub Enterprise instances:

conventionalGithubReleaser({
  token: process.env.GITHUB_TOKEN,
  url: 'https://github.company.com/api/v3'
}, options, callback);
# CLI
conventional-github-releaser -p angular -u https://github.company.com/api/v3