mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-02 20:24:32 +02:00
Merge branch 'ci/danger-tracelog-checks-output' into 'master'
ci(danger-gitlab): Add CI job tracelog checks output Closes RDT-547 See merge request espressif/esp-idf!26154
This commit is contained in:
56
.gitlab/dangerjs/configParameters.js
Normal file
56
.gitlab/dangerjs/configParameters.js
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
let outputStatuses = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs the status of a rule with padded formatting and stores it in the `outputStatuses` array.
|
||||||
|
* If the rule already exists in the array, its status is updated.
|
||||||
|
* @param message The name of the rule
|
||||||
|
* @param status The output (exit) status of the rule
|
||||||
|
*/
|
||||||
|
function recordRuleExitStatus(message, status) {
|
||||||
|
// Check if the rule already exists in the array
|
||||||
|
const existingRecord = outputStatuses.find(
|
||||||
|
(rule) => rule.message === message
|
||||||
|
);
|
||||||
|
|
||||||
|
if (existingRecord) {
|
||||||
|
// Update the status of the existing rule
|
||||||
|
existingRecord.status = status;
|
||||||
|
} else {
|
||||||
|
// If the rule doesn't exist, add it to the array
|
||||||
|
outputStatuses.push({ message, status });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays all the rule output statuses stored in the `outputStatuses` array.
|
||||||
|
* Filters out any empty lines, sorts them alphabetically, and prints the statuses
|
||||||
|
* with a header and separator.
|
||||||
|
* These statuses are later displayed in CI job tracelog.
|
||||||
|
*/
|
||||||
|
function displayAllOutputStatuses() {
|
||||||
|
const lineLength = 100;
|
||||||
|
const sortedStatuses = outputStatuses.sort((a, b) =>
|
||||||
|
a.message.localeCompare(b.message)
|
||||||
|
);
|
||||||
|
|
||||||
|
const formattedLines = sortedStatuses.map((statusObj) => {
|
||||||
|
const paddingLength =
|
||||||
|
lineLength - statusObj.message.length - statusObj.status.length;
|
||||||
|
const paddedMessage = statusObj.message.padEnd(
|
||||||
|
statusObj.message.length + paddingLength,
|
||||||
|
"."
|
||||||
|
);
|
||||||
|
return `${paddedMessage} ${statusObj.status}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
"DangerJS checks (rules) output states:\n" + "=".repeat(lineLength + 2)
|
||||||
|
);
|
||||||
|
console.log(formattedLines.join("\n"));
|
||||||
|
console.log("=".repeat(lineLength + 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
displayAllOutputStatuses,
|
||||||
|
recordRuleExitStatus,
|
||||||
|
};
|
@@ -1,7 +1,8 @@
|
|||||||
|
const { displayAllOutputStatuses } = require("./configParameters.js");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
async function runChecks() {
|
async function runChecks() {
|
||||||
// Checks for merge request title
|
// Checks for merge request title
|
||||||
require("./mrTitleNoDraftOrWip.js")();
|
require("./mrTitleNoDraftOrWip.js")();
|
||||||
@@ -28,13 +29,16 @@ async function runChecks() {
|
|||||||
// Checks for Source branch name
|
// Checks for Source branch name
|
||||||
require("./mrSourceBranchName.js")();
|
require("./mrSourceBranchName.js")();
|
||||||
|
|
||||||
|
// Show DangerJS individual checks statuses - visible in CI job tracelog
|
||||||
|
displayAllOutputStatuses();
|
||||||
|
|
||||||
// Add success log if no issues
|
// Add success log if no issues
|
||||||
if (
|
if (
|
||||||
results.fails.length === 0 &&
|
results.fails.length === 0 &&
|
||||||
results.warnings.length === 0 &&
|
results.warnings.length === 0 &&
|
||||||
results.messages.length === 0
|
results.messages.length === 0
|
||||||
) {
|
) {
|
||||||
return message("Good Job! All checks are passing!");
|
return message("🎉 Good Job! All checks are passing!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,9 +1,12 @@
|
|||||||
|
const { recordRuleExitStatus } = require("./configParameters.js");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if MR has area labels (light blue labels)
|
* Check if MR has area labels (light blue labels)
|
||||||
*
|
*
|
||||||
* @dangerjs WARN
|
* @dangerjs WARN
|
||||||
*/
|
*/
|
||||||
module.exports = async function () {
|
module.exports = async function () {
|
||||||
|
const ruleName = "Merge request area labels";
|
||||||
const projectId = 103; // ESP-IDF
|
const projectId = 103; // ESP-IDF
|
||||||
const areaLabelColor = /^#d2ebfa$/i; // match color code (case-insensitive)
|
const areaLabelColor = /^#d2ebfa$/i; // match color code (case-insensitive)
|
||||||
const projectLabels = await danger.gitlab.api.Labels.all(projectId); // Get all project labels
|
const projectLabels = await danger.gitlab.api.Labels.all(projectId); // Get all project labels
|
||||||
@@ -13,8 +16,12 @@ module.exports = async function () {
|
|||||||
const mrLabels = danger.gitlab.mr.labels; // Get MR labels
|
const mrLabels = danger.gitlab.mr.labels; // Get MR labels
|
||||||
|
|
||||||
if (!mrLabels.some((label) => areaLabels.includes(label))) {
|
if (!mrLabels.some((label) => areaLabels.includes(label))) {
|
||||||
warn(
|
recordRuleExitStatus(ruleName, "Failed");
|
||||||
|
return warn(
|
||||||
`Please add some [area labels](${process.env.DANGER_GITLAB_HOST}/espressif/esp-idf/-/labels) to this MR.`
|
`Please add some [area labels](${process.env.DANGER_GITLAB_HOST}/espressif/esp-idf/-/labels) to this MR.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// At this point, the rule has passed
|
||||||
|
recordRuleExitStatus(ruleName, "Passed");
|
||||||
};
|
};
|
||||||
|
@@ -4,6 +4,7 @@ const {
|
|||||||
maximumBodyLineChars,
|
maximumBodyLineChars,
|
||||||
allowedTypes,
|
allowedTypes,
|
||||||
} = require("./mrCommitsConstants.js");
|
} = require("./mrCommitsConstants.js");
|
||||||
|
const { recordRuleExitStatus } = require("./configParameters.js");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that commit messages are based on the Espressif ESP-IDF project's rules for git commit messages.
|
* Check that commit messages are based on the Espressif ESP-IDF project's rules for git commit messages.
|
||||||
@@ -11,6 +12,7 @@ const {
|
|||||||
* @dangerjs WARN
|
* @dangerjs WARN
|
||||||
*/
|
*/
|
||||||
module.exports = async function () {
|
module.exports = async function () {
|
||||||
|
const ruleName = "Commit messages style";
|
||||||
const mrCommits = danger.gitlab.commits;
|
const mrCommits = danger.gitlab.commits;
|
||||||
const lint = require("@commitlint/lint").default;
|
const lint = require("@commitlint/lint").default;
|
||||||
|
|
||||||
@@ -154,6 +156,10 @@ module.exports = async function () {
|
|||||||
dangerMessage += AImessageSuggestion;
|
dangerMessage += AImessageSuggestion;
|
||||||
}
|
}
|
||||||
|
|
||||||
warn(dangerMessage);
|
recordRuleExitStatus(ruleName, "Failed");
|
||||||
|
return warn(dangerMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// At this point, the rule has passed
|
||||||
|
recordRuleExitStatus(ruleName, "Passed");
|
||||||
};
|
};
|
||||||
|
@@ -1,16 +1,23 @@
|
|||||||
|
const { recordRuleExitStatus } = require("./configParameters.js");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the author is accidentally making a commit using a personal email
|
* Check if the author is accidentally making a commit using a personal email
|
||||||
*
|
*
|
||||||
* @dangerjs INFO
|
* @dangerjs INFO
|
||||||
*/
|
*/
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
|
const ruleName = 'Commits from outside Espressif';
|
||||||
const mrCommitAuthorEmails = danger.gitlab.commits.map(commit => commit.author_email);
|
const mrCommitAuthorEmails = danger.gitlab.commits.map(commit => commit.author_email);
|
||||||
const mrCommitCommitterEmails = danger.gitlab.commits.map(commit => commit.committer_email);
|
const mrCommitCommitterEmails = danger.gitlab.commits.map(commit => commit.committer_email);
|
||||||
const emailPattern = /.*@espressif\.com/;
|
const emailPattern = /.*@espressif\.com/;
|
||||||
const filteredEmails = [...mrCommitAuthorEmails, ...mrCommitCommitterEmails].filter((email) => !emailPattern.test(email));
|
const filteredEmails = [...mrCommitAuthorEmails, ...mrCommitCommitterEmails].filter((email) => !emailPattern.test(email));
|
||||||
if (filteredEmails.length) {
|
if (filteredEmails.length) {
|
||||||
|
recordRuleExitStatus(ruleName, "Failed");
|
||||||
return message(
|
return message(
|
||||||
`Some of the commits were authored or committed by developers outside Espressif: ${filteredEmails.join(', ')}. Please check if this is expected.`
|
`Some of the commits were authored or committed by developers outside Espressif: ${filteredEmails.join(', ')}. Please check if this is expected.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// At this point, the rule has passed
|
||||||
|
recordRuleExitStatus(ruleName, 'Passed');
|
||||||
};
|
};
|
||||||
|
@@ -1,15 +1,22 @@
|
|||||||
|
const { recordRuleExitStatus } = require("./configParameters.js");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if MR has not an excessive numbers of commits (if squashed)
|
* Check if MR has not an excessive numbers of commits (if squashed)
|
||||||
*
|
*
|
||||||
* @dangerjs INFO
|
* @dangerjs INFO
|
||||||
*/
|
*/
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
|
const ruleName = 'Number of commits in merge request';
|
||||||
const tooManyCommitThreshold = 2; // above this number of commits, squash commits is suggested
|
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) {
|
||||||
|
recordRuleExitStatus(ruleName, "Passed (with suggestions)");
|
||||||
return message(
|
return message(
|
||||||
`You might consider squashing your ${mrCommits.length} commits (simplifying branch history).`
|
`You might consider squashing your ${mrCommits.length} commits (simplifying branch history).`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// At this point, the rule has passed
|
||||||
|
recordRuleExitStatus(ruleName, 'Passed');
|
||||||
};
|
};
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
const { recordRuleExitStatus } = require("./configParameters.js");
|
||||||
|
|
||||||
/** Check that there are valid JIRA links in MR description.
|
/** Check that there are valid JIRA links in MR description.
|
||||||
*
|
*
|
||||||
* This check extracts the "Related" section from the MR description and
|
* This check extracts the "Related" section from the MR description and
|
||||||
@@ -10,6 +12,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
module.exports = async function () {
|
module.exports = async function () {
|
||||||
|
const ruleName = 'Jira ticket references';
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const mrDescription = danger.gitlab.mr.description;
|
const mrDescription = danger.gitlab.mr.description;
|
||||||
const mrCommitMessages = danger.gitlab.commits.map(
|
const mrCommitMessages = danger.gitlab.commits.map(
|
||||||
@@ -26,6 +29,7 @@ module.exports = async function () {
|
|||||||
!sectionRelated.header || // No section Related in MR description or ...
|
!sectionRelated.header || // No section Related in MR description or ...
|
||||||
!jiraTicketRegex.test(sectionRelated.content) // no Jira links in section Related
|
!jiraTicketRegex.test(sectionRelated.content) // no Jira links in section Related
|
||||||
) {
|
) {
|
||||||
|
recordRuleExitStatus(ruleName, 'Passed (with suggestions)');
|
||||||
return message(
|
return message(
|
||||||
"Please consider adding references to JIRA issues in the `Related` section of the MR description."
|
"Please consider adding references to JIRA issues in the `Related` section of the MR description."
|
||||||
);
|
);
|
||||||
@@ -88,6 +92,9 @@ module.exports = async function () {
|
|||||||
createReport();
|
createReport();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// At this point, the rule has passed
|
||||||
|
recordRuleExitStatus(ruleName, 'Passed');
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -225,6 +232,7 @@ module.exports = async function () {
|
|||||||
let dangerMessage = `Some issues found for the related JIRA tickets in this MR:\n${partMessages.join(
|
let dangerMessage = `Some issues found for the related JIRA tickets in this MR:\n${partMessages.join(
|
||||||
"\n"
|
"\n"
|
||||||
)}`;
|
)}`;
|
||||||
warn(dangerMessage);
|
recordRuleExitStatus(ruleName, "Failed");
|
||||||
|
return warn(dangerMessage);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -1,17 +1,24 @@
|
|||||||
|
const { recordRuleExitStatus } = require("./configParameters.js");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if MR Description has accurate description".
|
* Check if MR Description has accurate description".
|
||||||
*
|
*
|
||||||
* @dangerjs WARN
|
* @dangerjs WARN
|
||||||
*/
|
*/
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
|
const ruleName = "Merge request sufficient description";
|
||||||
const mrDescription = danger.gitlab.mr.description;
|
const mrDescription = danger.gitlab.mr.description;
|
||||||
const descriptionChunk = mrDescription.match(/^([^#]*)/)[1].trim(); // Extract all text before the first section header (i.e., the text before the "## Release notes")
|
const descriptionChunk = mrDescription.match(/^([^#]*)/)[1].trim(); // Extract all text before the first section header (i.e., the text before the "## Release notes")
|
||||||
|
|
||||||
const shortMrDescriptionThreshold = 50; // Description is considered too short below this number of characters
|
const shortMrDescriptionThreshold = 50; // Description is considered too short below this number of characters
|
||||||
|
|
||||||
if (descriptionChunk.length < shortMrDescriptionThreshold) {
|
if (descriptionChunk.length < shortMrDescriptionThreshold) {
|
||||||
|
recordRuleExitStatus(ruleName, "Failed");
|
||||||
return warn(
|
return warn(
|
||||||
"The MR description looks very brief, please check if more details can be added."
|
"The MR description looks very brief, please check if more details can be added."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// At this point, the rule has passed
|
||||||
|
recordRuleExitStatus(ruleName, "Passed");
|
||||||
};
|
};
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
const { recordRuleExitStatus } = require("./configParameters.js");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if MR Description contains mandatory section "Release notes"
|
* Check if MR Description contains mandatory section "Release notes"
|
||||||
*
|
*
|
||||||
@@ -6,6 +8,7 @@
|
|||||||
* @dangerjs WARN (if section missing, is empty or wrong markdown format)
|
* @dangerjs WARN (if section missing, is empty or wrong markdown format)
|
||||||
*/
|
*/
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
|
const ruleName = 'Merge request Release Notes section';
|
||||||
const mrDescription = danger.gitlab.mr.description;
|
const mrDescription = danger.gitlab.mr.description;
|
||||||
const wiki_link = `${process.env.DANGER_GITLAB_HOST}/espressif/esp-idf/-/wikis/rfc/How-to-write-release-notes-properly`;
|
const wiki_link = `${process.env.DANGER_GITLAB_HOST}/espressif/esp-idf/-/wikis/rfc/How-to-write-release-notes-properly`;
|
||||||
|
|
||||||
@@ -15,8 +18,8 @@ module.exports = function () {
|
|||||||
|
|
||||||
const sectionReleaseNotes = mrDescription.match(regexSectionReleaseNotes);
|
const sectionReleaseNotes = mrDescription.match(regexSectionReleaseNotes);
|
||||||
if (!sectionReleaseNotes) {
|
if (!sectionReleaseNotes) {
|
||||||
warn(`The \`Release Notes\` section seems to be missing. Please check if the section header in MR description is present and in the correct markdown format ("## Release Notes").\n\nSee [Release Notes Format Rules](${wiki_link}).`);
|
recordRuleExitStatus(ruleName, "Failed");
|
||||||
return null;
|
return warn(`The \`Release Notes\` section seems to be missing. Please check if the section header in MR description is present and in the correct markdown format ("## Release Notes").\n\nSee [Release Notes Format Rules](${wiki_link}).`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const releaseNotesLines = sectionReleaseNotes[1].replace(/<!--[\s\S]*?-->/g, '')
|
const releaseNotesLines = sectionReleaseNotes[1].replace(/<!--[\s\S]*?-->/g, '')
|
||||||
@@ -55,9 +58,12 @@ module.exports = function () {
|
|||||||
if (error_output.length > 0) {
|
if (error_output.length > 0) {
|
||||||
// Paragraphs joined by double `\n`s.
|
// Paragraphs joined by double `\n`s.
|
||||||
error_output = [...error_output, `See [Release Notes Format Guide](${wiki_link}).`].join('\n\n');
|
error_output = [...error_output, `See [Release Notes Format Guide](${wiki_link}).`].join('\n\n');
|
||||||
warn(error_output);
|
recordRuleExitStatus(ruleName, "Failed");
|
||||||
|
return warn(error_output);
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
// At this point, the rule has passed
|
||||||
|
recordRuleExitStatus(ruleName, 'Passed');
|
||||||
};
|
};
|
||||||
|
|
||||||
function check_entry(entry) {
|
function check_entry(entry) {
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
const { recordRuleExitStatus } = require("./configParameters.js");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check the documentation files in this MR.
|
* Check the documentation files in this MR.
|
||||||
*
|
*
|
||||||
@@ -24,6 +26,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
module.exports = async function () {
|
module.exports = async function () {
|
||||||
|
const ruleName = 'Documentation translation';
|
||||||
let partMessages = []; // Create a blank field for future records of individual issues
|
let partMessages = []; // Create a blank field for future records of individual issues
|
||||||
const pathProject = "espressif/esp-idf";
|
const pathProject = "espressif/esp-idf";
|
||||||
const regexIncludeLink = /\.\.\sinclude::\s((\.\.\/)+)en\//;
|
const regexIncludeLink = /\.\.\sinclude::\s((\.\.\/)+)en\//;
|
||||||
@@ -90,6 +93,9 @@ module.exports = async function () {
|
|||||||
// Create a report with found issues with documents in MR
|
// Create a report with found issues with documents in MR
|
||||||
createReport();
|
createReport();
|
||||||
|
|
||||||
|
// At this point, the rule has passed
|
||||||
|
recordRuleExitStatus(ruleName, 'Passed');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates an object that represents the relationships between files in two different languages found in this MR.
|
* Generates an object that represents the relationships between files in two different languages found in this MR.
|
||||||
*
|
*
|
||||||
@@ -245,6 +251,7 @@ module.exports = async function () {
|
|||||||
|
|
||||||
// No docs issues found in MR, but translation labels have been added anyway
|
// No docs issues found in MR, but translation labels have been added anyway
|
||||||
if (!partMessages.length && translationLabelsPresent) {
|
if (!partMessages.length && translationLabelsPresent) {
|
||||||
|
recordRuleExitStatus(ruleName, "Failed");
|
||||||
return warn(
|
return warn(
|
||||||
`Please remove the \`needs translation: XX\` labels. For documents that need to translate from scratch, Doc team will translate them in the future. For the current stage, we only focus on updating exiting EN and CN translation to make them in sync.`
|
`Please remove the \`needs translation: XX\` labels. For documents that need to translate from scratch, Doc team will translate them in the future. For the current stage, we only focus on updating exiting EN and CN translation to make them in sync.`
|
||||||
);
|
);
|
||||||
@@ -261,9 +268,11 @@ module.exports = async function () {
|
|||||||
dangerMessage += `
|
dangerMessage += `
|
||||||
\nWhen synchronizing the EN and CN versions, please follow the [Documentation Code](https://docs.espressif.com/projects/esp-idf/zh_CN/latest/esp32/contribute/documenting-code.html#standardize-document-format). The total number of lines of EN and CN should be same.\n
|
\nWhen synchronizing the EN and CN versions, please follow the [Documentation Code](https://docs.espressif.com/projects/esp-idf/zh_CN/latest/esp32/contribute/documenting-code.html#standardize-document-format). The total number of lines of EN and CN should be same.\n
|
||||||
\nIf you have difficulty in providing translation, you can contact Documentation team by adding <kbd>needs translation: CN</kbd> or <kbd>needs translation: EN</kbd> labels into this MR and retrying Danger CI job. The documentation team will be automatically notified and will help you with the translations before the merge.\n`;
|
\nIf you have difficulty in providing translation, you can contact Documentation team by adding <kbd>needs translation: CN</kbd> or <kbd>needs translation: EN</kbd> labels into this MR and retrying Danger CI job. The documentation team will be automatically notified and will help you with the translations before the merge.\n`;
|
||||||
|
recordRuleExitStatus(ruleName, "Failed");
|
||||||
return warn(dangerMessage); // no "needs translation: XX" labels in MR; report issues as warn
|
return warn(dangerMessage); // no "needs translation: XX" labels in MR; report issues as warn
|
||||||
} else {
|
} else {
|
||||||
dangerMessage += `\nTranslation labels <kbd>needs translation: CN</kbd> or <kbd>needs translation: EN</kbd> were added - this will automatically notify the Documentation team to help you with translation issues.`;
|
dangerMessage += `\nTranslation labels <kbd>needs translation: CN</kbd> or <kbd>needs translation: EN</kbd> were added - this will automatically notify the Documentation team to help you with translation issues.`;
|
||||||
|
recordRuleExitStatus(ruleName, 'Passed (with suggestions)');
|
||||||
return message(dangerMessage); // "needs translation: XX" labels were found in MR and Docs team was notified; report issues as info
|
return message(dangerMessage); // "needs translation: XX" labels were found in MR and Docs team was notified; report issues as info
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,15 +1,22 @@
|
|||||||
|
const { recordRuleExitStatus } = require("./configParameters.js");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if MR is too large (more than 1000 lines of changes)
|
* Check if MR is too large (more than 1000 lines of changes)
|
||||||
*
|
*
|
||||||
* @dangerjs INFO
|
* @dangerjs INFO
|
||||||
*/
|
*/
|
||||||
module.exports = async function () {
|
module.exports = async function () {
|
||||||
|
const ruleName = "Merge request size (number of changed lines)";
|
||||||
const bigMrLinesOfCodeThreshold = 1000;
|
const bigMrLinesOfCodeThreshold = 1000;
|
||||||
const totalLines = await danger.git.linesOfCode();
|
const totalLines = await danger.git.linesOfCode();
|
||||||
|
|
||||||
if (totalLines > bigMrLinesOfCodeThreshold) {
|
if (totalLines > bigMrLinesOfCodeThreshold) {
|
||||||
|
recordRuleExitStatus(ruleName, "Passed (with suggestions)");
|
||||||
return message(
|
return message(
|
||||||
`This MR seems to be quite large (total lines of code: ${totalLines}), you might consider splitting it into smaller MRs`
|
`This MR seems to be quite large (total lines of code: ${totalLines}), you might consider splitting it into smaller MRs`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// At this point, the rule has passed
|
||||||
|
recordRuleExitStatus(ruleName, "Passed");
|
||||||
};
|
};
|
||||||
|
@@ -1,23 +1,31 @@
|
|||||||
|
const { recordRuleExitStatus } = require("./configParameters.js");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throw Danger WARN if branch name contains more than one slash or uppercase letters
|
* Throw Danger WARN if branch name contains more than one slash or uppercase letters
|
||||||
*
|
*
|
||||||
* @dangerjs INFO
|
* @dangerjs INFO
|
||||||
*/
|
*/
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
|
const ruleName = "Source branch name";
|
||||||
const sourceBranch = danger.gitlab.mr.source_branch;
|
const sourceBranch = danger.gitlab.mr.source_branch;
|
||||||
|
|
||||||
// Check if the source branch name contains more than one slash
|
// Check if the source branch name contains more than one slash
|
||||||
const slashCount = (sourceBranch.match(/\//g) || []).length;
|
const slashCount = (sourceBranch.match(/\//g) || []).length;
|
||||||
if (slashCount > 1) {
|
if (slashCount > 1) {
|
||||||
return message(
|
recordRuleExitStatus(ruleName, "Failed");
|
||||||
|
return warn(
|
||||||
`The source branch name \`${sourceBranch}\` contains more than one slash. This can cause troubles with git sync. Please rename the branch.`
|
`The source branch name \`${sourceBranch}\` contains more than one slash. This can cause troubles with git sync. Please rename the branch.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the source branch name contains any uppercase letters
|
// Check if the source branch name contains any uppercase letters
|
||||||
if (sourceBranch !== sourceBranch.toLowerCase()) {
|
if (sourceBranch !== sourceBranch.toLowerCase()) {
|
||||||
return message(
|
recordRuleExitStatus(ruleName, "Failed");
|
||||||
`The source branch name \`${sourceBranch}\` contains uppercase letters. This can cause troubles on case-insensitive file systems (macOS). Please use only lowercase letters.`,
|
return warn(
|
||||||
|
`The source branch name \`${sourceBranch}\` contains uppercase letters. This can cause troubles on case-insensitive file systems (macOS). Please use only lowercase letters.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// At this point, the rule has passed
|
||||||
|
recordRuleExitStatus(ruleName, "Passed");
|
||||||
};
|
};
|
||||||
|
@@ -1,22 +1,31 @@
|
|||||||
|
const { recordRuleExitStatus } = require("./configParameters.js");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if MR Title contains prefix "WIP: ...".
|
* Check if MR Title contains prefix "WIP: ...".
|
||||||
*
|
*
|
||||||
* @dangerjs WARN
|
* @dangerjs WARN
|
||||||
*/
|
*/
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
const mrTitle = danger.gitlab.mr.title;
|
const ruleName = 'Merge request not in Draft or WIP state';
|
||||||
|
const mrTitle = danger.gitlab.mr.title;
|
||||||
const regexes = [
|
const regexes = [
|
||||||
{ prefix: 'WIP', regex: /^WIP:/i },
|
{ prefix: "WIP", regex: /^WIP:/i },
|
||||||
{ prefix: 'W.I.P', regex: /^W\.I\.P/i },
|
{ prefix: "W.I.P", regex: /^W\.I\.P/i },
|
||||||
{ prefix: '[WIP]', regex: /^\[WIP/i },
|
{ prefix: "[WIP]", regex: /^\[WIP/i },
|
||||||
{ prefix: '[W.I.P]', regex: /^\[W\.I\.P/i },
|
{ prefix: "[W.I.P]", regex: /^\[W\.I\.P/i },
|
||||||
{ prefix: '(WIP)', regex: /^\(WIP/i },
|
{ prefix: "(WIP)", regex: /^\(WIP/i },
|
||||||
{ prefix: '(W.I.P)', regex: /^\(W\.I\.P/i },
|
{ prefix: "(W.I.P)", regex: /^\(W\.I\.P/i },
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const item of regexes) {
|
for (const item of regexes) {
|
||||||
if (item.regex.test(mrTitle)) {
|
if (item.regex.test(mrTitle)) {
|
||||||
return warn(`Please remove the \`${item.prefix}\` prefix from the MR name before merging this MR.`);
|
recordRuleExitStatus(ruleName, "Failed");
|
||||||
}
|
return warn(
|
||||||
}
|
`Please remove the \`${item.prefix}\` prefix from the MR name before merging this MR.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// At this point, the rule has passed
|
||||||
|
recordRuleExitStatus(ruleName, "Passed");
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user