Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cz commitlint #2547

Merged
merged 17 commits into from
Apr 29, 2021
Merged

Feature/cz commitlint #2547

merged 17 commits into from
Apr 29, 2021

Conversation

curly210102
Copy link
Contributor

@curly210102 curly210102 commented Apr 12, 2021

Description

  1. Develop a new commitizen adapter: cz-commitlint, it based on inquirer and share commitlint.config.js with commitizen.
  2. Add "prompt" field in commitlint.config.js, the interactive process can be customized in different shared configuration.
    e.g.@commitlint/config-conventional

Motivation and Context

Why I have to develop it

It is necessary to submit and lint with same rules. It is inconvenient and unreliable to configure two file for commitlint and commitizen. I investigated the possible solutions:

  1. commitlint/prompt/commitlint/prompt-cli: The interactive experience is not good.
  2. cz-customizable: Not support async load.

There is no perfect solution, so I tried to develop a new one, which is inspired by cz-conventional-changelog and compatible with the submission process of commitlint/prompt.

It based on inquirer instead of vorpal, can be used with commitizen, also a beginning of "Rewrite @commitlint/prompt for better usability"(Refer from Roadmap).

How it works

Screen.Recording.2021-04-13.at.3.13.38.AM.mov

Usage examples

Prompt Config

Configure Prompt Config of commitlint.config.js,customize the interactive steps.

// commitlint.config.js
// Example: set prompt config  @commitlint/config-conventional
module.exports = {
	parserPreset: 'conventional-changelog-conventionalcommits',
	rules: {},
	prompt: {
		questions: {
			type: {
				description: "Select the type of change that you're committing:",
				enum: {
					feat: {
						description: 'A new feature',
						title: 'Features',
						emoji: '✨',
					},
					fix: {
						description: 'A bug fix',
						title: 'Bug Fixes',
						emoji: '🐛',
					},
					docs: {
						description: 'Documentation only changes',
						title: 'Documentation',
						emoji: '📚',
					},
					style: {
						description:
							'Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)',
						title: 'Styles',
						emoji: '💎',
					},
					refactor: {
						description:
							'A code change that neither fixes a bug nor adds a feature',
						title: 'Code Refactoring',
						emoji: '📦',
					},
					perf: {
						description: 'A code change that improves performance',
						title: 'Performance Improvements',
						emoji: '🚀',
					},
					test: {
						description: 'Adding missing tests or correcting existing tests',
						title: 'Tests',
						emoji: '🚨',
					},
					build: {
						description:
							'Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)',
						title: 'Builds',
						emoji: '🛠',
					},
					ci: {
						description:
							'Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)',
						title: 'Continuous Integrations',
						emoji: '⚙️',
					},
					chore: {
						description: "Other changes that don't modify src or test files",
						title: 'Chores',
						emoji: '♻️',
					},
					revert: {
						description: 'Reverts a previous commit',
						title: 'Reverts',
						emoji: '🗑',
					},
				},
			},
			scope: {
				description:
					'What is the scope of this change (e.g. component or file name)',
			},
			subject: {
				description: 'Write a short, imperative tense description of the change',
			},
			body: {
				description: 'Provide a longer description of the change',
			},
			isBreaking: {
				description: 'Are there any breaking changes?',
			},
			breakingBody: {
				description:
					'A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself',
			},
			breaking: {
				description: 'Describe the breaking changes',
			},
			isIssueAffected: {
				description: 'Does this change affect any open issues?',
			},
			issuesBody: {
				description:
					'If issues are closed, the commit requires a body. Please enter a longer description of the commit itself',
			},
			issues: {
				description: 'Add issue references (e.g. "fix #123", "re #123".)',
			},
		},
	}
};

For more detail: Introduction of Prompt Config

Command-line Interaction

You can try it out in @commitlint/cz-commitlint folder.

yarn commit

How Has This Been Tested?

I have covered unit tests from underlying utilities to top entry.

Screen Shot 2021-04-13 at 3 36 24 AM

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@escapedcat
Copy link
Member

escapedcat commented Apr 13, 2021

Awesome @curly210102 ! Thank you for your efforts!

The prettier task fails:
image
Could you try running it locally? It might fix this.

@armano2 @byCedric @marionebl would you mind taking a look at this PR?

yarn.lock Outdated Show resolved Hide resolved
@AdeAttwood
Copy link
Member

@curly210102 only comments from me is the __test__ directory in src. Can we remove the __test__ directory and move the test files in the src folder to keep it consistent with the other package?

The other thing is more of a question that is where do the scopes come from? I tried adding an enum to the scope config and could not get it to work. I would be cool if we could do something like we can with the "type".

scope: {
    description: 'What is the scope of this change (e.g. component or file name)',
    enum: {
	  thing: {
		  description: 'References the thing component of the app',
		  title: 'Thing',
	  },
    },
},

@curly210102 really like this by the way.

@curly210102
Copy link
Contributor Author

@curly210102 only comments from me is the __test__ directory in src. Can we remove the __test__ directory and move the test files in the src folder to keep it consistent with the other package?

The other thing is more of a question that is where do the scopes come from? I tried adding an enum to the scope config and could not get it to work. I would be cool if we could do something like we can with the "type".

scope: {
    description: 'What is the scope of this change (e.g. component or file name)',
    enum: {
	  thing: {
		  description: 'References the thing component of the app',
		  title: 'Thing',
	  },
    },
},

@curly210102 really like this by the way.

@AdeAttwood thanks for review. I agree with the suggestion that move the test files flat with source code files to keep consistency.

The scopes is configured by "rules" field. As commitlint.config.js designed, the parts of commit message is decided by "rules", so it can be worked on both "lint" and "prompt"."prompt" field is only worked with prompt process, add auxiliary messages.Thus, if you'd like to add scope enums, need set 'rules -> scope-enum' at first.

rules: {
    'scope-enum': [2, 'always', ['thing']]
},
prompt: {
    questions: {
        scope: {
            description: 'What is the scope of this change (e.g. component or file name)',
            enum: {
                thing: {
                    description: 'References the thing component of the app',
                    title: 'Thing',
	            },
            },
        }
    }
}

@escapedcat
Copy link
Member

Thanks for this @curly210102 !
@AdeAttwood thanks for your feedback.
Will merge this in and create next release for testing.

@escapedcat escapedcat merged commit c77381d into conventional-changelog:master Apr 29, 2021
escapedcat added a commit that referenced this pull request Apr 29, 2021
@escapedcat
Copy link
Member

Published under next. Please give it a try.

@curly210102
Copy link
Contributor Author

curly210102 commented May 1, 2021 via email

yuth pushed a commit to aws-amplify/amplify-cli that referenced this pull request May 24, 2021
…elog (#7264)

This commit updates to @commitlint/cz-commitlint, which adds the `scope` enum from commitlint
without changing the interactive commit experience. Further motivation is explained in
conventional-changelog/commitlint#2547

Co-authored-by: John Corser <[email protected]>
cjihrig pushed a commit to ctjlewis/amplify-cli that referenced this pull request Jul 12, 2021
…elog (aws-amplify#7264)

This commit updates to @commitlint/cz-commitlint, which adds the `scope` enum from commitlint
without changing the interactive commit experience. Further motivation is explained in
conventional-changelog/commitlint#2547

Co-authored-by: John Corser <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants