Skip to content

Commit

Permalink
Merge pull request #11 from maykinmedia/feature/commitlint
Browse files Browse the repository at this point in the history
Feature/commitlint
  • Loading branch information
svenvandescheur authored Jan 19, 2024
2 parents 9e717ea + c4e2365 commit 02aa2de
Show file tree
Hide file tree
Showing 7 changed files with 1,425 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"browser": true,
"es2021": true
},
"ignorePatterns": ["dist/**/*", "**/*.css", "**/*.scss"],
"ignorePatterns": ["*.config.js", "dist/**/*", "**/*.css", "**/*.scss", "**/*.md"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ jobs:
- name: build package
run: npm pack

commitlint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install commitlint
run: |
npm install conventional-changelog-conventionalcommits
npm install commitlint@latest
- name: Validate PR commits with commitlint
if: github.event_name == 'pull_request'
run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose


lint:
runs-on: ubuntu-latest

Expand Down
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run commitlint ${1}
65 changes: 65 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Contribution guidelines

If you want to contribute, we ask you to follow these guidelines.

## Reporting bugs

If you have encountered a bug in this project, please check if an issue already exists in the list
of existing [issues][issues]. If such an issue does not exist, you can create a [new
issue][new_issue]. When writing the bug report, try to add a clear example that shows how to
reproduce said bug.

## Adding new features

Before making making changes to the code, we advise you to first check the list of existing
[issues][issues] for this project to see if an issue for the suggested changes already exists. If
such an issue does not exist, you can create a [new issue][new_issue]. Creating an issue gives an
opportunity for other developers to give tips even before you start coding.

### Code style

To keep the code clean and readable, this project uses:

- [`eslint`](https://www.npmjs.com/package/eslint) to format the code and keep diffs for pull
requests small

- [`prettier`](https://www.npmjs.com/package/prettier) to automatically format the code, including
import sorting

- [`commitlint`](https://www.npmjs.com/package/commitlint) to automatically check for the commit
message format (see next section).

Whenever a branch is pushed or a pull request is made, the code will be checked in CI by the tools
mentioned above, so make sure to install these tools and run them locally before pushing
branches/making pull requests.

### Making the changes

Please ensure that an issue exists before you start committing changes. Ideally, every commit can be
traced back to a Github issue.

On your local machine, create a new branch, and name it like:

- `feature/some-new-feature`, if the changes implement a new feature
- `issue/some-issue`, if the changes fix an issue

Once you have made changes or additions to the code, you can commit them (try to keep the commit
message descriptive but short). Make sure to format your commit message like
`:sparkles: #1 - feat: implement new feature`.

### Making a pull request

If all changes have been committed, you can push the branch to your fork of the repository and
create a pull request to the `main` branch of this project's repository. Your pull request will be
reviewed, if applicable, feedback will be given and if everything is approved, it will be merged.

When your branch is not ready yet to be reviewed, please mark it as draft so we don't run
unnecessary Chromatic builds (our quota are limited under the free plan).

### Reviews on releases

All pull requests will be reviewed by a project memeber before they are merged to a release branch.

[issues]: https://github.com/maykinmedia/maykin-ui/issues
[new_issue]: https://github.com/maykinmedia/maykin-ui/issues/new
[repository]: https://github.com/maykinmedia/maykin-ui
59 changes: 59 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* @example: :sparkles: #1 - feat: implement new feature
* @see {@link https://regexr.com/7qm0o RegExr}
* @type {RegExp}
*/
const COMMIT_PATTERN =
/(:\w+\:)(?:\s+(#\d+))?\s-\s([\w\s]+)(?:\((\w+)\))?:\s(.+)/;

// We can't use commitlint type enum here due to gitmoji.
const TYPE_ENUM = [
"build",
"chore",
"ci",
"docs",
"feat",
"fix",
"style",
"refactor",
"perf",
"test",
];

module.exports = {
plugins: ["commitlint-plugin-function-rules"],
rules: {
"header-full-stop": [2, "never"],
"function-rules/header-max-length": [
2, // level: error
"always",
/**
* Override header-max-length to provide pattern matching for commit headers.
* Format should be: ":gitmoji: #ticket - type: description
* @param header
* @return {[boolean,string]}
*/
({ header }) => {
const match = header.match(COMMIT_PATTERN);

if (match) {
const [header, gitmoji, ticket, type, scope, description] = match;
if (!TYPE_ENUM.includes(type)) {
// Message match but type is not in TYPE_ENUM.
return [false, `${type} is not in ${TYPE_ENUM.join(", ")}`];
}

// Message matched.
return [true, ""];
}

// Message did not match format.
return [
false,
"Commit message format invalid: \n\nFormat: <gitmoji>[ [ticket]] - <type>[([optional scope])]: <description>.\nExample: :sparkles: #1 - feat: implement new feature",
];
q;
},
],
},
};
Loading

0 comments on commit 02aa2de

Please sign in to comment.