UNPKG

commit-parser

Version:

A tiny parser for conventional commits that extracts metadata like type, scope, breaking changes and references

77 lines 2.32 kB
//#region src/types.d.ts interface GitCommitAuthor { name: string; email: string; } interface RawGitCommit { message: string; body: string; shortHash: string; author: GitCommitAuthor; data: string; } interface Reference { type: "issue" | "pull-request"; value: string; } interface GitCommit extends Omit<RawGitCommit, "author"> { isConventional: boolean; description: string; type: string; scope: string; references: Reference[]; authors: GitCommitAuthor[]; isBreaking: boolean; } //#endregion //#region src/commits.d.ts interface GetCommitsOptions { /** * The starting reference (commit, branch, tag). If undefined, it will fetch commits up to the `to` reference. * @default undefined */ from?: string; /** * The ending reference. Defaults to "HEAD". * @default "HEAD" */ to?: string; /** * The current working directory where the git command will be executed. * If not provided, the command will run in the process's current directory. * @default process.cwd() */ cwd?: string; /** * The folder to provide to the git command. * This is useful when you only want to retrieve commits from a specific folder. * @default undefined */ folder?: string; } /** * Retrieves a list of parsed git commits between two points in history. * * @param {GetCommitsOptions} options - Options for fetching and parsing git commits. * * @returns {GitCommit[]} An array of parsed GitCommit objects. */ declare function getCommits(options: GetCommitsOptions): GitCommit[]; //#endregion //#region src/parse.d.ts /** * Parses a raw git commit string into a structured format. * * @param {string} commit - A raw git commit string delimited by '|' character * @returns {RawGitCommit} A structured representation of the git commit */ declare function parseRawCommit(commit: string): RawGitCommit; /** * Parses a raw git commit into a structured format with additional metadata * * @param {RawGitCommit} rawCommit - The raw git commit to parse * @returns {GitCommit} A structured representation of the git commit with additional metadata */ declare function parseCommit(rawCommit: RawGitCommit): GitCommit; //#endregion export { GetCommitsOptions, GitCommit, GitCommitAuthor, RawGitCommit, Reference, getCommits, parseCommit, parseRawCommit };