Directus Hook Extension: Version Control Changelog

Overview

Directus Hook Extension: Version Control Changelog

Node.js CI Build Badge npm version

This package is a Hook Extension for the CMS Directus that allows you to add entries to a changelog in a version control system. Currently only Bitbucket Server is supported, but it is prepared to be extended to other version control systems (like GitHub or GitLab) in the future.

Instead of just "blindly" adding each change in the database it relies on a user written changelog entry that summarizes the changes. For that it relies on a singleton collection with (at least) a textarea field in it.

Why would I want that?

We (BI X) created this extension because of the way how GatsbyJS with Directus as content source and our build system (OpenDevStack with ods-pipeline) work.
Our builds are triggered by webhooks that get fired on pushes to our VCS server. For that it relies heavily on the Bitbucket webhooks and its specific content. Recreating them with the Directus webhook functionality would have been a huge effort - and as our build system does not rebuild things if there are no changes (to the codebase / repository) it would also be without any effect.

Additionally we wanted to see what has changed in a new release - code as well as content.

That is why we decided to maintain a changelog inside of the VCS that can be updated by Directus. And for that we wrote this extension hook.

Table of Contents

How can I use it?

Set up things in Directus

1. Create a singleton collection with at least one textarea

First you create a new collection in your Directus - make sure that the option to treat it as a single object is activated: Screenshot of the collection setup

Then you add at least one textarea field and make sure that it is requiring content in there to be saved: Screenshot of the textarea setup

While the above shown is enough we recommend to use the features of Directus to give the content managers more guidance. Below you see our setup where we used the placeholder and the note of the textarea - as well as a readonly-field with an instructional message as default content: Screenshot of a recommended setup

2. Add the required configuration values to your Directus installation

The extension uses the configuration mechanism of Directus. So all you have to do is to add the following variables to your preferred configuration location:

Variable Name Description
VERSION_CONTROL_CHANGELOG_COLLECTION name of the collection (e.g. vcs_changelog)
VERSION_CONTROL_CHANGELOG_FIELD_NAME name of the field in the collection (e.g. changes_made)
VERSION_CONTROL_CHANGELOG_VCS Has to be bitbucket for now
VERSION_CONTROL_CHANGELOG_BITBUCKET_USER the user of the Bitbucket VCS server
VERSION_CONTROL_CHANGELOG_BITBUCKET_PASSWORD the password for the user above
VERSION_CONTROL_CHANGELOG_VCS_SERVER_URL the full URL of your VCS server - without a trailing / (e.g. https://your.vcs.example)
VERSION_CONTROL_CHANGELOG_VCS_PROJECT the name of the project (or user) on the VCS server
VERSION_CONTROL_CHANGELOG_VCS_REPOSITORY the name of the repository of the project (or user)
VERSION_CONTROL_CHANGELOG_VCS_BRANCH the branch that should be used for reading and writing the changelog (e.g. cms-changes)
VERSION_CONTROL_CHANGELOG_VCS_FILENAME the name of the file that should be used (e.g. directus-changelog.md)

Important: Make sure that the assigned Bitbucket user has write permissions in the repository.
There is no need to create the branch or the file in the repository, the extension takes care of this. This also means that in case you delete the file or the branch it will be automatically recreated on the next execution of the extension.

3. Add the extension to your installation

  1. clone (or download) this repository to your local machine - alternatively you can install the package from npm and run the following next steps in the folder of the module
  2. open a terminal and change into the directory containing the package.json
  3. run npm install
  4. run npm run build
  5. create a directory named version-control-changelog inside of your /extensions/hooks/ directory
  6. copy the generated index.js file from the dist directory
  7. paste the copied file into the newly created directory
  8. restart your Directus instance; monitor the log during startup

If everything works you will see the following line in the log output:

01:23:45 ✨ Version Control Changelog Extension Extension initialized, action handler registered
...
01:23:45 ✨ Server started at http://localhost:8055

4. Add your first changelog entry

Once you save your first changes in the configured collection & field the log should show you the following line:

17:32:16 ✨ Version Control Changelog Extension BitbucketVersionControl: new changelog pushed successful

If you see it: congratulations, your setup works!

Release History

Version 0.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

2022-02-14

  • initial release for Bitbucket

Future possibilities

These are things that would make sense, but it is not granted that it will be implemented

  • support "auto-create" of the required collection(s) and field(s) on first run
  • allow multiple changelogs (multiple collections writing to multiple repositories)
  • add GitHub and / or GitLab as target systems
  • added to npm (to allow installation via npm once it is available)
    • confirm it works or do required adjustments once available
  • add to the Extension Marketplace once it is available
You might also like...

Apply version control to databases from within a Node.js application.

Node Flyway Apply version control to databases from within a Node.js application. Uses Flyway for database version control, schema evolution and migra

Sep 6, 2022

The Remix version of the fakebooks app demonstrated on https://remix.run. Check out the CRA version: https://github.com/kentcdodds/fakebooks-cra

Remix Fakebooks App This is a (very) simple implementation of the fakebooks mock app demonstrated on remix.run. There is no database, but there is an

Dec 22, 2022

Chrome extension for granular visual control over Notion.so

Notion Style Tweaks (Beta) A Chrome extension aiming to give granular control over the visual experience of Notion. Written in Svelte. Installation Ch

Dec 25, 2022

Animated sprite hook for react-three-fiber

use-animated-sprite Animated sprite hook for react-three-fiber Dependencies npm install @react-three/drei @react-three/fiber react three Installation

Dec 4, 2022

An enchanced useState hook which keeps track of the states history, allowing you to undo and redo states.

useTimeline An enchanced useState hook which keeps track of the states history, allowing you to undo and redo states. useTimeline is a simple hook bas

Apr 22, 2022

🪝 React hook for subscribing to user's color scheme preference.

🪝 React hook for subscribing to user's color scheme preference.

use-prefers-color-scheme React hook for subscribing to user's color scheme preference. 🚀 Getting Started 🐇 Jump Start npm install @anatoliygatt/use-

Dec 19, 2022

A React hook to fetch ENS records from a domain.

use-ens A React hook to fetch ENS records from a domain. Install pnpm i use-ens Example import React, { useEffect } from 'react' import { useWeb3React

Jul 31, 2022

A trpc-ified useReducer hook. ⚡

trpc-reducer A trpc-ified react useReducer hook that lets you perform state logic in reducers just like React's useReducer hook When you dispatch an a

Aug 27, 2022

A tiny, SSR-friendly hook for listening to gamepad events.

useGamepadEvents useGamepadEvents is a tiny, SSR-friendly hook for listening to gamepad events. It's a wrapper around the Gamepad API designed for fir

Oct 2, 2022
Comments
  • .split on undefined causes a crash

    .split on undefined causes a crash

    It can happen that the trigger ends up in an error as below:

    TypeError: Cannot read properties of undefined (reading 'split') at Function.formatLatestChanges (/directus/extensions/hooks/version-control-changelog/index.js:8:8352) at Bi.triggerProcessor (/directus/extensions/hooks/version-control-changelog/index.js:8:19511) at processTicksAndRejections (node:internal/process/task_queues:96:5)

    The reason still needs to be investigated, but the guess is that the system cannot handle formatting of a NULL value in the previous change log data yet (as this appears on a system that never had any content in that field before)

    bug 
    opened by ManuelFeller 4
  • Finalize bitbucket api

    Finalize bitbucket api

    • finalized Bitbucket API
      • auto branch creation
      • auto file creation
    • added some tests for internal classes without external dependencies

    Manually "integration-tested" on Directus 9.5.1 against Bitbucket Server 6.10.12 without any errors

    opened by ManuelFeller 0
Releases(v0.8.1)
Owner
BIX Digital Lab
https://www.bix-digital.com/about-us/
BIX Digital Lab
🪵 Aggressively find a packages changelog (or releases) between versions.

?? changelogd Aggressively find a packages changelog (or releases) between versions. Status: Early Access Please report any issues ?? Made possible by

Harlan Wilton 8 May 10, 2022
⚡️ An action for generate gitmoji changelog. 😜

Gitmoji Changelog Action An action for generate gitmoji changelog. Usage name: "Generate Gitmoji Changelog" on: push: branches: - "main"

Sercan Üste 10 Dec 24, 2022
Directus dataprovider package for refine.

refine-directus Directus dataprovider package for refine. About refine offers lots of out-of-the box functionality for rapid development, without comp

Vivek Palanisamy 15 Dec 27, 2022
The official Directus SDK for use in JavaScript!

Directus JS SDK Installation npm install @directus/sdk Basic Usage import { Directus } from '@directus/sdk'; const directus = new Directus('http://d

Directus 36 Dec 29, 2022
Custom endpoint to backup the PG database and upload the `.dump` to Directus.

Directus Backup Endpoint Custom Directus endpoint to backup Postgres database using pg_dump and upload the .dump file into Directus files. Usage Clone

Guilherme Oliveira 7 Dec 21, 2022
Custom operation to backup the PG database and upload the .dump to Directus.

Directus Backup Operation Custom Directus operation to backup Postgres database using pg_dump and upload the .dump file into Directus storage. Prerequ

Guilherme Oliveira 7 Dec 21, 2022
Web based application that uses playerctl in it backend to control remotely your audio using the frontend as remote control.

Linux Remote This is a web based application that uses playerctl in it backend to control remotely your audio using the frontend as remote control. Do

Gabriel Guerra 4 Jul 6, 2022
A three.js and roslibjs powered web-control for zju fast-drone-250 for laptop-free flight control

Web Control for ZJU Fast-Drone-250 A three.js and roslibjs powered web-control for zju fast-drone-250 for laptop-free flight control (tested on Xiaomi

null 6 Nov 11, 2022
A Hackable Markdown Note Application for Programmers. Version control, AI completion, mind map, documents encryption, code snippet running, integrated terminal, chart embedding, HTML applets, plug-in, and macro replacement.

Yank Note A hackable markdown note application for programmers Download | Try it Online >>> Not ecommended English | 中文说明 [toc]{level: [2]} Highlights

洋子 4.3k Dec 31, 2022
GitSol - an onchain version control protocol, service and cli tool

GitSol an onchain version control protocol, service and cli tool. Content what and why ?? Features ✨ Install ?? Usage ?? Examples ?? Documentation ??

GitSol 11 Sep 10, 2022