@eighty4/changelog
Version:
Changelog utilities for CICD
49 lines (40 loc) • 1.26 kB
text/typescript
import { CliError } from './errors.ts'
// todo alt cfg with `git remote get-url origin`
export type MakeNewOpts = {
repo: string
}
export function parseArgs(args: Array<string>): MakeNewOpts {
const opts: Partial<MakeNewOpts> = {}
let shifted: string
while ((shifted = args.shift()!)) {
switch (shifted) {
case '--repo':
const repo = args.shift()
if (!!repo && /[a-z\d]*\/[a-z\d]*/.test(repo)) {
opts.repo = repo
} else {
throw new CliError(
'--repo must be a `eighty4/changelog` style GitHub repository name',
)
}
break
default:
throw new CliError(shifted + ' is not a supported arg')
}
}
if (!('repo' in opts)) {
throw new CliError('--repo is required')
}
return opts as MakeNewOpts
}
export function makeNewChangelogFromCliArgs(args: Array<string>): string {
return makeNewChangelog(parseArgs(args))
}
export function makeNewChangelog(opts: MakeNewOpts): string {
return `
- ???
[]: https://github.com/${opts.repo}/commits/main
`
}