Compare commits
2 Commits
d826b4191d
...
2e9d0d4b66
Author | SHA1 | Date | |
---|---|---|---|
2e9d0d4b66 | |||
bef10869ce |
@ -13,6 +13,8 @@ releases:
|
|||||||
- type: feat
|
- type: feat
|
||||||
desc: cutting a release also add a new NEXT release
|
desc: cutting a release also add a new NEXT release
|
||||||
commit: 167f631d1fe4eadba3ed5fdadbe378b8255d4ad2
|
commit: 167f631d1fe4eadba3ed5fdadbe378b8255d4ad2
|
||||||
|
- type: feat
|
||||||
|
desc: git-gather also filters on descs
|
||||||
- version: 0.1.0
|
- version: 0.1.0
|
||||||
changes:
|
changes:
|
||||||
- port the core of the Perl changelord to JavaScript.
|
- port the core of the Perl changelord to JavaScript.
|
||||||
|
@ -102,7 +102,7 @@ Git messages are compared to the regular expression
|
|||||||
configured at `project.commit_regex`. If none is found, it
|
configured at `project.commit_regex`. If none is found, it
|
||||||
defaults to
|
defaults to
|
||||||
|
|
||||||
^(?<type>[^: ]+):(?<desc>.*?)(\[(?<ticket>[^\]]+)\])?$
|
^(?<type>[^: ]+):\s*(?<desc>.*?)(\[(?<ticket>[^\]]+)\])?$
|
||||||
|
|
||||||
The regular expression must capture a `desc` field, and may
|
The regular expression must capture a `desc` field, and may
|
||||||
capture a `type` and `ticket` as well.
|
capture a `type` and `ticket` as well.
|
||||||
|
@ -8,6 +8,7 @@ import fs from "fs-extra";
|
|||||||
import consola from "consola";
|
import consola from "consola";
|
||||||
import u from "@yanick/updeep-remeda";
|
import u from "@yanick/updeep-remeda";
|
||||||
import { once } from "remeda";
|
import { once } from "remeda";
|
||||||
|
import simpleGit from "simple-git";
|
||||||
|
|
||||||
import print from "./command/print.js";
|
import print from "./command/print.js";
|
||||||
import init from "./command/init.js";
|
import init from "./command/init.js";
|
||||||
@ -22,6 +23,7 @@ consola.raw = (...args) => console.log(...args);
|
|||||||
|
|
||||||
yargs(hideBin(process.argv))
|
yargs(hideBin(process.argv))
|
||||||
.middleware((config) => {
|
.middleware((config) => {
|
||||||
|
config.git = once(simpleGit);
|
||||||
config.consola = consola;
|
config.consola = consola;
|
||||||
config.changelog = once(() =>
|
config.changelog = once(() =>
|
||||||
fs.readFile(config.source, "utf-8").then(yaml.parse)
|
fs.readFile(config.source, "utf-8").then(yaml.parse)
|
||||||
|
@ -2,50 +2,54 @@ import simpleGit from "simple-git";
|
|||||||
import { prop, compact, pickBy } from "remeda";
|
import { prop, compact, pickBy } from "remeda";
|
||||||
|
|
||||||
const handler = async (config) => {
|
const handler = async (config) => {
|
||||||
const next = await config.next_release();
|
const next = await config.next_release();
|
||||||
const seen_sha1s = compact(next?.changes.map(prop("commit")));
|
const seen_sha1s = compact(next?.changes.map(prop("commit")));
|
||||||
|
const seen_descs = next?.changes.map((change) =>
|
||||||
|
typeof change === "string" ? change : change.desc
|
||||||
|
);
|
||||||
|
|
||||||
const git = simpleGit();
|
const git = config.git();
|
||||||
|
|
||||||
const { version } = await config.latest_version();
|
const { version } = await config.latest_version();
|
||||||
|
|
||||||
let { all: commits } = await git.log({
|
let { all: commits } = await git.log({
|
||||||
from: "v" + version,
|
from: "v" + version,
|
||||||
});
|
});
|
||||||
|
|
||||||
config.consola.start(`gathering changes since v${version}`);
|
config.consola.start(`gathering changes since v${version}`);
|
||||||
|
|
||||||
commits = commits.filter(({ hash }) => !seen_sha1s.includes(hash));
|
commits = commits.filter(({ hash }) => !seen_sha1s.includes(hash));
|
||||||
|
|
||||||
const regex = new RegExp(
|
const regex = new RegExp(
|
||||||
(await config.changelog().project?.commit_regex) ??
|
(await config.changelog().project?.commit_regex) ??
|
||||||
/^(?<type>[^: ]+):(?<desc>.*?)(\[(?<ticket>[^\]]+)\])?$/
|
/^(?<type>[^: ]+):\s*(?<desc>.*?)(\[(?<ticket>[^\]]+)\])?$/
|
||||||
|
);
|
||||||
|
|
||||||
|
const changes = commits
|
||||||
|
.map((commit) => [commit, commit.message.match(regex)])
|
||||||
|
.filter((x) => x[1])
|
||||||
|
.filter((x) => !seen_descs.includes(x[1].groups.desc))
|
||||||
|
.map(([commit, res]) =>
|
||||||
|
pickBy({ ...res.groups, commit: commit.hash }, (x) => x)
|
||||||
);
|
);
|
||||||
|
|
||||||
const changes = commits
|
if (changes.length === 0) {
|
||||||
.map((commit) => [commit, commit.message.match(regex)])
|
config.consola.success("no changes detected");
|
||||||
.filter((x) => x[1])
|
return;
|
||||||
.map(([commit, res]) =>
|
}
|
||||||
pickBy({ ...res.groups, commit: commit.hash }, (x) => x)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (changes.length === 0) {
|
for (const change of changes) {
|
||||||
config.consola.success("no changes detected");
|
config.consola.info(`${change.type}: ${change.desc}`);
|
||||||
return;
|
config.add_to_next(change);
|
||||||
}
|
}
|
||||||
|
config.consola.success("done");
|
||||||
for (const change of changes) {
|
|
||||||
config.consola.info(`${change.type}: ${change.desc}`);
|
|
||||||
config.add_to_next(change);
|
|
||||||
}
|
|
||||||
config.consola.success("done");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
command: "git-gather",
|
command: "git-gather",
|
||||||
desc: "gather change entries from git commits",
|
desc: "gather change entries from git commits",
|
||||||
builder: (yargs) => {
|
builder: (yargs) => {
|
||||||
yargs;
|
yargs;
|
||||||
},
|
},
|
||||||
handler,
|
handler,
|
||||||
};
|
};
|
||||||
|
28
src/command/git-gather.test.js
Normal file
28
src/command/git-gather.test.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import { test, expect, vi } from "vitest";
|
||||||
|
import gather from "./git-gather.js";
|
||||||
|
|
||||||
|
test("no changes detected", async () => {
|
||||||
|
const changelog = {
|
||||||
|
releases: [{ version: "NEXT", changes: [] }, { version: "1.0.0" }],
|
||||||
|
};
|
||||||
|
|
||||||
|
const noop = () => {};
|
||||||
|
const config = {
|
||||||
|
consola: {
|
||||||
|
start: noop,
|
||||||
|
success: vi.fn(),
|
||||||
|
},
|
||||||
|
changelog: () => changelog,
|
||||||
|
next_release: () => ({
|
||||||
|
changes: [],
|
||||||
|
}),
|
||||||
|
latest_version: () => ({ version: "1.2.3" }),
|
||||||
|
git: () => ({
|
||||||
|
log: () => ({ all: [] }),
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
await gather.handler(config);
|
||||||
|
|
||||||
|
expect(config.consola.success).toHaveBeenCalledWith("no changes detected");
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user