### Full configuration example for changelogithub Source: https://github.com/antfu/changelogithub/blob/main/_autodocs/quick-reference.md A comprehensive example of `defineConfig` showing all available options for git references, repository settings, GitHub integration, release metadata, output formatting, and customization. ```typescript export default defineConfig({ // Git references from: 'v1.0.0', to: 'v2.0.0', // Repository repo: 'owner/repo', releaseRepo: 'owner/releases', // For monorepos // GitHub token: process.env.GITHUB_TOKEN, baseUrl: 'github.com', baseUrlApi: 'api.github.com', // Release metadata name: 'Version 2.0', draft: false, prerelease: false, // Output formatting style: 'markdown', // or 'plain' emoji: true, capitalize: true, contributors: true, group: true, // Customization tag: 'v%s', assets: ['dist/*.js', 'dist/*.css'], titles: { breakingChanges: '🚨 Breaking Changes' }, scopeMap: { 'api': 'API', 'ui': 'User Interface' }, types: { feat: { title: '🚀 Features' }, fix: { title: '🐞 Bug Fixes' }, perf: { title: '🏎 Performance' } } }) ``` -------------------------------- ### Install changelogithub Source: https://github.com/antfu/changelogithub/blob/main/_autodocs/quick-reference.md Install the package using npm or use it directly with npx. ```bash npm install changelogithub # or use directly npx changelogithub ``` -------------------------------- ### Example Changelogithub Configuration Source: https://github.com/antfu/changelogithub/blob/main/_autodocs/README.md An example configuration file for changelogithub using TypeScript. This demonstrates how to set options like contributors, emoji usage, grouping, and scope mapping. ```typescript import { defineConfig } from 'changelogithub' export default defineConfig({ contributors: true, emoji: true, group: true, scopeMap: { 'api': 'API', 'ui': 'User Interface' } }) ``` -------------------------------- ### Install changelogithub Source: https://github.com/antfu/changelogithub/blob/main/_autodocs/cli.md Install the changelogithub CLI globally using npm or use it directly with npx. ```bash npm install -g changelogithub # or use directly npx changelogithub ``` -------------------------------- ### Example Configuration in package.json Source: https://github.com/antfu/changelogithub/blob/main/_autodocs/configuration.md Shows how to configure changelog generation directly within the package.json file. This is a convenient way to set basic options for the project. ```json { "changelogithub": { "contributors": true, "emoji": true, "group": true, "style": "markdown" } } ``` -------------------------------- ### Example Conventional Commits Source: https://github.com/antfu/changelogithub/blob/main/_autodocs/README.md Provides examples of valid conventional commit messages. These demonstrate different types, scopes, and breaking change indicators. ```text feat(api): add new endpoint fix(ui): correct button alignment docs: update README perf!: remove deprecated API feat!: redesign architecture ``` -------------------------------- ### Monorepo Setup Source: https://github.com/antfu/changelogithub/blob/main/_autodocs/cli.md Configure the CLI to use one GitHub repository for generating the changelog while tagging releases in another repository, suitable for monorepos. ```bash changelogithub --github owner/main-repo --release-github owner/releases-repo ``` -------------------------------- ### Example Configuration File (changelogithub.config.ts) Source: https://github.com/antfu/changelogithub/blob/main/_autodocs/configuration.md Demonstrates how to configure changelog generation using a TypeScript configuration file. This file allows for detailed customization of release titles, scope mapping, and commit type definitions. ```typescript import { defineConfig } from 'changelogithub' export default defineConfig({ contributors: true, capitalize: true, emoji: true, group: true, tag: 'v%s', style: 'markdown', titles: { breakingChanges: '🚨 Breaking Changes' }, scopeMap: { 'core': 'Core', 'api': 'API', 'ui': 'User Interface' } }) ``` -------------------------------- ### Example Type Configuration Source: https://github.com/antfu/changelogithub/blob/main/_autodocs/configuration.md Shows how to define custom commit types for grouping conventional commits in the changelog. Only types defined here will be included in the output. ```typescript types: { feat: { title: '🚀 Features' }, fix: { title: '🐞 Bug Fixes' }, perf: { title: '🏎 Performance' }, docs: { title: '📚 Documentation' } } ``` -------------------------------- ### Example Scope Mapping Source: https://github.com/antfu/changelogithub/blob/main/_autodocs/configuration.md Demonstrates how to use the `scopeMap` option to rename scope names in the changelog. This allows for more user-friendly display names for different parts of the project. ```typescript scopeMap: { 'auth': 'Authentication', 'db': 'Database', 'api': 'API' } ``` -------------------------------- ### Handle Cannot Parse GitHub Repo Error Source: https://github.com/antfu/changelogithub/blob/main/_autodocs/errors.md This example shows how an invalid remote origin URL that does not match the expected GitHub format will cause an error when trying to get the GitHub repository information. ```bash # If repository isn't a GitHub repo git remote -v # Shows: origin https://example.com/repo.git await getGitHubRepo('github.com') # Throws error ``` -------------------------------- ### Get All Git Tags Source: https://github.com/antfu/changelogithub/blob/main/_autodocs/README.md Retrieves a list of all tags present in the git repository. ```typescript getGitTags(): Promise ``` -------------------------------- ### Get Release by Tag Source: https://github.com/antfu/changelogithub/blob/main/_autodocs/endpoints.md Checks if a release already exists for a given tag. Requires authentication and specific headers. ```APIDOC ## GET /repos/{owner}/{repo}/releases/tags/{tag} ### Description Check if a release already exists for the current tag. ### Method GET ### Endpoint `/repos/{owner}/{repo}/releases/tags/{tag}` ### Request Example ```http GET https://api.github.com/repos/antfu/changelogithub/releases/tags/v2.0.0 Authorization: token ghp_xxxx Accept: application/vnd.github.v3+json ``` ### Response #### Success Response (200 OK) - **id** (integer) - The release ID. - **url** (string) - The API URL for the release. - **html_url** (string) - The URL to the release on GitHub. - **upload_url** (string) - The URL for uploading assets. - **tag_name** (string) - The name of the tag. - **name** (string) - The display name of the release. - **body** (string) - The release notes. - **draft** (boolean) - Whether the release is a draft. - **prerelease** (boolean) - Whether the release is a prerelease. - **created_at** (string) - The timestamp when the release was created. - **published_at** (string) - The timestamp when the release was published. #### Response Example ```json { "id": 123456, "url": "https://api.github.com/repos/antfu/changelogithub/releases/123456", "html_url": "https://github.com/antfu/changelogithub/releases/tag/v2.0.0", "upload_url": "https://uploads.github.com/repos/antfu/changelogithub/releases/123456/assets{?name,label}", "tag_name": "v2.0.0", "name": "v2.0.0", "body": "...", "draft": false, "prerelease": false, "created_at": "2024-01-01T00:00:00Z", "published_at": "2024-01-01T00:00:00Z" } ``` #### Response Example (404 Not Found) Release doesn't exist yet. ``` -------------------------------- ### GET Release by Tag Source: https://github.com/antfu/changelogithub/blob/main/_autodocs/endpoints.md Checks if a release already exists for a given tag. Requires a GitHub token in the Authorization header. ```http GET https://api.github.com/repos/antfu/changelogithub/releases/tags/v2.0.0 Authorization: token ghp_xxxx Accept: application/vnd.github.v3+json ``` -------------------------------- ### Get GitHub Repository from Git Config Source: https://github.com/antfu/changelogithub/blob/main/_autodocs/README.md Retrieves the GitHub repository information from the local git configuration. ```typescript getGitHubRepo(baseUrl: string): Promise ``` -------------------------------- ### Custom Formatting Options Source: https://github.com/antfu/changelogithub/blob/main/_autodocs/quick-reference.md Control the output style and content using flags like `--style`, `--emoji`, and `--group`. For example, use `--style plain` for email-friendly text. ```bash # Plain text for emails changelogithub --style plain # Without emoji changelogithub --emoji false # Group all scopes changelogithub --group true ``` -------------------------------- ### GitHub Actions Workflow for Release Source: https://github.com/antfu/changelogithub/blob/main/README.md Integrate changelogithub into your GitHub Actions to automatically generate release notes when a new tag is pushed. Ensure you have the necessary permissions and node setup. ```yaml # .github/workflows/release.yml name: Release permissions: contents: write on: push: tags: - 'v*' jobs: release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 with: fetch-depth: 0 - name: Set node uses: actions/setup-node@v6 with: registry-url: https://registry.npmjs.org/ node-version: lts/* - run: npx changelogithub # or changelogithub@0.12 to ensure a stable result env: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} ``` -------------------------------- ### Handle GitHub API Authentication Errors Source: https://github.com/antfu/changelogithub/blob/main/_autodocs/errors.md This example demonstrates how an invalid or expired GitHub token will lead to a 401 Unauthorized error when interacting with the GitHub API. ```bash GITHUB_TOKEN=invalid_token npx changelogithub # Throws: 401 Unauthorized from GitHub API ``` -------------------------------- ### Basic Usage Source: https://github.com/antfu/changelogithub/blob/main/_autodocs/cli.md Generate a changelog for the current repository. Ensure the GITHUB_TOKEN environment variable is set. ```bash changelogithub ``` -------------------------------- ### Normalize Tag Template Source: https://github.com/antfu/changelogithub/blob/main/_autodocs/INDEX.md Get a normalized tag template string using getSafeTagTemplate. ```typescript import { getSafeTagTemplate } from 'changelogithub/git' const tagTemplate = await getSafeTagTemplate() console.log(tagTemplate) ``` -------------------------------- ### Changelogithub CLI essential options Source: https://github.com/antfu/changelogithub/blob/main/_autodocs/quick-reference.md Lists essential command-line options for changelogithub, including token, dry run, output path, and style. ```bash --token # GitHub token (or GITHUB_TOKEN env) --dry # Preview only --output # Save to file --style