npm.io
1.7.0 • Published 17h agoCLI

pull-request-changelog

Licence
MIT
Version
1.7.0
Deps
3
Size
393 kB
Vulns
0
Weekly
0

pull-request-changelog

Add a sticky comment to a pull request with the changelog entries for the new commits.

Features:

  • Github action for easy integration with Github.
  • CLI and API for custom usage.
  • Supports both Conventional Changelog presets or a custom configuration.
  • Works with Semantic Release

example comment

Create a workflow with these steps:

on:
  pull_request:

permissions:
  pull-requests: write

jobs:
  pr-changelog:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          ref: "${{ github.head_ref }}"
      - uses: actions/setup-node@v4
        with:
          node-version: 22.x
      - run: npm ci
      - name: Pull Requst Changelog
        uses: ext/pull-request-changelog@v1
        with:
          preset: conventional-changelog-conventionalcommits

Node 22.x or later is required, make sure to specify node-version!

If you want to only run for pull requests targeting certain branches add:

 on:
   pull_request:
+    branches:
+      - main

Configuration

The following input parameters are provided, which can be passed to the with parameter. All parameters are optional.

Input parameter Default Description
preset full name of an NPM package with a conventional changelog preset
config path to a configuration file exporting a configuration
template-dir directory with templates
filename "pr-changelog.md" name of temporary file generated by script
comment true If true a sticky comment will be added with the changelog.
comment-id "pull-request-changelog" id passed to sticky-pull-request-commend
fetch-depth 100 git commit depth
version "auto" NPM script version (passed to npx). Default is to use same script version as action version.
skip-install Skip installing NPM package (you need to manually ensure the package exists)

Usage with CLI

npx pull-request-changelog \
  --preset conventional-changelog-conventionalcommits \
  --from origin/main \
  --to HEAD

Do note that the full name of the preset must be specified, this is different to how conventional-changelog-cli handles -p.

Generate changelog from conventional changelog for using in a pull request comment.

Usage
  $ npx pull-request-changelog -f origin/main

Options
  --from, -f          Base branch/ref
  --to, -t            Pull request branch/ref (default: HEAD)
  --preset, -p        Conventional Changelog preset (NPM package)
  --config, -c        Conventional Changelog config (filename)
  --output, -o        Output file (default stdout)
  --template-dir, -T  Template directory

Other
  --help      Show usage
  --version   Show version

The template directory may contain the files:

- message.hbs for the main template
- header.hbs for the header partial
- footer.hbs for the footer partial

If you need to customize the configuration for the conventional-changelog preset create a new file default exporting a function wrapping the preset and use --config instead:

import conventionalChangelogConventionalcommits from "conventionallchangelog-conventionalcommits";

export default () => {
  return conventionalChangelogConventionalcommits({/* preset configuration */});
};
 npx pull-request-changelog \
-  --preset conventional-changelog-conventionalcommits \
+  --config my-config.mjs \
   --from origin/main \
   --to HEAD

Usage with API

import { pullRequestChangelog } from "pull-request-changelog";
import conventionalChangelogConventionalcommits from "conventionallchangelog-conventionalcommits";

const markdown = await pullRequestChangelog({
  config: conventionalChangelogConventionalcommits({/* preset configuration */}),
  git: {
    from: "origin/main",
    to: "HEAD",
  },
});

Keywords