Skip to content

Commit

Permalink
feat: support templates for commit and tag messages (#68)
Browse files Browse the repository at this point in the history
* feat: config with commit, tag message

* refactor: move to templates

* use replaceAll

* simplify template convention

(also consitent with nitropack)

---------

Co-authored-by: Pooya Parsa <[email protected]>
  • Loading branch information
aa900031 and pi0 authored Mar 28, 2023
1 parent 602a440 commit f9eff68
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/commands/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,22 @@ export default async function defaultMain(args: Argv) {
(f) => f && typeof f === "string"
) as string[];
await execa("git", ["add", ...filesToAdd], { cwd });
await execa(
"git",
["commit", "-m", `chore(release): v${config.newVersion}`],
{ cwd }
const msg = config.templates.commitMessage.replaceAll(
"{{newVersion}}",
config.newVersion
);
await execa("git", ["commit", "-m", msg], { cwd });
}
if (args.tag !== false) {
await execa(
"git",
["tag", "-am", "v" + config.newVersion, "v" + config.newVersion],
{ cwd }
const msg = config.templates.tagMessage.replaceAll(
"{{newVersion}}",
config.newVersion
);
const body = config.templates.tagBody.replaceAll(
"{{newVersion}}",
config.newVersion
);
await execa("git", ["tag", "-am", msg, body], { cwd });
}
if (args.push === true) {
await execa("git", ["push", "--follow-tags"], { cwd });
Expand Down
10 changes: 10 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export interface ChangelogConfig {
to: string;
newVersion?: string;
output: string | boolean;
templates: {
commitMessage?: string;
tagMessage?: string;
tagBody?: string;
};
}

const getDefaultConfig = () =>
Expand Down Expand Up @@ -44,6 +49,11 @@ const getDefaultConfig = () =>
process.env.GITHUB_TOKEN ||
process.env.GH_TOKEN,
},
templates: {
commitMessage: "chore(release): v{{newVersion}}",
tagMessage: "v{{newVersion}}",
tagBody: "v{{newVersion}}",
},
};

export async function loadChangelogConfig(
Expand Down

0 comments on commit f9eff68

Please sign in to comment.