From 4a11f6d780c965dca2f619381750a071f44ebb0b Mon Sep 17 00:00:00 2001 From: Joachim Dalen <15696189+joachimdalen@users.noreply.github.com> Date: Thu, 30 Dec 2021 09:01:30 +0100 Subject: [PATCH] Prepare and fixes for v0.3.0 (#36) --- .azext/changelog.json | 82 +++++------ CHANGELOG.md | 84 ++++++----- schemas/v1/changelog-schema.json | 11 +- src/core/utils.ts | 18 +++ src/modules/changelog/changelog-service.ts | 21 ++- src/modules/changelog/generator.ts | 25 ++-- src/modules/changelog/metadata.ts | 10 +- .../changelog/models/changelog-definition.ts | 2 +- src/tests/core/utils.test.ts | 132 +++++++++++++++++- 9 files changed, 269 insertions(+), 116 deletions(-) diff --git a/.azext/changelog.json b/.azext/changelog.json index 83c853c..78c3235 100644 --- a/.azext/changelog.json +++ b/.azext/changelog.json @@ -1,6 +1,6 @@ [ { - "publishDate": "2021-12-XX", + "publishDate": "2021-12-30", "version": "0.3.0", "changes": [ { @@ -102,17 +102,11 @@ { "publishDate": "2021-12-25", "version": "0.2.1", - "modules": [ + "changes": [ { - "name": "core", - "version": "0.2.1", - "changes": [ - { - "type": "docs", - "description": "Updated NPM readme", - "pullRequest": 20 - } - ] + "type": "docs", + "description": "Updated NPM readme", + "pullRequest": 20 } ] }, @@ -120,6 +114,28 @@ "publishDate": "2021-12-22", "version": "0.2.0", "notes": "This release introduces a new command (`azext readme`) to manage documentation. See [GitHub Documentation](https://github.com/joachimdalen/azext/blob/master/docs/readme/index.md) for more information.", + "changes": [ + { + "type": "maint", + "description": "Split CLI and implementation in preparation for Node API", + "pullRequest": 6 + }, + { + "description": "Added more detailed documentation", + "type": "docs", + "pullRequest": 7 + }, + { + "type": "feature", + "description": "Add support for global options", + "pullRequest": 7 + }, + { + "type": "maint", + "description": "Forced path of configuration files to be in folder `.azext/`", + "pullRequest": 12 + } + ], "modules": [ { "name": "readme", @@ -175,32 +191,6 @@ } ] }, - { - "name": "core", - "version": "0.2.0", - "changes": [ - { - "type": "maint", - "description": "Split CLI and implementation in preparation for Node API", - "pullRequest": 6 - }, - { - "description": "Added more detailed documentation", - "type": "docs", - "pullRequest": 7 - }, - { - "type": "feature", - "description": "Add support for global options", - "pullRequest": 7 - }, - { - "type": "maint", - "description": "Forced path of configuration files to be in folder `.azext/`", - "pullRequest": 12 - } - ] - }, { "name": "init", "version": "0.2.0", @@ -224,6 +214,13 @@ "publishDate": "2021-12-13", "version": "0.0.1", "summary": "Initial release of AzExt", + "changes": [ + { + "type": "maint", + "description": "Setup CI and CD", + "pullRequest": 1 + } + ], "modules": [ { "name": "changelog", @@ -254,17 +251,6 @@ "type": "feature" } ] - }, - { - "name": "core", - "version": "0.0.1", - "changes": [ - { - "type": "maint", - "description": "Setup CI and CD", - "pullRequest": 1 - } - ] } ] } diff --git a/CHANGELOG.md b/CHANGELOG.md index db8d2d8..1943d41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## 0.3.0 (2021-12-XX) +## 0.3.0 (2021-12-30) ### 💬 Other (1) @@ -37,6 +37,18 @@ ## 0.2.2 (2021-12-26) +### 💬 Other (2) + +#### `readme@0.2.2` + +- Refactor how cli parameters are set in the cli definition + - Pull Request: [GH#25 - Fix wrong option names being passed from cli to handler](https://github.com/joachimdalen/azext/pull/25) + +#### `init@0.2.2` + +- Refactor how cli parameters are set in the cli definition + - Pull Request: [GH#25 - Fix wrong option names being passed from cli to handler](https://github.com/joachimdalen/azext/pull/25) + ### 🐛 Fixes (3) #### `changelog@0.2.2` @@ -54,26 +66,12 @@ - Issue: [GH#21 - Can not initialize in a new project](https://github.com/joachimdalen/azext/issues/21) - Pull Request: [GH#26 - Fix not being able to initialize in a new project](https://github.com/joachimdalen/azext/pull/26) -### 💬 Other (2) - -#### `readme@0.2.2` - -- Refactor how cli parameters are set in the cli definition - - Pull Request: [GH#25 - Fix wrong option names being passed from cli to handler](https://github.com/joachimdalen/azext/pull/25) - -#### `init@0.2.2` - -- Refactor how cli parameters are set in the cli definition - - Pull Request: [GH#25 - Fix wrong option names being passed from cli to handler](https://github.com/joachimdalen/azext/pull/25) - --- ## 0.2.1 (2021-12-25) ### 📝 Documentation (1) -#### `core@0.2.1` - - Updated NPM readme - Pull Request: [GH#20 - Fix readme for Npm](https://github.com/joachimdalen/azext/pull/20) @@ -83,7 +81,26 @@ > This release introduces a new command (`azext readme`) to manage documentation. See [GitHub Documentation](https://github.com/joachimdalen/azext/blob/master/docs/readme/index.md) for more information. -### 🚀 Features (9) +### 🚀 Features (1) + +- Add support for global options + - Pull Request: [GH#7 - Update documentation](https://github.com/joachimdalen/azext/pull/7) + +### 📝 Documentation (1) + +- Added more detailed documentation + - Pull Request: [GH#7 - Update documentation](https://github.com/joachimdalen/azext/pull/7) + +### 🛠️ Maintenance (2) + +- Split CLI and implementation in preparation for Node API + - Pull Request: [GH#6 - Refactor to support for usage from node](https://github.com/joachimdalen/azext/pull/6) +- Forced path of configuration files to be in folder `.azext/` + - Pull Request: [GH#12 - Refactoring and docs generation](https://github.com/joachimdalen/azext/pull/12) + +## 📦 Module changes + +### 🚀 Features (8) #### `readme@0.1.0` @@ -107,11 +124,6 @@ - Issue: [GH#13 - Add command to populate changelog cache without generating it](https://github.com/joachimdalen/azext/issues/13) - Pull Request: [GH#16 - Add command for refresh of changelog cache](https://github.com/joachimdalen/azext/pull/16) -#### `core@0.2.0` - -- Add support for global options - - Pull Request: [GH#7 - Update documentation](https://github.com/joachimdalen/azext/pull/7) - #### `init@0.2.0` - Add new command to create mapping file @@ -130,28 +142,19 @@ - Issue: [GH#2 - Init command does not respect --root option](https://github.com/joachimdalen/azext/issues/2) - Pull Request: [GH#6 - Refactor to support for usage from node](https://github.com/joachimdalen/azext/pull/6) -### 📝 Documentation (1) - -#### `core@0.2.0` - -- Added more detailed documentation - - Pull Request: [GH#7 - Update documentation](https://github.com/joachimdalen/azext/pull/7) - -### 🛠️ Maintenance (2) - -#### `core@0.2.0` - -- Split CLI and implementation in preparation for Node API - - Pull Request: [GH#6 - Refactor to support for usage from node](https://github.com/joachimdalen/azext/pull/6) -- Forced path of configuration files to be in folder `.azext/` - - Pull Request: [GH#12 - Refactoring and docs generation](https://github.com/joachimdalen/azext/pull/12) - --- ## 0.0.1 (2021-12-13) Initial release of AzExt +### 🛠️ Maintenance (1) + +- Setup CI and CD + - Pull Request: [GH#1 - Setup build and deployment pipeline](https://github.com/joachimdalen/azext/pull/1) + +## 📦 Module changes + ### 🚀 Features (3) #### `changelog@0.0.1` @@ -166,11 +169,4 @@ Initial release of AzExt - Added config command -### 🛠️ Maintenance (1) - -#### `core@0.0.1` - -- Setup CI and CD - - Pull Request: [GH#1 - Setup build and deployment pipeline](https://github.com/joachimdalen/azext/pull/1) - --- diff --git a/schemas/v1/changelog-schema.json b/schemas/v1/changelog-schema.json index b52fc1c..c377b47 100644 --- a/schemas/v1/changelog-schema.json +++ b/schemas/v1/changelog-schema.json @@ -6,7 +6,16 @@ "description": "An explanation about the purpose of this instance.", "default": {}, "additionalProperties": false, - "required": ["publishDate", "version", "modules"], + + "required": ["publishDate", "version"], + "anyOf": [ + { + "required": ["changes"] + }, + { + "required": ["modules"] + } + ], "properties": { "publishDate": { "type": "string", diff --git a/src/core/utils.ts b/src/core/utils.ts index 877714c..b0ceb52 100644 --- a/src/core/utils.ts +++ b/src/core/utils.ts @@ -1,9 +1,11 @@ +import ChangelogDefinition from '../modules/changelog/models/changelog-definition'; import GitHubIssue from '../modules/changelog/models/github-issue'; import GitHubPullRequest from '../modules/changelog/models/github-pull-request'; export const isNumber = (item: number | undefined): item is number => { return !!item; }; + export const isIssue = (item: GitHubIssue | undefined): item is GitHubIssue => { return !!item; }; @@ -17,3 +19,19 @@ export const isPullRequest = ( ): item is GitHubPullRequest => { return !!item; }; + +export const getChangesForDefinition = (def: ChangelogDefinition) => { + const moduleChanges = def.modules?.flatMap((x) => x.changes); + + if (def.changes) { + if (moduleChanges) return [...def.changes, ...moduleChanges]; + return [...def.changes]; + } + + if (moduleChanges !== undefined) return moduleChanges; + + return []; +}; +export const getChangesForAllDefinition = (def: ChangelogDefinition[]) => { + return def.flatMap((x) => getChangesForDefinition(x)); +}; diff --git a/src/modules/changelog/changelog-service.ts b/src/modules/changelog/changelog-service.ts index 48b83c4..30d73be 100644 --- a/src/modules/changelog/changelog-service.ts +++ b/src/modules/changelog/changelog-service.ts @@ -1,7 +1,13 @@ import chalk from 'chalk'; import { ActionResult } from '../../constants'; -import { distinct, isIssue, isNumber, isPullRequest } from '../../core'; +import { + distinct, + getChangesForAllDefinition, + isIssue, + isNumber, + isPullRequest +} from '../../core'; import ConfigProvider from '../../data-providers/config-provider'; import GitHub from '../../data-providers/github'; import { @@ -133,8 +139,9 @@ class ChangelogService { } if (cache.issues) { - const issueIds = changelog - .flatMap((x) => x.modules.flatMap((x) => x.changes.map((x) => x.issue))) + const allModules = getChangesForAllDefinition(changelog); + const issueIds = allModules + .map((x) => x.issue) .filter(isNumber) .filter(distinct) .filter((y) => !cache.issues?.some((x) => x.number === y)); @@ -154,10 +161,10 @@ class ChangelogService { } if (cache.pullRequests) { - const prIds = changelog - .flatMap((x) => - x.modules.flatMap((x) => x.changes.map((x) => x.pullRequest)) - ) + const allModules = getChangesForAllDefinition(changelog); + + const prIds = allModules + .map((x) => x.pullRequest) .filter(isNumber) .filter(distinct) .filter((y) => !cache.pullRequests?.some((x) => x.number === y)); diff --git a/src/modules/changelog/generator.ts b/src/modules/changelog/generator.ts index 214f6ea..004ab05 100644 --- a/src/modules/changelog/generator.ts +++ b/src/modules/changelog/generator.ts @@ -3,7 +3,7 @@ import fs from 'fs/promises'; import { isModuleInstalled } from '../../core/addons-checker'; import Replacer from '../../core/replacer'; -import { distinct, isNumber } from '../../core/utils'; +import { distinct, getChangesForDefinition, isNumber } from '../../core/utils'; import ConfigProvider from '../../data-providers/config-provider'; import { CHANGELOG_CONFIG_NAME, CHANGELOG_NAME } from './changelog-constants'; import MarkdownBuilder from './markdown-builder'; @@ -240,6 +240,8 @@ class Generator { release: ChangelogDefinition, context: GeneratorContext ) { + if (!release.modules) return; + if (cfg.moduleChangesTitle && release.changes !== undefined) { builder.addHeader( this._replacer.replaceEmojisIf( @@ -314,12 +316,10 @@ class Generator { release: ChangelogDefinition, context: GeneratorContext ) { - const moduleIssues = release.modules - .flatMap((x) => x.changes.flatMap((y) => y.issue)) - .filter(isNumber); - const modulePrs = release.modules - .flatMap((x) => x.changes.flatMap((y) => y.pullRequest)) - .filter(isNumber); + const changes = getChangesForDefinition(release); + + const moduleIssues = changes.flatMap((x) => x.issue).filter(isNumber); + const modulePrs = changes.flatMap((x) => x.pullRequest).filter(isNumber); const nonAuthors = [ ...context.issues.values(), @@ -382,8 +382,15 @@ class Generator { this.addSectionHeader(builder, cfg, release); this.addSummaryAndNotes(builder, cfg, release); - this.addRootChanges(builder, cfg, release, context); - this.addModuleChanges(builder, cfg, release, context); + + if (release.changes) { + this.addRootChanges(builder, cfg, release, context); + } + + if (release.modules) { + this.addModuleChanges(builder, cfg, release, context); + } + this.addContributors(builder, cfg, release, context); builder.addSplitter(); } diff --git a/src/modules/changelog/metadata.ts b/src/modules/changelog/metadata.ts index 0521d63..ad33802 100644 --- a/src/modules/changelog/metadata.ts +++ b/src/modules/changelog/metadata.ts @@ -1,4 +1,4 @@ -import ConfigProvider from '../../data-providers/config-provider'; +import { getChangesForAllDefinition } from '../../core'; import ChangelogService from './changelog-service'; import ChangelogConfig from './models/changelog-config'; import ChangelogDefinition from './models/changelog-definition'; @@ -42,10 +42,10 @@ export class MetaDataLoader { cachedPullRequests.map((i) => [i.number, i]) ); - const distinctTypes = log - .flatMap((x) => - x.modules.flatMap((y) => y.changes.flatMap((z) => z.type)) - ) + const changes = getChangesForAllDefinition(log); + + const distinctTypes = changes + .map((x) => x.type) .filter((value, index, self) => { return self.indexOf(value) === index; }); diff --git a/src/modules/changelog/models/changelog-definition.ts b/src/modules/changelog/models/changelog-definition.ts index 3560b7b..390ce99 100644 --- a/src/modules/changelog/models/changelog-definition.ts +++ b/src/modules/changelog/models/changelog-definition.ts @@ -6,6 +6,6 @@ export default interface ChangelogDefinition { publishDate: string; summary?: string; notes?: string; - modules: ChangelogModule[]; + modules?: ChangelogModule[]; changes?: ChangelogEntry[]; } diff --git a/src/tests/core/utils.test.ts b/src/tests/core/utils.test.ts index 804c10d..265f135 100644 --- a/src/tests/core/utils.test.ts +++ b/src/tests/core/utils.test.ts @@ -1,4 +1,12 @@ -import { distinct, isIssue, isNumber, isPullRequest } from '../../core'; +import { + distinct, + getChangesForAllDefinition, + getChangesForDefinition, + isIssue, + isNumber, + isPullRequest +} from '../../core'; +import ChangelogDefinition from '../../modules/changelog/models/changelog-definition'; import GitHubIssue from '../../modules/changelog/models/github-issue'; import GitHubPullRequest from '../../modules/changelog/models/github-pull-request'; @@ -46,4 +54,126 @@ describe('Utils', () => { expect([1, 2, 2, 3].filter(distinct)).toEqual([1, 2, 3]); }); }); + describe('getChangesForDefinition', () => { + it('should return correct when only root changes', () => { + const definition: ChangelogDefinition = { + publishDate: '2021-12-30', + version: '0.0.1', + changes: [ + { + type: 'bugfix', + description: 'Some desc' + } + ] + }; + + const fetched = getChangesForDefinition(definition); + + expect(fetched.length).toEqual(1); + }); + it('should return correct when only module changes', () => { + const definition: ChangelogDefinition = { + publishDate: '2021-12-30', + version: '0.0.1', + modules: [ + { + name: 'module-1', + version: '0.0.1', + changes: [ + { + type: 'bugfix', + description: 'Some desc' + } + ] + } + ] + }; + + const fetched = getChangesForDefinition(definition); + + expect(fetched.length).toEqual(1); + }); + it('should return correct when root and module changes', () => { + const definition: ChangelogDefinition = { + publishDate: '2021-12-30', + version: '0.0.1', + changes: [ + { + type: 'bugfix', + description: 'Some desc' + } + ], + modules: [ + { + name: 'module-1', + version: '0.0.1', + changes: [ + { + type: 'bugfix', + description: 'Some desc' + } + ] + } + ] + }; + + const fetched = getChangesForDefinition(definition); + + expect(fetched.length).toEqual(2); + }); + }); + describe('getChangesForAllDefinition', () => { + it('should return correct when root and module changes', () => { + const definitions: ChangelogDefinition[] = [ + { + publishDate: '2021-12-30', + version: '0.0.1', + changes: [ + { + type: 'bugfix', + description: 'Some desc' + } + ], + modules: [ + { + name: 'module-1', + version: '0.0.1', + changes: [ + { + type: 'bugfix', + description: 'Some desc' + } + ] + } + ] + }, + { + publishDate: '2021-12-30', + version: '0.0.1', + changes: [ + { + type: 'bugfix', + description: 'Some desc' + } + ], + modules: [ + { + name: 'module-1', + version: '0.0.1', + changes: [ + { + type: 'bugfix', + description: 'Some desc' + } + ] + } + ] + } + ]; + + const fetched = getChangesForAllDefinition(definitions); + + expect(fetched.length).toEqual(4); + }); + }); });