提交 b03ed194 编写于 作者: T Tomas Vik

Merge branch 'fix-commit-lint' into 'main'

ci: fix the commit-lint script to reflect new squash logic

See merge request gitlab-org/gitlab-vscode-extension!275
......@@ -22,10 +22,10 @@ We use the following logic to lint your MR's commit messages:
```mermaid
graph TD
A{Is MR set to be squashed?} --no--> B[Every commit must be valid]
A --yes--> C{Is there at least one multiline commit?}
C --no--> D[MR title must be valid]
C --yes--> E[First multiline commit must be valid]
A{Are there multiple commits?} --no--> B[Commit must be valid]
A --yes--> C
C{Is MR set to be squashed?} --no--> D[Every commit must be valid]
C --yes--> E[MR title must be valid]
```
Following these conventions will result in a clear [changelog](./CHANGELOG.md) for every version.
......@@ -37,7 +37,7 @@ upon merge, the maintainer will be able to use its title as the final commit mes
## Is it okay that all my commits don't follow the conventions in a single MR?
If your MR contains only one logical change, you can enable the [Squash commits when merge request is accepted](https://gitlab.com/help/user/project/merge_requests/squash_and_merge) option. Then GitLab uses either the first multiline commit in your MR as commit message for the squashed changes or it uses the MR title.
If your MR contains multiple commits but only one logical change, you can enable the [Squash commits when merge request is accepted](https://gitlab.com/help/user/project/merge_requests/squash_and_merge) option. Then GitLab uses the MR title.
## What types can I use for my commit messages?
......
......@@ -46,32 +46,19 @@ async function isConventional(message) {
return lint(message, { ...config.rules, ...customRules }, { defaultIgnores: false });
}
const isMultiline = commit => {
const [, empty, body] = commit.split('\n');
return empty === '' && Boolean(body);
};
async function lintMr() {
const mr = await getMr();
const commits = await getCommitsInMr();
if (!mr.squash) {
if (!mr.squash || commits.length === 1) {
console.log(
'INFO: MR is not set to squash, every commit message needs to conform to conventional commit standard.\n',
'INFO: MR is not set to squash and/or there is only one commit. Every commit message needs to conform to conventional commit standard.\n',
);
return Promise.all(commits.map(isConventional));
}
const firstMultiline = commits.reverse().find(isMultiline); // first chronologically means last in the commits list
if (firstMultiline) {
console.log(
'INFO: MR is set to squash, GitLab is going to used the first multiline MR as commit message.\n',
);
return isConventional(firstMultiline).then(Array.of);
}
console.log(
'INFO: MR is set to squash, there is no multiline commit and so GitLab is going to use the MR title.\n' +
'INFO: MR is set to squash. GitLab is going to use the MR title.\n' +
"INFO: If the MR title isn't correct, you can fix it and rerun this CI Job.\n",
);
return isConventional(mr.title).then(Array.of);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册