mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'dangerjs/improove_commit_messages' into 'master'
ci: danger: Improve check for git commit messages Closes IDF-6856 and IDF-6970 See merge request espressif/esp-idf!22655
This commit is contained in:
commit
8e65a673fa
@ -170,14 +170,6 @@ check_artifacts_expire_time:
|
|||||||
# check if we have set expire time for all artifacts
|
# check if we have set expire time for all artifacts
|
||||||
- python tools/ci/check_artifacts_expire_time.py
|
- python tools/ci/check_artifacts_expire_time.py
|
||||||
|
|
||||||
check_commit_msg:
|
|
||||||
extends: .pre_check_template
|
|
||||||
script:
|
|
||||||
- git status
|
|
||||||
- git log -n10 --oneline ${PIPELINE_COMMIT_SHA}
|
|
||||||
# commit start with "WIP: " need to be squashed before merge
|
|
||||||
- 'git log --pretty=%s origin/master..${PIPELINE_COMMIT_SHA} -- | grep -i "^WIP:" && exit 1 || exit 0'
|
|
||||||
|
|
||||||
check_test_scripts_build_test_rules:
|
check_test_scripts_build_test_rules:
|
||||||
extends:
|
extends:
|
||||||
- .pre_check_template
|
- .pre_check_template
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
* Modules with checks are stored in ".gitlab/dangerjs/<module_name>". To import them, use path relative to "dangerfile.js"
|
* Modules with checks are stored in ".gitlab/dangerjs/<module_name>". To import them, use path relative to "dangerfile.js"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const checkMrCommits = require(`./mrCommitsCommitMessage.js`);
|
|
||||||
|
|
||||||
async function runChecks() {
|
async function runChecks() {
|
||||||
// Checks for merge request title
|
// Checks for merge request title
|
||||||
require("./mrTitleNoDraftOrWip.js")();
|
require("./mrTitleNoDraftOrWip.js")();
|
||||||
|
@ -1,26 +1,70 @@
|
|||||||
/**
|
/**
|
||||||
* Check commit message are descriptive enough (longer that 10 characters)
|
* Check if commit messages are sufficiently descriptive (not too short).
|
||||||
*
|
*
|
||||||
* #TODO: this simple logic will be improved in future MRs - Jira IDF-6856.
|
* Search for commit messages that appear to be automatically generated by Gitlab or temporary messages and report them.
|
||||||
*
|
*
|
||||||
* @dangerjs WARN
|
* @dangerjs WARN
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
const shortCommitMessageThreshold = 10; // commit message is considered too short below this number of characters
|
const mrCommits = danger.gitlab.commits;
|
||||||
const mrCommit = danger.gitlab.commits;
|
|
||||||
|
|
||||||
let shortCommitMessages = [];
|
const detectRegexes = [
|
||||||
for (let i = 0; i < mrCommit.length; i++) {
|
/^Rebased.*onto.*/i, // Automatically generated message by Gitlab
|
||||||
const commitMessage = mrCommit[i].message;
|
/^Fast-forwarded.*to.*/i, // Automatically generated message by Gitlab
|
||||||
|
/^Applied suggestion to.*/i, // Automatically generated message by Gitlab
|
||||||
|
/^Suggestion applied for line.*/i, // Automatically generated message by Gitlab
|
||||||
|
/^Opened merge request/i, // Automatically generated message by Gitlab
|
||||||
|
/^Merged.*/i, // Automatically generated message by Gitlab
|
||||||
|
/^Opened issue #\d+:.*/i, // Automatically generated message by Gitlab
|
||||||
|
/^Closed issue #\d+:.*/i, // Automatically generated message by Gitlab
|
||||||
|
/^Tagged.*as.*/i, // Automatically generated message by Gitlab
|
||||||
|
/^Deleted tag.*/i, // Automatically generated message by Gitlab
|
||||||
|
/^WIP.*/i, // Message starts with prefix "WIP"
|
||||||
|
/^Cleaned.*/i, // Message starts "Cleaned"
|
||||||
|
/clean ?up/i, // Message contains "clean up"
|
||||||
|
/^[^A-Za-z0-9\s].*/, // Message starts with special characters
|
||||||
|
];
|
||||||
|
|
||||||
|
// Search for the messages in each commit
|
||||||
|
let partMessages = [];
|
||||||
|
for (const commit of mrCommits) {
|
||||||
|
const commitMessage = commit.message;
|
||||||
|
const commitMessageTitle = commit.title;
|
||||||
|
|
||||||
|
// Check if the commit message contains any Jira ticket references
|
||||||
|
const jiraTicketRegex = /[A-Z0-9]+-[0-9]+/g;
|
||||||
|
const jiraTicketMatches = commitMessage.match(jiraTicketRegex);
|
||||||
|
if (jiraTicketMatches) {
|
||||||
|
const jiraTicketNames = jiraTicketMatches.join(", ");
|
||||||
|
partMessages.push(
|
||||||
|
`- the commit message \`${commitMessageTitle}\` probably contains Jira ticket reference (\`${jiraTicketNames}\`). Please remove Jira tickets from commit messages.`
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the commit message matches any regex from "detectRegexes"
|
||||||
|
if (detectRegexes.some((regex) => commitMessage.match(regex))) {
|
||||||
|
partMessages.push(
|
||||||
|
`- the commit message \`${commitMessageTitle}\` appears to be a temporary or automatically generated message`
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the commit message is not too short
|
||||||
|
const shortCommitMessageThreshold = 20; // commit message is considered too short below this number of characters
|
||||||
if (commitMessage.length < shortCommitMessageThreshold) {
|
if (commitMessage.length < shortCommitMessageThreshold) {
|
||||||
shortCommitMessages.push(`- commit message: ${commitMessage}`);
|
partMessages.push(
|
||||||
|
`- the commit message \`${commitMessageTitle}\` may not be sufficiently descriptive`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shortCommitMessages.length) {
|
// Create report
|
||||||
warn(`Some of your commit messages may not be sufficiently descriptive (are shorter than ${shortCommitMessageThreshold} characters):
|
if (partMessages.length) {
|
||||||
\n${shortCommitMessages.join("")}
|
partMessages.sort();
|
||||||
\nYou might consider squashing commits (simplifying branch history) or updating those short commit messages.`);
|
let dangerMessage = `\nSome issues found for the commit messages in this MR:\n${partMessages.join('\n')}
|
||||||
}
|
\nPlease consider updating these commit messages. It is recommended to follow this [commit messages guide](https://gitlab.espressif.cn:6688/espressif/esp-idf/-/wikis/dev-proc/Commit-messages)`;
|
||||||
|
warn(dangerMessage);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
/**
|
/**
|
||||||
* Check if MR has not an excessive numbers of commits (if squashed)
|
* Check if MR has not an excessive numbers of commits (if squashed)
|
||||||
*
|
*
|
||||||
* #TODO: this simple logic will be improved in future MRs - Jira IDF-6856.
|
|
||||||
*
|
|
||||||
* @dangerjs INFO
|
* @dangerjs INFO
|
||||||
*/
|
*/
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
const tooManyCommitThreshold = 5; // above this number of commits, squash is recommended
|
const tooManyCommitThreshold = 2; // above this number of commits, squash commits is suggested
|
||||||
const mrCommits = danger.gitlab.commits;
|
const mrCommits = danger.gitlab.commits;
|
||||||
|
|
||||||
if (mrCommits.length > tooManyCommitThreshold) {
|
if (mrCommits.length > tooManyCommitThreshold) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user