Compare commits

..

No commits in common. "1c7b6158f4a4b933614bb513394472f35ba4e7c0" and "2e9d0d4b66a0530769c58e4204569d7d5dbb72e8" have entirely different histories.

11 changed files with 71 additions and 177 deletions

View File

@ -2,6 +2,7 @@ project:
name: changelord name: changelord
homepage: https://git.babyl.ca/yanick/changelord.js homepage: https://git.babyl.ca/yanick/changelord.js
with_stats: true with_stats: true
ticket_url: null
releases: releases:
- version: NEXT - version: NEXT
changes: changes:
@ -14,9 +15,6 @@ releases:
commit: 167f631d1fe4eadba3ed5fdadbe378b8255d4ad2 commit: 167f631d1fe4eadba3ed5fdadbe378b8255d4ad2
- type: feat - type: feat
desc: git-gather also filters on descs desc: git-gather also filters on descs
- type: feat
desc: add the validate command
commit: 5ba75a8e3d42f633e38c3584898ef0085c48fb04
- 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.

View File

@ -82,10 +82,6 @@ Outputs the latest non-NEXT release.
$ changelord latest-version $ changelord latest-version
3.2.0 3.2.0
### `changelord validate`
Validates the changelog source against its json schema.
### `changelord git-gather` ### `changelord git-gather`
Gathers change entries from git commits. If any are found, they are Gathers change entries from git commits. If any are found, they are

View File

@ -25,7 +25,6 @@
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@yanick/updeep-remeda": "^2.2.0", "@yanick/updeep-remeda": "^2.2.0",
"ajv": "^8.12.0",
"consola": "^3.1.0", "consola": "^3.1.0",
"fs-extra": "^11.1.1", "fs-extra": "^11.1.1",
"markdown-utils": "^1.0.0", "markdown-utils": "^1.0.0",

View File

@ -1,113 +0,0 @@
export default {
type: "object",
additionalProperties: false,
properties: {
change_types: {
items: {
additionalProperties: false,
properties: {
keywords: {
items: {
type: "string",
},
type: "array",
},
level: {
enum: ["major", "minor", "patch"],
},
title: {
type: "string",
},
},
type: "object",
},
type: "array",
},
project: {
additionalProperties: false,
properties: {
homepage: {
description: "url of the project's homepage",
examples: ["https://github.com/yanick/app-changelord"],
type: ["string", "null"],
},
name: {
description: "name of the project",
examples: ["App::Changelord"],
type: ["null", "string"],
},
ticket_url: {
description:
"perl code that takes a ticket string (e.g. 'GH123') via the `$_` variable and turns it into a link.",
examples: [
"s!GH(\\d+)!https://github.com/yanick/App-Changelord/issue/$1/",
{
'/^\\d+$/ ? "https://.../$_"': "undef",
},
],
type: "string",
},
with_stats: {
description: "if true, add git statistics when bumping the version.",
},
},
type: "object",
},
releases: {
items: {
oneOf: [
{
type: "string",
},
{
additionalProperties: false,
properties: {
changes: {
items: {
$ref: "#/$defs/change",
},
type: "array",
},
date: {
type: ["null", "string"],
},
version: {
type: ["null", "string"],
},
},
type: "object",
},
],
},
type: "array",
},
},
$defs: {
change: {
oneOf: [
{
type: "string",
},
{
additionalProperties: false,
properties: {
commit: {
type: ["string", "null"],
},
desc: {
type: "string",
},
ticket: {
type: ["string", "null"],
},
type: {
type: ["string", "null"],
},
},
required: ["desc"],
type: "object",
},
],
},
},
};

59
src/changelog-schema.yml Normal file
View File

@ -0,0 +1,59 @@
type: object
additionalProperties: false
properties:
project:
type: object
additionalProperties: false
properties:
homepage:
type: [ string, 'null' ]
description: url of the project's homepage
examples:
- https://github.com/yanick/app-changelord
name:
type: [ 'null', string ]
description: name of the project
examples:
- App::Changelord
ticket_url:
type: string
description: perl code that takes a ticket string (e.g. 'GH123') via the `$_` variable and turns it into a link.
examples:
- s!GH(\d+)!https://github.com/yanick/App-Changelord/issue/$1/
- /^\d+$/ ? "https://.../$_" : undef
with_stats:
description: if true, add git statistics when bumping the version.
change_types:
type: array
items:
type: object
additionalProperties: false
properties:
keywords:
type: array
items: { type: string }
level: { enum: [ major, minor, patch ] }
title: { type: string }
releases:
type: array
items:
oneOf:
- type: string
- type: object
additionalProperties: false
properties:
version: { type: [ 'null', string ] }
date: { type: ['null',string] }
changes: { type: 'array', items: { $ref: '#/$defs/change' } }
$defs:
change:
oneOf:
- type: string
- type: object
required: [ desc ]
additionalProperties: false
properties:
desc: { type: string }
ticket: { type: [ string, 'null' ] }
type: { type: [ string, 'null' ] }
commit: { type: [ string, 'null' ] }

View File

@ -9,7 +9,6 @@ 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 simpleGit from "simple-git";
import Ajv from "ajv";
import print from "./command/print.js"; import print from "./command/print.js";
import init from "./command/init.js"; import init from "./command/init.js";
@ -18,9 +17,7 @@ import add from "./command/add.js";
import cut from "./command/cut.js"; import cut from "./command/cut.js";
import upcoming, { next_release } from "./command/upcoming.js"; import upcoming, { next_release } from "./command/upcoming.js";
import latest, { latest_version } from "./command/latest-version.js"; import latest, { latest_version } from "./command/latest-version.js";
import validate from "./command/validate.js";
import git_gather from "./command/git-gather.js"; import git_gather from "./command/git-gather.js";
import schemaV1 from "./changelog-schema.js";
consola.raw = (...args) => console.log(...args); consola.raw = (...args) => console.log(...args);
@ -29,18 +26,7 @@ yargs(hideBin(process.argv))
config.git = once(simpleGit); config.git = once(simpleGit);
config.consola = consola; config.consola = consola;
config.changelog = once(() => config.changelog = once(() =>
fs fs.readFile(config.source, "utf-8").then(yaml.parse)
.readFile(config.source, "utf-8")
.then(yaml.parse)
.then((doc) => {
const ajv = new Ajv();
const validate = ajv.compile(schemaV1);
const valid = validate(doc);
if (valid) return doc;
config.consola.error("invalid changelog: ", validate.errors);
throw "changelog is invalid";
})
); );
config.save_changelog = async (changelog) => { config.save_changelog = async (changelog) => {
if (!changelog) changelog = await config.changelog(); if (!changelog) changelog = await config.changelog();
@ -50,9 +36,7 @@ yargs(hideBin(process.argv))
config.latest_version = latest_version.bind(config); config.latest_version = latest_version.bind(config);
return config; return config;
}) })
.middleware((argv, yargs) => { .middleware((argv) => {
argv.yargs = yargs;
argv.add_to_next = async (entry) => { argv.add_to_next = async (entry) => {
const changelog = yaml.parse(await fs.readFile(argv.source, "utf-8")); const changelog = yaml.parse(await fs.readFile(argv.source, "utf-8"));
@ -86,7 +70,6 @@ yargs(hideBin(process.argv))
}) })
.command(latest) .command(latest)
.command(git_gather) .command(git_gather)
.command(validate)
.strictCommands() .strictCommands()
.help() .help()
.parse(); .parse();

View File

@ -19,6 +19,7 @@ export const base_changelog = {
name: null, name: null,
homepage: null, homepage: null,
with_stats: true, with_stats: true,
ticket_url: null,
}, },
releases: [{ version: "NEXT", changes: [] }], releases: [{ version: "NEXT", changes: [] }],
change_types, change_types,

View File

@ -103,7 +103,7 @@ export const render_release = (config, source) => (release) => {
}; };
const handler = async (config) => { const handler = async (config) => {
const source = await config.changelog(); const source = await fs.readFile(config.source, "utf-8").then(yaml.parse);
let output = ""; let output = "";

View File

@ -1,9 +1,12 @@
import fs from "fs-extra"; import fs from "fs-extra";
import yaml from "yaml";
import schemaV1 from "../changelog-schema.js";
const handler = async ({consola}) => { const handler = async ({consola}) => {
consola.raw(yaml.stringify(schemaV1)); consola.raw(
await fs.readFile(
new URL("../changelog-schema.yml", import.meta.url),
"utf-8"
)
);
}; };
export default { export default {

View File

@ -1,16 +0,0 @@
const handler = async (config) => {
config.consola.start("validating changelog...");
try {
await config.changelog();
config.consola.success("valid!");
} catch (e) {
config.yargs.exit(1, "changelog is invalid :-(");
}
};
export default {
command: "validate",
desc: "validate the changelog against its json schema",
handler,
};

View File

@ -1,16 +0,0 @@
import { test, expect, vi } from "vitest";
import validate from "./validate.js";
test("basic", async () => {
const success = vi.fn();
const noop = () => true;
await validate.handler({
changelog: () => ({}),
consola: {
start: noop,
success,
},
});
expect(success).toHaveBeenCalled();
});