Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ cli
.option('--group', 'Nest commit messages under their scopes')
.option('--dry', 'Dry run')
.option('--assets <paths...>', 'Files to upload as assets to the release. Use quotes to prevent shell glob expansion, e.g., "--assets \'dist/*.js\'"')
.option('--commit-paths [paths...]', 'Paths to filter commits by. If true, CWD will be used as the path')
.option('--style <style>', 'Style of the changelog', { default: 'markdown' })
.help()

Expand Down
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export async function resolveConfig(options: ChangelogOptions) {
// @ts-expect-error backward compatibility
config.releaseRepo = config.releaseRepo || config.releaseGithub || config.repo
config.prerelease = config.prerelease ?? isPrerelease(config.to)
config.commitPaths = config.commitPaths ?? []
if (config.commitPaths === true)
config.commitPaths = [config.cwd ?? process.cwd()]

if (typeof config.repo !== 'string')
throw new Error(`Invalid GitHub repository, expected a string but got ${JSON.stringify(config.repo)}`)
Expand Down
2 changes: 1 addition & 1 deletion src/generate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ChangelogOptions } from './types'
import { getGitDiff } from 'changelogen'
import { getGitDiff } from './git'
import { resolveConfig } from './config'
import { resolveAuthors } from './github'
import { parseCommits } from './parse'
Expand Down
34 changes: 34 additions & 0 deletions src/git.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RawGitCommit } from 'changelogen'
import semver from 'semver'

export async function getGitHubRepo(baseUrl: string) {
Expand Down Expand Up @@ -79,6 +80,39 @@ export async function getLastMatchingTag(
return tag
}

export async function getGitDiff(
from: string,
to: string,
paths: string[] = [],
): Promise<RawGitCommit[]> {
// https://git-scm.com/docs/pretty-formats
const r = await execCommand(
'git',
[
'--no-pager', 'log',
`${from ? `${from}...` : ''}${to}`,
'--pretty="----%n%s|%h|%an|%ae%n%b"',
'--name-status',
...(paths.length > 0 ? ['--', ...paths] : []),
],
);
return r
.split("----\n")
.splice(1)
.map((line) => {
const [firstLine, ..._body] = line.split("\n");
const [message, shortHash, authorName, authorEmail] =
firstLine.split("|");
const r: RawGitCommit = {
message,
shortHash,
author: { name: authorName, email: authorEmail },
body: _body.join("\n"),
};
return r;
});
}

export async function isRefGitTag(to: string) {
const { execa } = await import('execa')
try {
Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ export interface ChangelogOptions extends Partial<ChangelogenOptions> {
*/
assets?: string[] | string

/**
* Paths to filter commits by
* If true, CWD will be used as the path
*/
commitPaths?: string[] | true
/**
* Style of the changelog
* @default 'markdown'
Expand Down