Skip to content
This repository was archived by the owner on Dec 23, 2019. It is now read-only.

Commit 28ba8dc

Browse files
author
Julien DONQUE
committed
🎉 initial commit
0 parents  commit 28ba8dc

File tree

10 files changed

+2394
-0
lines changed

10 files changed

+2394
-0
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "./node_modules/eslint-config-ovh/configs/es6-node.js"
3+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

CONTRIBUTING.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Contributing to cz-ovh-commit
2+
3+
This project accepts contributions. In order to contribute, you should
4+
pay attention to a few things:
5+
6+
1. your code must follow the coding style rules
7+
2. your code must be unit-tested
8+
3. your code must be documented
9+
4. your work must be signed (see below)
10+
5. you may contribute through GitHub Pull Requests
11+
12+
# Coding and documentation Style
13+
14+
Your code must pass `npm run lint`.
15+
Refer to https://github.com/ovh-ux/eslint-config-ovh
16+
17+
# Submitting Modifications
18+
19+
The contributions should be submitted through GitHub Pull Requests.
20+
21+
# Licensing for new files
22+
23+
cz-ovh-commit is licensed under a BSD-3 Clause license. Anything
24+
contributed to cz-ovh-commit must be released under this license.
25+
26+
When introducing a new file into the project, please make sure it has a
27+
copyright header making clear under which license it's being released.

LICENSE

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright (c) 2013-2017, OVH SAS.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in the
11+
documentation and/or other materials provided with the distribution.
12+
* Neither the name of OVH SAS nor the
13+
names of its contributors may be used to endorse or promote products
14+
derived from this software without specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY OVH SAS AND CONTRIBUTORS AS IS'' AND ANY
17+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL OVH SAS AND CONTRIBUTORS BE LIABLE FOR ANY
20+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
# cz-ovh-commit
3+
4+
![OVH component](https://user-images.githubusercontent.com/3379410/27423240-3f944bc4-5731-11e7-87bb-3ff603aff8a7.png)
5+
6+
[![Maintenance](https://img.shields.io/maintenance/yes/2017.svg)]() [![Chat on gitter](https://img.shields.io/gitter/room/ovh/ux.svg)](https://gitter.im/ovh/ux) [![Build Status](https://travis-ci.org/ovh-ux/cz-ovh-commit.svg)](https://travis-ci.org/ovh-ux/cz-ovh-commit) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
7+
8+
[![NPM](https://nodei.co/npm/cz-ovh-commit.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/cz-ovh-commit/)
9+
10+
Tool for unifying commit style inside OVH
11+
12+
# Installation
13+
14+
in a terminal:
15+
```bash
16+
npm i -g commitizen
17+
```
18+
19+
in the repos:
20+
```bash
21+
npm install --save-dev cz-ovh-commit
22+
commitizen init cz-ovh-commit --save-dev --save-exact
23+
git cz -a
24+
```
25+
26+
## Get the sources
27+
28+
```bash
29+
git clone https://github.com/ovh-ux/cz-ovh-commit.git
30+
cd cz-ovh-commit
31+
```
32+
33+
You've developed a new cool feature? Fixed an annoying bug? We'd be happy
34+
to hear from you!
35+
36+
see https://github.com/ovh-ux/cz-ovh-commit/blob/master/CONTRIBUTING.md
37+
38+
## Run the tests
39+
40+
no test for the moment
41+
42+
## Build the documentation
43+
44+
look in `ovh-config.js` for building your config file
45+
46+
# Related links
47+
48+
* Contribute: https://github.com/ovh-ux/cz-ovh-commit/blob/master/CONTRIBUTING.md
49+
* Report bugs: https://github.com/ovh-ux/cz-ovh-commit/issues
50+
* Get latest version: https://github.com/ovh-ux/cz-ovh-commit
51+
52+
# License
53+
54+
See https://github.com/ovh-ux/cz-ovh-commit/blob/master/LICENSE

index.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"use strict";
2+
3+
const inquirer = require("inquirer");
4+
const _ = require("lodash");
5+
const config = require("./ovh-config");
6+
7+
module.exports = {
8+
prompter (cz, commit) {
9+
inquirer
10+
.prompt([
11+
{
12+
type: "list",
13+
name: "type",
14+
message: "Please select the TYPE of your commit: ",
15+
choices: config.TYPES,
16+
when: true
17+
},
18+
{
19+
type: "list",
20+
name: "type",
21+
message: (answers) => `Please select the kind of ${answers.type}: `,
22+
choices: (answers) => config.SUB_TYPES[answers.type],
23+
when: (answers) => config.SUB_TYPES[answers.type] != null && config.SUB_TYPES[answers.type].length > 0,
24+
filter: (input) => _.trim(input)
25+
},
26+
{
27+
type: "input",
28+
name: "scope",
29+
message: "Please denote the SCOPE of the commit: (optional)",
30+
when: (answers) => _.includes(config.useScope, answers.type),
31+
filter: (input) => _.trim(input)
32+
},
33+
{
34+
type: "input",
35+
name: "header",
36+
message: "Please write a HEADER: (mandatory)",
37+
when: (answers) => _.includes(config.useHeader, answers.type),
38+
validate: (input) => input && _.trim(input).length < config.headerLength && _.trim(input).length !== 0 ? true : `Message should not be empty and should be shorter than ${config.headerLength} characters`,
39+
filter: (input) => _.trim(input, [" ."])
40+
},
41+
{
42+
type: "input",
43+
name: "body",
44+
message: "Please write a BODY: (optional)",
45+
when: (answers) => _.includes(config.useBody, answers.type),
46+
filter: (input) => _.trim(input)
47+
},
48+
{
49+
type: "input",
50+
name: "footer",
51+
message: "Please list the bug that has been closed, eg: #13, #42 or eg: crash when user click: (mandatory)",
52+
when: (answers) => answers.type === "fix",
53+
validate: (input) => input && _.trim(input).length !== 0 ? true : "List is empty",
54+
filter: (input) => _.trim(input)
55+
},
56+
{
57+
type: "input",
58+
name: "footer",
59+
message: "Please list any bug that has been closed, eg: #13, #42 or eg: crash when user click: (optional)",
60+
when: (answers) => _.includes(config.useFooter, answers.type) && answers.type !== "fix",
61+
filter: (input) => _.trim(input)
62+
},
63+
{
64+
type: "confirm",
65+
name: "confirm",
66+
message: (answers) => `your commit message:\n\n${config.parseCommitMsg(answers.type, answers.scope, answers.header, answers.body, answers.footer)}\n\nIs your commit message correct ?`
67+
}
68+
])
69+
.then((answers) => {
70+
const commitMessage = config.parseCommitMsg(answers.type, answers.scope, answers.header, answers.body, answers.footer);
71+
if (answers.confirm) {
72+
commit(commitMessage);
73+
} else {
74+
console.warn("Commit canceled, run `git cz` to retry");
75+
}
76+
});
77+
}
78+
};

ovh-config.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"use strict";
2+
3+
module.exports = {
4+
// These are the main types
5+
TYPES: [
6+
{ value: "first", name: "first commit" },
7+
{ value: "feat", name: "A new feature" },
8+
{ value: "fix", name: "A bug fix" },
9+
{ value: "chore", name: "Refactoring, Changing the build process or auxiliary tools and libraries etc" },
10+
{ value: "docs", name: "Documentation" },
11+
{ value: "style", name: "Cosmetics purpose" },
12+
{ value: "test", name: "Adding missing or correcting tests" }
13+
],
14+
15+
// sub types, if you want to be more specific, the type value is replaced by this one
16+
SUB_TYPES: {
17+
chore: [{ value: "merge", name: "A merge chore" }, { value: "refactor", name: "A refactor of code" }, { value: "chore", name: "Other" }]
18+
},
19+
20+
// emojis to add before a type, the type is the key
21+
EMOJIS: {
22+
feat: ":sparkles:",
23+
fix: ":ambulance:",
24+
docs: ":books:",
25+
merge: ":handshake:",
26+
refactor: ":tractor:",
27+
style: ":lipstick:"
28+
},
29+
30+
// should prompt about the scope
31+
useScope: ["feat", "fix", "chore", "docs", "style", "refactor"],
32+
33+
// should prompt about the header
34+
useHeader: ["feat", "chore", "style", "test", "docs", "refactor", "merge"],
35+
36+
// should prompt about the body
37+
useBody: ["feat", "chore", "style", "test"],
38+
39+
// should prompt about the footer which indicates bug fix
40+
useFooter: ["feat", "fix"],
41+
42+
// first line max header lenght
43+
headerLength: 72,
44+
45+
// parser for the commit msg, the only value guarented is type
46+
parseCommitMsg (type, rawScope = "", header = "", body = "", rawFooter = "") {
47+
const scope = rawScope ? `(${rawScope})` : "";
48+
const footer = rawFooter ? `closes : ${rawFooter}` : "";
49+
switch (type) {
50+
case "first":
51+
return ":tada: initial commit";
52+
case "fix":
53+
return `:ambulance: fix${scope}: fix ${rawFooter}`;
54+
case "docs":
55+
case "chore":
56+
case "merge":
57+
case "refactor":
58+
return `${this.EMOJIS[type] || ""} ${type}${scope}: ${header}`;
59+
case "feat":
60+
default:
61+
return `${this.EMOJIS[type] || ""} ${type}${scope}: ${header}\n\n${body}\n\n${footer}`;
62+
}
63+
}
64+
};

0 commit comments

Comments
 (0)