-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: git cliff programmatic api
- Loading branch information
Showing
1 changed file
with
17 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
import { doActionAndLog, getGitHubRepo, getGitHubToken, getGitRootDirection, resolveTagTemplate } from '#lib/utils'; | ||
import { isNullishOrEmpty } from '@sapphire/utilities'; | ||
import type { Options } from 'commander'; | ||
import { execSync } from 'node:child_process'; | ||
import { runGitCliff, type Options as GitCliffOptions } from 'git-cliff'; | ||
|
||
export function updateChangelog(options: Options, newVersion: string) { | ||
const repositoryRootDirectory = getGitRootDirection(); | ||
|
||
resolveTagTemplate(options, newVersion); | ||
|
||
return doActionAndLog('Updating Changelog', () => { | ||
return doActionAndLog('Updating Changelog', async () => { | ||
if (!options.dryRun) { | ||
const monoRepoConfig = isNullishOrEmpty(repositoryRootDirectory) | ||
? '' | ||
: `-r ${repositoryRootDirectory}/ --include-path "${options.packagePath}/*"`; | ||
let githubConfig = ''; | ||
const gitCliffOptions: GitCliffOptions = { | ||
tag: options.tagTemplate, | ||
prepend: './CHANGELOG.md', | ||
unreleased: true, | ||
config: './cliff.toml' | ||
}; | ||
|
||
if (!isNullishOrEmpty(repositoryRootDirectory)) { | ||
gitCliffOptions.repository = repositoryRootDirectory; | ||
gitCliffOptions.includePath = `${options.packagePath}/*`; | ||
} | ||
|
||
const githubToken = getGitHubToken(options); | ||
const githubRepo = getGitHubRepo(options); | ||
if (!isNullishOrEmpty(githubRepo) && !isNullishOrEmpty(githubToken)) { | ||
const resolvedGitHubRepo = githubRepo === 'auto' ? `${options.org}/${options.name}` : `${githubRepo}`; | ||
githubConfig = `--github-repo ${resolvedGitHubRepo} --github-token ${githubToken}`; | ||
|
||
gitCliffOptions.githubRepo = resolvedGitHubRepo; | ||
gitCliffOptions.githubToken = githubToken; | ||
} | ||
|
||
execSync(`npx git-cliff --tag ${options.tagTemplate} --prepend ./CHANGELOG.md -u -c ./cliff.toml ${githubConfig} ${monoRepoConfig}`); | ||
await runGitCliff(gitCliffOptions, { stdio: 'ignore' }); | ||
} | ||
}); | ||
} |