diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..d2c942c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,90 @@ +# Changelog + +All notable changes to this project are documented in this file. It is **generated from the +Conventional Commits** of the history: run `npm run changelog` instead of editing it by hand. +The project follows [Semantic Versioning](https://semver.org/). + +## [Unreleased] + +### Features +- **status:** _(feat)_ rotate an editable list of bot statuses ([c785e9a]) +- **voice:** _(feat)_ guarantee an empty generated channel disappears ([76e2269]) +- **voice:** _(feat)_ support several trigger channels with their own category ([836abea]) +- **voice:** _(feat)_ add temporary voice channel manager ([5191942]) +- **polls:** _(feat)_ implement polls, fun and statistics commands ([ef1bedb]) +- **members:** _(feat)_ add welcome, default role and departure reporting ([f29c095]) +- **moderation:** _(feat)_ implement the moderation service and commands ([c49c600]) +- **tickets:** _(feat)_ implement the ticket service, command and channel controls ([e8c95b2]) +- **notifications:** _(feat)_ dispatch Gitea webhooks through the notification service ([a5280ce]) +- **fws:** _(feat)_ implement the version, status and changelog subcommands ([26d7cce]) +- **gitea:** _(feat)_ add embeds, modals and the issue and pull request commands ([76d0bf9]) +- **core:** _(feat)_ add shared constants, interaction components and Gitea client helpers ([66be463]) +- **database:** _(feat)_ add repositories for tickets, moderation, polls and notifications ([03a217c]) +- **database:** _(feat)_ add database initialization script ([9a266b7]) +- **commands:** _(feat)_ add slash command deployment script ([6b4ac37]) +- **core:** _(feat)_ add bot entry point ([de97f87]) +- **fun:** _(feat)_ add fun command skeleton ([208d713]) +- **stats:** _(feat)_ add stats command skeleton ([baca3f0]) +- **polls:** _(feat)_ add poll command skeleton ([9ccecb3]) +- **roles:** _(feat)_ add role command skeleton ([cef9ed0]) +- **moderation:** _(feat)_ add moderation logs command skeleton ([744eaa8]) +- **moderation:** _(feat)_ add clear command skeleton ([dc4958f]) +- **moderation:** _(feat)_ add ban command skeleton ([002380c]) +- **moderation:** _(feat)_ add kick command skeleton ([4cc475e]) +- **moderation:** _(feat)_ add mute command skeleton ([373c7e6]) +- **moderation:** _(feat)_ add warn command skeleton ([1bcc3d3]) +- **support:** _(feat)_ add ticket command skeleton ([ab08253]) +- **gitea:** _(feat)_ add activity and release command skeleton ([d9ce9e4]) +- **gitea:** _(feat)_ add pull request command skeleton ([44c9595]) +- **gitea:** _(feat)_ add issue command skeleton ([bd2475c]) +- **fws:** _(feat)_ add fws information command ([4cc6964]) +- **commands:** _(feat)_ add help command ([3aa17e5]) +- **members:** _(feat)_ add member leave event handler ([9cb2a73]) +- **members:** _(feat)_ add member join event handler ([aa404dd]) +- **commands:** _(feat)_ dispatch slash commands with access control ([017764d]) +- **discord:** _(feat)_ log shard disconnections ([8f48efd]) +- **discord:** _(feat)_ log discord client errors ([e9c110a]) +- **discord:** _(feat)_ handle client ready event ([0fb20d1]) +- **webhooks:** _(feat)_ add http server for gitea webhooks ([fb63cc9]) +- **webhooks:** _(feat)_ validate and deduplicate gitea webhook events ([7a7d8e6]) +- **notifications:** _(feat)_ add notification dispatch service ([13f8e24]) +- **gitea:** _(feat)_ add gitea api client ([6fca3b7]) +- **ui:** _(feat)_ add link buttons builder ([856e7ba]) +- **ui:** _(feat)_ add standard embed builders ([94dab89]) +- **utils:** _(feat)_ add cooldown guard against duplicate actions ([f56e837]) +- **utils:** _(feat)_ add retry helper with exponential backoff ([4205ed5]) +- **database:** _(feat)_ add event log repository ([de64a0e]) +- **database:** _(feat)_ add guild settings repository ([910cf32]) +- **database:** _(feat)_ initialize sqlite connection and migrations ([5716d24]) +- **database:** _(feat)_ add initial sqlite schema ([a2520fe]) +- **discord:** _(feat)_ add event loader ([34da3eb]) +- **commands:** _(feat)_ add slash command loader ([15e7279]) +- **discord:** _(feat)_ create client with required gateway intents ([baf8db0]) +- **auth:** _(feat)_ add centralized permission checks ([2085f57]) +- **observability:** _(feat)_ add json logger with secret masking ([c03027e]) +- **core:** _(feat)_ add typed application errors ([bba2ee7]) +- **config:** _(feat)_ add colors, access levels and ticket categories ([eca9bbe]) +- **config:** _(feat)_ load and expose environment settings ([d1388b6]) + +### Other changes +- **gitignore:** _(chore)_ ignore the AI assistant data and the other toolchains ([2df33c2]) +- **ui:** _(refactor)_ give every message one friendly, ungendered voice ([ef8f09d]) +- **agents:** _(docs)_ add the shared agent instructions for FWS repositories ([66c04c6]) +- **readme:** _(docs)_ document the implemented features and the voice manager ([be4981a]) +- **app:** _(test)_ add command and event loading smoke tests ([aa5343b]) +- **core:** _(docs)_ document project structure ([abf6701]) +- **docs:** _(chore)_ add screenshots directory ([fec8007]) +- **observability:** _(chore)_ keep logs directory in repository ([9f2aa90]) +- **database:** _(chore)_ keep data directory in repository ([070612a]) +- **database:** _(test)_ add sqlite storage tests ([baef3fa]) +- **auth:** _(test)_ add permission checks tests ([52e24bd]) +- **config:** _(build)_ add environment variables example ([1cf7b1f]) +- **quality:** _(build)_ configure eslint flat config ([de328af]) +- **quality:** _(build)_ add prettier ignore rules ([25cc44d]) +- **quality:** _(build)_ configure prettier ([bafda6b]) +- **deps:** _(build)_ add npm lockfile ([d4d5854]) +- **deps:** _(build)_ add package manifest with discord.js and npm scripts ([f57a4f2]) +- **editor:** _(chore)_ add editorconfig settings ([4693ea0]) +- **security:** _(build)_ replace python ignore rules with node.js rules ([bfd4c26]) +- **BREAKING** **readme:** _(docs)_ Edit of the Readme ([2a91229]) +- Initial commit ([5fc5cf8]) diff --git a/package.json b/package.json index 67540de..cc9fcfa 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,8 @@ "dev": "node --watch src/index.js", "deploy:commands": "node scripts/deploy-commands.js", "db:init": "node scripts/init-database.js", + "changelog": "node scripts/generate-changelog.js", + "changelog:check": "node scripts/generate-changelog.js --check", "lint": "eslint .", "lint:fix": "eslint . --fix", "format": "prettier --write .", diff --git a/scripts/generate-changelog.js b/scripts/generate-changelog.js new file mode 100644 index 0000000..74d05ee --- /dev/null +++ b/scripts/generate-changelog.js @@ -0,0 +1,172 @@ +#!/usr/bin/env node +import { execFileSync } from 'node:child_process'; +import { readFileSync, writeFileSync } from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +/** + * Builds CHANGELOG.md from the Conventional Commits of the history, as the FWS conventions + * require: `feat` and `fix` feed the Features and Bug Fixes sections, the other types are + * grouped under "Other changes". The file is generated, so run this script instead of editing it. + * + * Usage: node scripts/generate-changelog.js [--check] + * --check exits with code 1 when CHANGELOG.md is out of date (used by CI and tests) + */ + +const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); +const changelogPath = path.join(rootDir, 'CHANGELOG.md'); +const checkOnly = process.argv.includes('--check'); + +/** Section order and titles; anything else falls into "Other changes". */ +const SECTIONS = [ + { title: 'Features', test: (type) => type === 'feat' }, + { title: 'Bug Fixes', test: (type) => type === 'fix' }, + { title: 'Performance', test: (type) => type === 'perf' }, + { + title: 'Other changes', + test: (type) => type !== 'feat' && type !== 'fix' && type !== 'perf', + }, +]; + +const OTHER_LABELS = { + build: 'build', + chore: 'chore', + ci: 'ci', + docs: 'docs', + refactor: 'refactor', + revert: 'revert', + style: 'style', + test: 'test', +}; + +const git = (args) => execFileSync('git', args, { cwd: rootDir, encoding: 'utf8' }); + +function readCommits() { + // One record per commit, fields separated by unit separators so bodies stay readable. + const raw = git([ + 'log', + '--no-merges', + '--date=short', + '--format=%H%x1f%ad%x1f%s%x1f%b%x1f%D%x1e', + // A commit that only rewrites the changelog must not appear in it, otherwise `--check` + // could never be green once that file is committed. + '--', + '.', + ':(exclude)CHANGELOG.md', + ]); + return raw + .split('\x1e') + .map((record) => record.trim()) + .filter(Boolean) + .map((record) => { + const [hash, date, subject, body = '', decoration = ''] = record.split('\x1f'); + const match = /^(?[a-z]+)(?:\((?[^)]*)\))?(?!)?: (?.+)$/.exec( + subject.trim(), + ); + const breaking = Boolean(match?.groups.breaking) || /BREAKING CHANGE/.test(body); + return { + hash, + date, + subject: subject.trim(), + type: match?.groups.type ?? 'other', + scope: match?.groups.scope ?? null, + description: match?.groups.description ?? subject.trim(), + breaking, + tags: decoration + .split(',') + .map((ref) => ref.trim().replace(/^tag: /, '')) + .filter((ref) => /^v?\d+\.\d+\.\d+/.test(ref)), + }; + }); +} + +function entryLine(commit) { + const scope = commit.scope ? `**${commit.scope}:** ` : ''; + const breaking = commit.breaking ? '**BREAKING** ' : ''; + const label = commit.type === 'other' ? '' : `_(${OTHER_LABELS[commit.type] ?? commit.type})_ `; + const detail = commit.type === 'other' ? commit.subject : commit.description; + return `- ${breaking}${scope}${label}${detail} ([${commit.hash.slice(0, 7)}])`; +} + +/** A commit without a tag belongs to "Unreleased"; a tag closes the section it points to. */ +function groupByRelease(commits) { + const releases = []; + let current = { title: 'Unreleased', date: null, commits: [] }; + + for (const commit of commits) { + current.commits.push(commit); + for (const tag of commit.tags) { + releases.push({ title: tag, date: commit.date, commits: current.commits }); + current = { title: 'Unreleased', date: null, commits: [] }; + } + } + if (current.commits.length > 0) releases.push(current); + return releases; +} + +function renderRelease(release) { + const heading = release.date ? `## [${release.title}] — ${release.date}` : `## [${release.title}]`; + const lines = [heading]; + + for (const section of SECTIONS) { + const entries = release.commits.filter((commit) => section.test(commit.type)); + if (entries.length === 0) continue; + lines.push('', `### ${section.title}`, ...entries.map(entryLine)); + } + + if (release.commits.length === 0) lines.push('', '_Nothing yet._'); + return lines.join('\n'); +} + +/** SemVer hint from the commits since the last release: breaking > feature > fix. */ +function suggestVersion(commits) { + const version = JSON.parse(readFileSync(path.join(rootDir, 'package.json'), 'utf8')).version; + const [major, minor, patch] = version.split('.').map(Number); + const breaking = commits.some((commit) => commit.breaking); + const feature = commits.some((commit) => commit.type === 'feat'); + + // SemVer §4: below 1.0.0 anything may change, so a breaking change only bumps the minor. + if (major === 0) return breaking || feature ? `0.${minor + 1}.0` : `0.${minor}.${patch + 1}`; + if (breaking) return `${major + 1}.0.0`; + if (feature) return `${major}.${minor + 1}.0`; + return `${major}.${minor}.${patch + 1}`; +} + +function buildChangelog(commits) { + const releases = groupByRelease(commits); + + return [ + '# Changelog', + '', + 'All notable changes to this project are documented in this file. It is **generated from the', + 'Conventional Commits** of the history: run `npm run changelog` instead of editing it by hand.', + 'The project follows [Semantic Versioning](https://semver.org/).', + '', + releases.map(renderRelease).join('\n\n'), + '', + ].join('\n'); +} + +const commits = readCommits(); +const content = buildChangelog(commits); +const unreleased = commits.filter((commit) => !commit.tags.length); +const previous = (() => { + try { + return readFileSync(changelogPath, 'utf8'); + } catch { + return null; + } +})(); + +if (checkOnly) { + if (previous !== content) { + console.error('CHANGELOG.md is out of date: run `npm run changelog`.'); + process.exit(1); + } + console.log('CHANGELOG.md is up to date.'); + process.exit(0); +} + +writeFileSync(changelogPath, content); +console.log(`Wrote ${path.relative(rootDir, changelogPath)} from ${commits.length} commits.`); +console.log(`Suggested next version: ${suggestVersion(unreleased)}`);