Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: conventional-changelog/commitlint
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v14.1.0
Choose a base ref
...
head repository: conventional-changelog/commitlint
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v14.2.0
Choose a head ref
  • 5 commits
  • 20 files changed
  • 4 contributors

Commits on Nov 2, 2021

  1. chore: update typescript-eslint monorepo to v5.3.0 (#2847)

    Co-authored-by: Renovate Bot <bot@renovateapp.com>
    renovate[bot] and renovate-bot authored Nov 2, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ea52361 View commit details

Commits on Nov 6, 2021

  1. chore: update dependency eslint to v8.2.0 (#2849)

    Co-authored-by: Renovate Bot <bot@renovateapp.com>
    renovate[bot] and renovate-bot authored Nov 6, 2021
    Copy the full SHA
    7ea2e0f View commit details
  2. chore: update dependency eslint-plugin-jest to v25.2.3 (#2848)

    Co-authored-by: Renovate Bot <bot@renovateapp.com>
    renovate[bot] and renovate-bot authored Nov 6, 2021
    Copy the full SHA
    42b3984 View commit details
  3. feat(prompt): rewrite codebase to use inquirer - UPDATED with current…

    … master (#2697)
    
    * feat(prompt): rewrite codebase to use inquirer
    
    * fix(prompt): simplify logic used to compute maxLength
    
    * test(prompt): add basic input test
    
    * fix(prompt): small code refactor
    
    * fix: correct linting issues, add missing dependencies
    
    * fix: add missing tsconfig reference
    
    * fix: update lock file after merge
    
    * fix: correct issue with mac-os tab completion
    
    * chore: code review
    
    * fix: integrate review feedback
    
    * style: prettier
    
    Co-authored-by: Armano <armano2@users.noreply.github.com>
    escapedcat and armano2 authored Nov 6, 2021
    Copy the full SHA
    5105f43 View commit details
  4. v14.2.0

    escapedcat committed Nov 6, 2021
    Copy the full SHA
    bcbc9bf View commit details
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@ module.exports = {
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/triple-slash-reference': 'off',

// TODO: enable those rules?
'no-empty': 'off',
11 changes: 11 additions & 0 deletions @commitlint/prompt-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [14.2.0](https://github.com/conventional-changelog/commitlint/compare/v14.1.0...v14.2.0) (2021-11-06)


### Features

* **prompt:** rewrite codebase to use inquirer - UPDATED with current master ([#2697](https://github.com/conventional-changelog/commitlint/issues/2697)) ([5105f43](https://github.com/conventional-changelog/commitlint/commit/5105f43ea8093bce82fe4703c4c14a8210721924))





# [14.1.0](https://github.com/conventional-changelog/commitlint/compare/v14.0.0...v14.1.0) (2021-11-01)

**Note:** Version bump only for package @commitlint/prompt-cli
6 changes: 2 additions & 4 deletions @commitlint/prompt-cli/cli.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/usr/bin/env node
const execa = require('execa');
const inquirer = require('inquirer');
const {prompter} = require('@commitlint/prompt');

const _ = undefined;
const prompt = () => prompter(_, commit);

main().catch((err) => {
setTimeout(() => {
throw err;
@@ -21,7 +19,7 @@ function main() {
process.exit(1);
}
})
.then(() => prompt());
.then(() => prompter(inquirer, commit));
}

function isStageEmpty() {
7 changes: 4 additions & 3 deletions @commitlint/prompt-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@commitlint/prompt-cli",
"version": "14.1.0",
"version": "14.2.0",
"description": "commit prompt using commitlint.config.js",
"files": [
"cli.js"
@@ -36,8 +36,9 @@
"@commitlint/utils": "^14.0.0"
},
"dependencies": {
"@commitlint/prompt": "^14.1.0",
"execa": "^5.0.0"
"@commitlint/prompt": "^14.2.0",
"execa": "^5.0.0",
"inquirer": "^6.5.2"
},
"gitHead": "70f7f4688b51774e7ac5e40e896cdaa3f132b2bc"
}
11 changes: 11 additions & 0 deletions @commitlint/prompt/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [14.2.0](https://github.com/conventional-changelog/commitlint/compare/v14.1.0...v14.2.0) (2021-11-06)


### Features

* **prompt:** rewrite codebase to use inquirer - UPDATED with current master ([#2697](https://github.com/conventional-changelog/commitlint/issues/2697)) ([5105f43](https://github.com/conventional-changelog/commitlint/commit/5105f43ea8093bce82fe4703c4c14a8210721924))





# [14.1.0](https://github.com/conventional-changelog/commitlint/compare/v14.0.0...v14.1.0) (2021-11-01)

**Note:** Version bump only for package @commitlint/prompt
12 changes: 8 additions & 4 deletions @commitlint/prompt/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@commitlint/prompt",
"version": "14.1.0",
"version": "14.2.0",
"description": "commitizen prompt using commitlint.config.js",
"main": "./lib/index.js",
"files": [
@@ -37,16 +37,20 @@
"node": ">=v12"
},
"devDependencies": {
"@commitlint/config-angular": "^13.2.0",
"@commitlint/types": "^13.2.0",
"@commitlint/utils": "^14.0.0",
"commitizen": "4.2.4"
"@types/inquirer": "^6.5.0",
"commitizen": "^4.2.4",
"inquirer": "^6.5.2"
},
"dependencies": {
"@commitlint/ensure": "^14.1.0",
"@commitlint/load": "^14.1.0",
"@commitlint/types": "^14.0.0",
"chalk": "^4.0.0",
"throat": "^6.0.0",
"vorpal": "^1.12.0"
"inquirer": "^6.5.2",
"lodash": "^4.17.19"
},
"gitHead": "70f7f4688b51774e7ac5e40e896cdaa3f132b2bc"
}
16 changes: 4 additions & 12 deletions @commitlint/prompt/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import vorpal from 'vorpal';
import input from './input';
import inquirer from 'inquirer';
import {input} from './input';

type Commit = (input: string) => void;

/**
* Entry point for commitizen
* @param _ inquirer instance passed by commitizen, unused
* @param commit callback to execute with complete commit message
* @return {void}
*/
export function prompter(_: unknown, commit: Commit): void {
input(vorpal).then((message) => {
export function prompter(cz: typeof inquirer, commit: Commit): void {
input(cz.prompt).then((message) => {
commit(message);
});
}
96 changes: 96 additions & 0 deletions @commitlint/prompt/src/input.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import {Answers, PromptModule, QuestionCollection} from 'inquirer';
/// <reference path="./inquirer/inquirer.d.ts" />
import {input} from './input';
import chalk from 'chalk';

jest.mock(
'@commitlint/load',
() => {
return () => require('@commitlint/config-angular');
},
{
virtual: true,
}
);

test('should work with all fields filled', async () => {
const prompt = stub({
'input-custom': {
type: 'fix',
scope: 'test',
subject: 'subject',
body: 'body',
footer: 'footer',
},
});
const message = await input(prompt);
expect(message).toEqual('fix(test): subject\n' + 'body\n' + 'footer');
});

test('should work without scope', async () => {
const prompt = stub({
'input-custom': {
type: 'fix',
scope: '',
subject: 'subject',
body: 'body',
footer: 'footer',
},
});
const message = await input(prompt);
expect(message).toEqual('fix: subject\n' + 'body\n' + 'footer');
});

test('should fail without type', async () => {
const spy = jest.spyOn(console, 'error').mockImplementation();
const prompt = stub({
'input-custom': {
type: '',
scope: '',
subject: '',
body: '',
footer: '',
},
});
const message = await input(prompt);
expect(message).toEqual('');
expect(console.error).toHaveBeenCalledTimes(1);
expect(console.error).toHaveBeenLastCalledWith(
new Error(`⚠ ${chalk.bold('type')} may not be empty.`)
);
spy.mockRestore();
});

function stub(config: Record<string, Record<string, unknown>>): PromptModule {
const prompt = async (questions: QuestionCollection): Promise<any> => {
const result: Answers = {};
const resolvedConfig = Array.isArray(questions) ? questions : [questions];
for (const promptConfig of resolvedConfig) {
const configType = promptConfig.type || 'input';
const questions = config[configType];
if (!questions) {
throw new Error(`Unexpected config type: ${configType}`);
}
const answer = questions[promptConfig.name!];
if (answer == null) {
throw new Error(`Unexpected config name: ${promptConfig.name}`);
}
const validate = promptConfig.validate;
if (validate) {
const validationResult = validate(answer, result);
if (validationResult !== true) {
throw new Error(validationResult || undefined);
}
}

result[promptConfig.name!] = answer;
}
return result;
};
prompt.registerPrompt = () => {
return prompt;
};
prompt.restoreDefaultPrompts = () => true;
prompt.prompts = {};
return prompt as any as PromptModule;
}
65 changes: 27 additions & 38 deletions @commitlint/prompt/src/input.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
import load from '@commitlint/load';
import throat from 'throat';
import {DistinctQuestion, PromptModule} from 'inquirer';

import format from './library/format';
import getPrompt from './library/get-prompt';
import settings from './settings';
import {InputSetting, Prompter, Result} from './library/types';
import {getHasName, getMaxLength, getRules} from './library/utils';
import type {InputSetting, Result} from './library/types';

export default input;
import {getHasName, getMaxLength, getRules} from './library/utils';
import InputCustomPrompt from './inquirer/InputCustomPrompt';

/**
* Get user input by interactive prompt based on
* conventional-changelog-lint rules.
* @param prompter
* @return commit message
*/
async function input(prompter: () => Prompter): Promise<string> {
const results: Result = {
type: null,
scope: null,
subject: null,
body: null,
footer: null,
};

export async function input(prompter: PromptModule): Promise<string> {
const {rules} = await load();
const parts = ['type', 'scope', 'subject', 'body', 'footer'] as const;
const headerParts = ['type', 'scope', 'subject'];
@@ -33,31 +25,28 @@ async function input(prompter: () => Prompter): Promise<string> {
);
const maxLength = getMaxLength(headerLengthRule);

await Promise.all(
parts.map(
throat(1, async (input) => {
const inputRules = getRules(input, rules);
const inputSettings: InputSetting = settings[input];

if (headerParts.includes(input) && maxLength < Infinity) {
inputSettings.header = {
length: maxLength,
};
}

results[input] = await getPrompt(input, {
rules: inputRules,
settings: inputSettings,
results,
prompter,
});
})
)
).catch((err) => {
try {
const questions: DistinctQuestion<Result>[] = [];
prompter.registerPrompt('input-custom', InputCustomPrompt);

for (const input of parts) {
const inputSetting: InputSetting = settings[input];
const inputRules = getRules(input, rules);
if (headerParts.includes(input) && maxLength < Infinity) {
inputSetting.header = {
length: maxLength,
};
}
const question = getPrompt(input, inputRules, inputSetting);
if (question) {
questions.push(question);
}
}

const results = await prompter<Result>(questions);
return format(results);
} catch (err) {
console.error(err);
return '';
});

// Return the results
return format(results);
}
}
Loading