Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
feat(deps): migrates to commitlint-plugin-spend
Browse files Browse the repository at this point in the history
/spend 5m
  • Loading branch information
nico-i committed Feb 4, 2024
1 parent a653f2c commit 3c603c7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 45 deletions.
47 changes: 2 additions & 45 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,7 @@
module.exports = {
extends: [`@commitlint/config-conventional`],
rules: {
"require-spent": [2, `always`],
spend: [2, `always`],
},
plugins: [
{
rules: {
"require-spent": ({ raw }: { raw: string }) => {
const commitMessage = raw.trim();

const msgSplit = commitMessage.split(`\n`);
if (msgSplit.length < 3)
return [
false,
`'/spent' directive must be in new line separated by another new line`,
]; // ensure that commit message has more than 1 line

if (msgSplit[1] !== ``)
return [
false,
`'/spent' directive must be separated by another new line`,
]; // ensure that commit message has more than 1 line

const spentSplit = msgSplit[msgSplit.length - 1].split(` `);
const isCorrectCommand =
spentSplit[0] === `/spent` || spentSplit[0] === `/spend`;
if (spentSplit.length < 2 || !isCorrectCommand)
return [
false,
`the last line of a commit must be a '/spent' directive`,
]; // ensure that commit message ends with '/spent'

const spentTimeValue = spentSplit[spentSplit.length - 1].trim();
const regex = /^(\d|[1-5]\d)m|(([1-9]|[1-4]\d)h(\d|[1-5]\d)?m?)$/; // 1h30, 30m, 1h, 1h30m, 1h30, 1h30m
const matches = regex.exec(spentTimeValue);

if (!matches || matches[0].length !== spentTimeValue.length) {
// ensure that spent time value is valid
return [
false,
`Commit message must end with a valid spent time with the format '/spent 1h30' or '/spent 30m' or '/spent 1h'`,
];
}
return [true];
},
},
},
],
plugins: [`commitlint-plugin-spend`],
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"@typescript-eslint/parser": "^6.20.0",
"@vitest/coverage-v8": "^1.2.2",
"c8": "^9.1.0",
"commitlint-plugin-spend": "^1.0.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard": "^17.1.0",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5226,6 +5226,11 @@ commander@^7.2.0:
resolved "https://registry.yarnpkg.com/commander/-/commander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7"
integrity sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==

commitlint-plugin-spend@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/commitlint-plugin-spend/-/commitlint-plugin-spend-1.0.1.tgz#8dc8a0cfb48a923a584cc64d86e03d651e544417"
integrity sha512-YIz6WSQQVqyGWPLSB3m5LuVlNuEDYkK50bafAufCYw7UmONDN1T4z8oqGLMIpKbCMyBf3NORjLI3HD1tJunqAw==

common-path-prefix@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/common-path-prefix/-/common-path-prefix-3.0.0.tgz#7d007a7e07c58c4b4d5f433131a19141b29f11e0"
Expand Down

0 comments on commit 3c603c7

Please sign in to comment.