Skip to content

Commit 009773b

Browse files
committed
ci: 🎡 commitlint msg to a new level
added git-cz for cli interactive git commit messages, also changes the requirements for commit messages
1 parent 6fae555 commit 009773b

File tree

3 files changed

+152
-19
lines changed

3 files changed

+152
-19
lines changed

commitlint.config.cjs

Lines changed: 119 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,124 @@
1+
// Credit: @ONEARMY/community-platform
2+
// https://github.com/ONEARMY/community-platform/blob/master/commitlint.config.js
3+
4+
/* global module */
15
module.exports = {
2-
extends: [],
3-
rules: {
4-
"header-min-length": [2, "always", 15],
5-
"header-case-start-capital": [2, "always"],
6-
"header-end-period": [2, "always"],
7-
},
8-
plugins: [
9-
{
10-
rules: {
11-
"header-case-start-capital": ({ raw }) => {
12-
return [
13-
/^[A-Z]/.test(raw),
14-
"Commit message must start with a capital letter.",
15-
];
16-
},
17-
"header-end-period": ({ header }) => {
18-
return [/\.$/.test(header), "Commit message must end with a period"];
6+
extends: ["@commitlint/config-conventional"],
7+
/** Add optional custom formatter */
8+
// Temporarily removed due to unresolved error: https://app.circleci.com/pipelines/github/ONEARMY/community-platform/5891/workflows/59757a07-b416-43be-9a57-eedc1190d5a0/jobs/44654
9+
// formatter: path.resolve(__dirname, 'commitlint.format.ts'),
10+
/** Add optional override rules (https://www.npmjs.com/package/@commitlint/config-conventional) */
11+
// rules: {},
12+
helpUrl:
13+
"run `npm commit` for interactive prompt or see examples at\nhttps://www.conventionalcommits.org",
14+
// Interactive prompts, called via `yarn commit`
15+
prompt: {
16+
settings: {},
17+
messages: {
18+
skip: ":skip",
19+
max: "upper %d chars",
20+
min: "%d chars at least",
21+
emptyWarning: "can not be empty",
22+
upperLimitWarning: "over limit",
23+
lowerLimitWarning: "below limit",
24+
},
25+
26+
questions: {
27+
type: {
28+
description: "Select the type of change that you're committing:",
29+
enum: {
30+
feat: {
31+
description: "A new feature",
32+
title: "Features",
33+
emoji: "✨",
34+
},
35+
fix: {
36+
description: "A bug fix",
37+
title: "Bug Fixes",
38+
emoji: "🐛",
39+
},
40+
docs: {
41+
description: "Documentation only changes",
42+
title: "Documentation",
43+
emoji: "📚",
44+
},
45+
style: {
46+
description:
47+
"Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)",
48+
title: "Styles",
49+
emoji: "💎",
50+
},
51+
refactor: {
52+
description:
53+
"A code change that neither fixes a bug nor adds a feature",
54+
title: "Code Refactoring",
55+
emoji: "📦",
56+
},
57+
perf: {
58+
description: "A code change that improves performance",
59+
title: "Performance Improvements",
60+
emoji: "🚀",
61+
},
62+
test: {
63+
description: "Adding missing tests or correcting existing tests",
64+
title: "Tests",
65+
emoji: "🚨",
66+
},
67+
build: {
68+
description:
69+
"Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)",
70+
title: "Builds",
71+
emoji: "🛠",
72+
},
73+
ci: {
74+
description:
75+
"Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)",
76+
title: "Continuous Integrations",
77+
emoji: "⚙️",
78+
},
79+
chore: {
80+
description: "Other changes that don't modify src or test files",
81+
title: "Chores",
82+
emoji: "♻️",
83+
},
84+
revert: {
85+
description: "Reverts a previous commit",
86+
title: "Reverts",
87+
emoji: "🗑",
88+
},
1989
},
2090
},
91+
scope: {
92+
description:
93+
"What is the scope of this change (e.g. component or file name)",
94+
},
95+
subject: {
96+
description:
97+
"Write a short, imperative tense description of the change",
98+
},
99+
body: {
100+
description: "Provide a longer description of the change",
101+
},
102+
isBreaking: {
103+
description: "Are there any breaking changes?",
104+
},
105+
breakingBody: {
106+
description:
107+
"A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself",
108+
},
109+
breaking: {
110+
description: "Describe the breaking changes",
111+
},
112+
isIssueAffected: {
113+
description: "Does this change affect any open issues?",
114+
},
115+
issuesBody: {
116+
description:
117+
"If issues are closed, the commit requires a body. Please enter a longer description of the commit itself",
118+
},
119+
issues: {
120+
description: 'Add issue references (e.g. "fix #123", "re #123".)',
121+
},
21122
},
22-
],
123+
},
23124
};

commitlint.format.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { FormattableReport, Formatter } from "@commitlint/types";
2+
3+
// Custom formatter for commitlint message
4+
export const formatter: Formatter = function (report, options) {
5+
const { results, valid } = report as IFormatReport;
6+
if (results && !valid) {
7+
console.log("\nCommit needs to be formatted as conventional commit");
8+
console.log("\n<type>[optional scope]: <description>\n");
9+
for (const result of results) {
10+
if (result.errors) {
11+
for (const error of result.errors) {
12+
console.log(result.input);
13+
console.log("\x1b[31m%s\x1b[0m", "✖ " + error.message);
14+
}
15+
}
16+
}
17+
}
18+
console.log("\n");
19+
console.log(options.helpUrl);
20+
console.log("\n");
21+
return "";
22+
};
23+
24+
module.exports = formatter;
25+
26+
// Fix type definition for formattable report
27+
interface IFormatReport extends FormattableReport {
28+
errorCount: number;
29+
valid: boolean;
30+
warningCount: number;
31+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"prepare": "husky",
1010
"lint": "eslint . --ext js,jsx,ts,tsx --report-unused-disable-directives --max-warnings 0",
1111
"lint:fix": "eslint . --ext js,jsx,ts,tsx --fix",
12-
"format": "prettier --config .prettierrc.json --write --ignore-unknown \"**/*.{ts,tsx}\""
12+
"format": "prettier --config .prettierrc.json --write --ignore-unknown \"**/*.{ts,tsx}\"",
13+
"commit": "npx git-cz"
1314
},
1415
"dependencies": {
1516
"@radix-ui/react-collapsible": "^1.0.3",

0 commit comments

Comments
 (0)