Generate Beautiful Changelogs using Conventional Commits
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Full GitHub API integration for creating, updating, and synchronizing releases with changelog content. This module provides comprehensive GitHub release management capabilities with automatic authentication resolution and error handling.
Synchronizes a release with GitHub, creating or updating releases as needed.
/**
* Sync release with GitHub, creating or updating as needed
* @param config - Resolved changelog configuration with GitHub settings
* @param release - Release information with version and body
* @returns Result object with status and relevant URLs/IDs
*/
function syncGithubRelease(
config: ResolvedChangelogConfig,
release: { version: string; body: string }
): Promise<{
status: "created" | "updated" | "manual";
id?: string;
url?: string;
error?: any;
}>;Usage Examples:
import { syncGithubRelease, loadChangelogConfig } from "changelogen";
const config = await loadChangelogConfig(process.cwd());
const release = {
version: "1.2.0",
body: "## Changes\n- Add new feature\n- Fix bug"
};
const result = await syncGithubRelease(config, release);
switch (result.status) {
case "created":
console.log(`Release created with ID: ${result.id}`);
break;
case "updated":
console.log(`Release updated with ID: ${result.id}`);
break;
case "manual":
console.log(`Manual action required: ${result.url}`);
if (result.error) {
console.error("Error:", result.error);
}
break;
}Creates a new GitHub release.
/**
* Create a new GitHub release
* @param config - Resolved changelog configuration with GitHub API access
* @param body - GitHub release object with release details
* @returns Promise resolving to created release object
*/
function createGithubRelease(
config: ResolvedChangelogConfig,
body: GithubRelease
): Promise<GithubRelease>;Updates an existing GitHub release.
/**
* Update an existing GitHub release
* @param config - Resolved changelog configuration with GitHub API access
* @param id - GitHub release ID to update
* @param body - Updated GitHub release object
* @returns Promise resolving to updated release object
*/
function updateGithubRelease(
config: ResolvedChangelogConfig,
id: string,
body: GithubRelease
): Promise<GithubRelease>;Usage Examples:
import {
createGithubRelease,
updateGithubRelease,
getGithubReleaseByTag
} from "changelogen";
// Create new release
const newRelease = await createGithubRelease(config, {
tag_name: "v1.2.0",
name: "v1.2.0",
body: "Release notes here...",
draft: false,
prerelease: false
});
// Update existing release
const existingRelease = await getGithubReleaseByTag(config, "v1.2.0");
const updatedRelease = await updateGithubRelease(config, existingRelease.id, {
...existingRelease,
body: "Updated release notes..."
});Retrieves all GitHub releases for the repository.
/**
* List all GitHub releases for the repository
* @param config - Resolved changelog configuration with repository info
* @returns Promise resolving to array of GitHub releases
*/
function listGithubReleases(
config: ResolvedChangelogConfig
): Promise<GithubRelease[]>;Retrieves a specific GitHub release by tag name.
/**
* Get a specific GitHub release by tag name
* @param config - Resolved changelog configuration
* @param tag - Git tag name (e.g., "v1.2.0")
* @returns Promise resolving to GitHub release object
*/
function getGithubReleaseByTag(
config: ResolvedChangelogConfig,
tag: string
): Promise<GithubRelease>;Usage Examples:
import {
listGithubReleases,
getGithubReleaseByTag
} from "changelogen";
// List all releases
const releases = await listGithubReleases(config);
console.log(`Found ${releases.length} releases`);
releases.forEach(release => {
console.log(`${release.tag_name}: ${release.name}`);
});
// Get specific release
try {
const release = await getGithubReleaseByTag(config, "v1.2.0");
console.log(`Release v1.2.0: ${release.body}`);
} catch (error) {
console.log("Release v1.2.0 not found");
}Retrieves the raw CHANGELOG.md file from the GitHub repository.
/**
* Get raw CHANGELOG.md content from GitHub repository
* @param config - Resolved changelog configuration with repository info
* @returns Promise resolving to raw changelog content
*/
function getGithubChangelog(
config: ResolvedChangelogConfig
): Promise<string>;Generates a GitHub URL for manual release creation.
/**
* Generate GitHub URL for manual release creation
* @param config - Resolved changelog configuration
* @param release - Release information for URL generation
* @returns Pre-filled GitHub release creation URL
*/
function githubNewReleaseURL(
config: ResolvedChangelogConfig,
release: { version: string; body: string }
): string;Usage Examples:
import { githubNewReleaseURL } from "changelogen";
const releaseUrl = githubNewReleaseURL(config, {
version: "1.2.0",
body: "Release notes here..."
});
console.log(`Manual release URL: ${releaseUrl}`);
// Opens pre-filled release creation form in browserAutomatic GitHub token resolution from multiple sources.
/**
* Resolve GitHub authentication token from various sources
* @param config - Resolved changelog configuration
* @returns Promise resolving to GitHub token or undefined
*/
function resolveGithubToken(
config: ResolvedChangelogConfig
): Promise<string | undefined>;Token Sources (in order of precedence):
Environment Variables:
CHANGELOGEN_TOKENS_GITHUBGITHUB_TOKENGH_TOKENConfiguration Files:
~/.changelogrc with tokens.githubGitHub CLI:
~/.config/gh/hosts.yml (when authenticated with gh auth login)CLI Arguments:
--token flag in CLI commandsUsage Examples:
import { resolveGithubToken } from "changelogen";
// Automatic token resolution
const token = await resolveGithubToken(config);
if (token) {
console.log("GitHub token found");
config.tokens.github = token;
} else {
console.log("No GitHub token available - manual release required");
}interface GithubRelease {
/** GitHub release ID (set by GitHub API) */
id?: string;
/** Git tag name for the release */
tag_name: string;
/** Display name for the release */
name?: string;
/** Markdown body content for the release */
body?: string;
/** Whether this is a draft release */
draft?: boolean;
/** Whether this is a prerelease */
prerelease?: boolean;
}
interface GithubOptions {
/** Repository path in format "owner/repo" */
repo: string;
/** GitHub authentication token */
token: string;
}The GitHub integration includes a dedicated command for release management:
# Sync all releases from CHANGELOG.md
npx changelogen gh release all
# Sync specific versions
npx changelogen gh release v1.2.0 v1.1.0
# Sync latest version
npx changelogen gh release
# With custom token
npx changelogen gh release --token ghp_xxxxxxxxxxxx/**
* Create or update GitHub release from changelog content
* @param config - Resolved changelog configuration
* @param release - Release information with version and body
* @returns Promise resolving when release sync completes
*/
function githubRelease(
config: ResolvedChangelogConfig,
release: { version: string; body: string }
): Promise<void>;When GitHub authentication fails:
{ status: "manual", url: "..." } from syncGithubReleaseExample Error Handling:
import { syncGithubRelease } from "changelogen";
try {
const result = await syncGithubRelease(config, release);
if (result.status === "manual") {
console.log("GitHub API unavailable - manual release required");
console.log(`Release URL: ${result.url}`);
if (result.error) {
console.error("API Error:", result.error.message);
}
}
} catch (error) {
console.error("Failed to sync release:", error.message);
}While this module focuses on GitHub, the architecture supports multiple providers:
github.com and GitHub Enterprisegitlab.com and self-hosted instancesbitbucket.orgRepository Configuration:
interface RepoConfig {
domain?: string; // "github.com", "gitlab.example.com"
repo?: string; // "user/repository"
provider?: RepoProvider; // "github", "gitlab", "bitbucket"
token?: string; // Authentication token
}Install with Tessl CLI
npx tessl i tessl/npm-changelogen