Skip to content

Commit

Permalink
MDL-81125 core: Add tooling to generate developer upgrade notes
Browse files Browse the repository at this point in the history
Usage:

    node .grunt/upgradenotes.mjs

      OR

    npm run upgradenote

Arguments can be provided to specify the issue number, component,
message, and type of change.

    node .grunt/upgradenotes.mjs -- \
        -c [component] \
        -i [issue number] \
        -t [type] \
        -m [message]

        OR

    npm run upgradenote -- \
        -c [component] \
        -i [issue number] \
        -t [type] \
        -m [message]

Summary Markdown files can be created using:

    node .grunt/upgradenotes.mjs summary

Weekly release files can be created using:

    node .grunt/upgradenotes.mjs release

Final release files can be created using:
using:
    node .grunt/upgradenotes.mjs release [version]

Generally speaking the integration team will be responsible for updating
the UPGRADING.md notes as part of the weekly integration processes.
  • Loading branch information
andrewnicols committed May 20, 2024
1 parent 486bc4b commit b7d029a
Show file tree
Hide file tree
Showing 14 changed files with 2,490 additions and 106 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ moodle-plugin-ci.phar
.hugo_build.lock
phpcs.xml
jsconfig.json
UPGRADING-CURRENT.md
110 changes: 110 additions & 0 deletions .grunt/notes/src/components.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

import * as Components from '../../components.js';

const componentData = Components.fetchComponentData();

/**
* The standard components shipped with core Moodle.
*
* @type {Object}
*/
export const standardComponents = componentData.standardComponents;

/**
* All components of the current Moodle instance.
*
* @type {Object}
*/
export const allComponents = componentData.components;

/**
* Get all components of the current Moodle instance.
*
* @returns {Array}
*/
export const getAllComponents = () => {
let components = new Map(Object.entries(componentData.pluginTypes).map(([value, path]) => ([path,{
path,
value,
name: `${value} (plugin type)`,
}])));

Object
.entries(componentData.components)
.filter(([path, value]) => Object.values(componentData.standardComponents).includes(value))
.forEach(([path, value]) => {
const entry = {
path,
value,
name: value,
};
if (Object.values(componentData.subsystems).includes(value)) {
if (components.has(path)) {
entry.name = `${value} (subsystem / plugintype)`;
} else {
entry.name = `${value} (subsystem)`;
}
}

components.set(path, entry);
});

return Array.from(components.values());
};

/**
* Whether the specified component is a standard component shipped with core Moodle.
*
* @param {string} componentName
* @returns {boolean}
*/
export const isStandardComponent = (componentName) => {
if (Object.values(componentData.standardComponents).includes(componentName)) {
return true;
}

if (Object.keys(componentData.pluginTypes).includes(componentName)) {
return true;
}

return false;
};

export const rewritePlugintypeAsSubsystem = (componentName) => {
if (Object.keys(componentData.pluginTypes).includes(componentName)) {
const pluginTypePath = componentData.pluginTypes[componentName];
if (Object.keys(componentData.subsystems).includes(pluginTypePath)) {
return true;
}
}

return false;
}

/**
* Whether the specified component is a community component.
*
* @param {string} componentName
* @returns {boolean}
*/
export const isCommunityComponent = (componentName) => {
if (isStandardComponent(componentName)) {
return false;
}

return Object.values(componentData.components).indexOf(componentName) !== -1;
}
85 changes: 85 additions & 0 deletions .grunt/notes/src/create.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env node
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

import inquirer from 'inquirer';
import chalk from 'chalk';

import { createNote } from './note.mjs';
import { getInitialValues } from './helpers.mjs';
import * as Prompts from './prompts.mjs';
import logger from './logger.mjs';

export default async (options) => {
// Processs the initial values.
const initialValues = getInitialValues(options);

// Fetch information.
const messages = [];
const { issueNumber } = await inquirer.prompt([
Prompts.getIssuePrompt(),
], initialValues);

let selection = {};
let notePath;
do {
selection = {};
selection = await inquirer.prompt([
Prompts.getComponentsPrompt(),
Prompts.getTypePrompt(),
Prompts.getMessagePromptInput(),
], initialValues);
if (selection.message === '') {
selection = Object.assign(
selection,
await inquirer.prompt([
Prompts.getMessagePromptEditor(),
]),
);
}

logger.info(`
Creating upgrade note with the following options:
- Issue: ${chalk.bold(issueNumber)}
- Component: ${chalk.bold(selection.components)}
- Type: ${chalk.bold(selection.type)}
- Message:
${chalk.bold(selection.message)}
`);

messages.push({
components: [selection.components],
type: selection.type,
message: selection.message,
});

// Save the note so far.
if (notePath) {
await createNote(issueNumber, messages, notePath);
logger.info(`Updated note at: ${chalk.underline(chalk.bold(notePath))}`);
} else {
notePath = await createNote(issueNumber, messages);
logger.info(`Note created at: ${chalk.underline(chalk.bold(notePath))}`);
}

selection = Object.assign(
selection,
await inquirer.prompt([
Prompts.getAddAnotherPrompt(),
], initialValues),
);
} while (selection.addAnother);
};
Loading

0 comments on commit b7d029a

Please sign in to comment.