From c4de3785324b4100f58ca2bec9638b6a4cdec5ca Mon Sep 17 00:00:00 2001 From: Manuel Feller Date: Tue, 22 Feb 2022 16:46:08 +0100 Subject: [PATCH 1/4] using configured field name & catch undefined --- src/core/ChangelogWriter.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/core/ChangelogWriter.ts b/src/core/ChangelogWriter.ts index 2372670..a3b6560 100644 --- a/src/core/ChangelogWriter.ts +++ b/src/core/ChangelogWriter.ts @@ -99,11 +99,18 @@ export default class ChangelogWriter { const changeUserId = this.extractUserId(userDetails[0]); const date = new Date().toLocaleString('en-GB', { hour12: false, timeZone: 'UTC', timeZoneName: 'short' }); - const newData = ChangelogFormatter.formatLatestChanges(event.payload.changes,`## ${date} by ${changeUserId}`); - const commitMsg = `Content update from Directus CMS by ${changeUserId}`; - - // do the actual execution - this.vcsAbstraction.addToChangelogFile(newData, commitMsg); + const changeContent = event.payload[this.extensionConfig.fieldName]; + if (event.payload[this.extensionConfig.fieldName] !== undefined) { + const newData = ChangelogFormatter.formatLatestChanges(changeContent,`## ${date} by ${changeUserId}`); + const commitMsg = `Content update from Directus CMS by ${changeUserId}`; + // do the actual execution + this.vcsAbstraction.addToChangelogFile(newData, commitMsg); + } else { + // it seems there is a change in the monitored collection, but not in the field we're looking at + // so we warn the admin that something that might be not intended is possible + this.loggerReference.logMessage(LogLevels.warn, + 'Things in the changelog collection changed, but not in the monitored field. Make sure this is wanted behavior...'); + } } From 40b8b54c5f68fdcf4c43003153a907734feba44e Mon Sep 17 00:00:00 2001 From: Manuel Feller Date: Tue, 22 Feb 2022 16:48:38 +0100 Subject: [PATCH 2/4] improving logger for non colored consoles This should make it more easy to distinguish the extension prefix from the content --- src/core/ExtensionLogger.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ExtensionLogger.ts b/src/core/ExtensionLogger.ts index 9f802e9..d91c3b7 100644 --- a/src/core/ExtensionLogger.ts +++ b/src/core/ExtensionLogger.ts @@ -18,7 +18,7 @@ export default class ExtensionLogger { // using "name" to have it before the message itself based on the used formatter // --> see https://github.com/directus/directus/blob/ee7e678f24fd85846798bc3cc1af3103e728ebb7/api/src/logger.ts#L18 // and https://www.npmjs.com/package/pino-colada - this.loggerReference = directusLogger.child({name: 'Version Control Changelog Extension'}); + this.loggerReference = directusLogger.child({name: 'Version Control Changelog Extension >'}); } /** From 720c08068c93b9e07689fe955a0e8e63b552924c Mon Sep 17 00:00:00 2001 From: Manuel Feller Date: Tue, 22 Feb 2022 17:02:15 +0100 Subject: [PATCH 3/4] preparing release of fixed version --- README.md | 15 ++++++++++++++- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 163f5b1..903f393 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ That is why we decided to maintain a changelog inside of the VCS that can be upd - [3. Add the extension to your installation](#3-add-the-extension-to-your-installation) - [4. Add your first changelog entry](#4-add-your-first-changelog-entry) - [Release History](#release-history) + - [Version 0.8.1](#version-081) + - [Version 0.8.0](#version-080) - [Future possibilities](#future-possibilities) ## How can I use it? @@ -95,7 +97,18 @@ If you see it: congratulations, your setup works! ## Release History -- [Version 0.8.0](https://github.com/BIX-Digital/directus-version-control-changelog/releases/tag/v0.8.0) / 2022-02-14 -> initial release for Bitbucket +### [Version 0.8.1](https://github.com/BIX-Digital/directus-version-control-changelog/releases/tag/v0.8.1) + +2022-02-22 + +- fixing a bug where a hardcoded field name (not respecting the settings) causes a crash +- improved prefix of extension in logger messages + +### [Version 0.8.0](https://github.com/BIX-Digital/directus-version-control-changelog/releases/tag/v0.8.0) + +2022-02-14 + +- initial release for Bitbucket ## Future possibilities diff --git a/package-lock.json b/package-lock.json index 2a0d52e..efae10f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@bix-digital/directus-extension-version-control-changelog", - "version": "0.8.0", + "version": "0.8.1", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index e684406..52f1a5b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bix-digital/directus-extension-version-control-changelog", - "version": "0.8.0", + "version": "0.8.1", "description": "A Directus hook extension to push user written change summaries (from a singleton collection text field) to a changelog in a VCS server", "author": { "name" :"BI X Digital Engineers", From 28f71aa3e4e8b6c8574b597f6552d586a43a8f36 Mon Sep 17 00:00:00 2001 From: Manuel Feller Date: Tue, 22 Feb 2022 17:04:55 +0100 Subject: [PATCH 4/4] Update src/core/ChangelogWriter.ts fixed forgotten use of variable as suggested Co-authored-by: gerardcl --- src/core/ChangelogWriter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ChangelogWriter.ts b/src/core/ChangelogWriter.ts index a3b6560..2286afa 100644 --- a/src/core/ChangelogWriter.ts +++ b/src/core/ChangelogWriter.ts @@ -100,7 +100,7 @@ export default class ChangelogWriter { const changeUserId = this.extractUserId(userDetails[0]); const date = new Date().toLocaleString('en-GB', { hour12: false, timeZone: 'UTC', timeZoneName: 'short' }); const changeContent = event.payload[this.extensionConfig.fieldName]; - if (event.payload[this.extensionConfig.fieldName] !== undefined) { + if (changeContent !== undefined) { const newData = ChangelogFormatter.formatLatestChanges(changeContent,`## ${date} by ${changeUserId}`); const commitMsg = `Content update from Directus CMS by ${changeUserId}`; // do the actual execution