2023-09-22 04:35:24 -04:00
const { recordRuleExitStatus } = require ( "./configParameters.js" ) ;
2023-09-20 00:32:47 -04:00
/ * *
* Throw Danger WARN if branch name contains more than one slash or uppercase letters
*
* @ dangerjs INFO
* /
module . exports = function ( ) {
2023-09-22 04:35:24 -04:00
const ruleName = "Source branch name" ;
2023-09-20 00:32:47 -04:00
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 ) {
2023-09-22 04:35:24 -04:00
recordRuleExitStatus ( ruleName , "Failed" ) ;
return warn (
2023-09-20 00:32:47 -04:00
` 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 ( ) ) {
2023-09-22 04:35:24 -04:00
recordRuleExitStatus ( ruleName , "Failed" ) ;
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. `
2023-09-20 00:32:47 -04:00
) ;
}
2023-09-22 04:35:24 -04:00
// At this point, the rule has passed
recordRuleExitStatus ( ruleName , "Passed" ) ;
2023-09-20 00:32:47 -04:00
} ;