ci(danger): Add rules for branch naming

This commit is contained in:
Anton Maklakov 2023-09-20 11:32:47 +07:00
parent e12522df12
commit 7ef91d4ec7
2 changed files with 26 additions and 0 deletions

View File

@ -25,6 +25,9 @@ async function runChecks() {
// Checks for MR area labels
await require("./mrAreaLabels.js")();
// Checks for Source branch name
require("./mrSourceBranchName.js")();
// Add success log if no issues
if (
results.fails.length === 0 &&

View File

@ -0,0 +1,23 @@
/**
* Throw Danger WARN if branch name contains more than one slash or uppercase letters
*
* @dangerjs INFO
*/
module.exports = function () {
const sourceBranch = danger.gitlab.mr.source_branch;
// Check if the source branch name contains more than one slash
const slashCount = (sourceBranch.match(/\//g) || []).length;
if (slashCount > 1) {
return message(
`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
if (sourceBranch !== sourceBranch.toLowerCase()) {
return message(
`The source branch name \`${sourceBranch}\` contains uppercase letters. This can cause troubles on case-insensitive file systems (macOS). Please use only lowercase letters.`,
);
}
};