From 7ef91d4ec7f0b456d033c523fb4c9ff45c3f5c54 Mon Sep 17 00:00:00 2001 From: Anton Maklakov Date: Wed, 20 Sep 2023 11:32:47 +0700 Subject: [PATCH] ci(danger): Add rules for branch naming --- .gitlab/dangerjs/dangerfile.js | 3 +++ .gitlab/dangerjs/mrSourceBranchName.js | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 .gitlab/dangerjs/mrSourceBranchName.js diff --git a/.gitlab/dangerjs/dangerfile.js b/.gitlab/dangerjs/dangerfile.js index d6084cf45c..80b5196725 100644 --- a/.gitlab/dangerjs/dangerfile.js +++ b/.gitlab/dangerjs/dangerfile.js @@ -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 && diff --git a/.gitlab/dangerjs/mrSourceBranchName.js b/.gitlab/dangerjs/mrSourceBranchName.js new file mode 100644 index 0000000000..ae76ed8e56 --- /dev/null +++ b/.gitlab/dangerjs/mrSourceBranchName.js @@ -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.`, + ); + } +};