-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed invalid custom scopes #203
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,6 @@ | |
}, | ||
"plugins": ["prettier"], | ||
"rules": { | ||
|
||
"no-param-reassign": "off" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,15 +17,21 @@ const addTicketNumber = (ticketNumber, config) => { | |
return `${ticketNumber.trim()} `; | ||
}; | ||
|
||
const addScope = (scope, config) => { | ||
const addScope = (scope, customScope, config) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could even consider calling this |
||
const separator = _.get(config, 'subjectSeparator', defaultSubjectSeparator); | ||
|
||
if (!scope) return separator; // it could be type === WIP. So there is no scope | ||
if (customScope) { | ||
scope = customScope; | ||
} | ||
|
||
if (!scope || scope === 'empty') { | ||
return separator; | ||
} | ||
|
||
return `(${scope.trim()})${separator}`; | ||
}; | ||
|
||
const addSubject = subject => _.trim(subject); | ||
const addSubject = (subject) => _.trim(subject); | ||
|
||
const addType = (type, config) => { | ||
const prefix = _.get(config, 'typePrefix', ''); | ||
|
@@ -35,10 +41,7 @@ const addType = (type, config) => { | |
}; | ||
|
||
const addBreaklinesIfNeeded = (value, breaklineChar = defaultBreaklineChar) => | ||
value | ||
.split(breaklineChar) | ||
.join('\n') | ||
.valueOf(); | ||
value.split(breaklineChar).join('\n').valueOf(); | ||
|
||
const addFooter = (footer, config) => { | ||
if (config && config.footerPrefix === '') return `\n\n${footer}`; | ||
|
@@ -74,7 +77,7 @@ module.exports = (answers, config) => { | |
// eslint-disable-next-line max-len | ||
const head = | ||
addType(answers.type, config) + | ||
addScope(answers.scope, config) + | ||
addScope(answers.scope, answers.customScope, config) + | ||
addTicketNumber(answers.ticketNumber, config) + | ||
addSubject(answers.subject.slice(0, config.subjectLimit)); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ const _ = require('lodash'); | |
const buildCommit = require('./build-commit'); | ||
const log = require('./logger'); | ||
|
||
const isNotWip = answers => answers.type.toLowerCase() !== 'wip'; | ||
const isNotWip = (answers) => answers.type.toLowerCase() !== 'wip'; | ||
|
||
const isValidateTicketNo = (value, config) => { | ||
if (!value) { | ||
|
@@ -13,13 +13,10 @@ const isValidateTicketNo = (value, config) => { | |
return true; | ||
} | ||
const reg = new RegExp(config.ticketNumberRegExp); | ||
if (value.replace(reg, '') !== '') { | ||
return false; | ||
} | ||
return true; | ||
return value.replace(reg, '') === ''; | ||
}; | ||
|
||
const getPreparedCommit = context => { | ||
const getPreparedCommit = (context) => { | ||
let message = null; | ||
if (fs.existsSync('./.git/COMMIT_EDITMSG')) { | ||
let preparedCommit = fs.readFileSync('./.git/COMMIT_EDITMSG', 'utf-8'); | ||
|
@@ -81,39 +78,52 @@ module.exports = { | |
message: messages.scope, | ||
choices(answers) { | ||
let scopes = []; | ||
|
||
if (scopeOverrides[answers.type]) { | ||
scopes = scopes.concat(scopeOverrides[answers.type]); | ||
} else { | ||
scopes = scopes.concat(config.scopes); | ||
} | ||
|
||
if (config.allowCustomScopes || scopes.length === 0) { | ||
scopes = scopes.concat([ | ||
new cz.Separator(), | ||
{ name: 'empty', value: false }, | ||
{ name: 'custom', value: 'custom' }, | ||
{ value: 'custom', name: config.customScopesName || 'custom scopes' }, | ||
]); | ||
} | ||
|
||
if (config.allowEmptyScopes || scopes.length === 0) { | ||
if (!config.allowCustomScopes) { | ||
scopes = scopes.concat([new cz.Separator()]); | ||
} | ||
scopes = scopes.concat([{ value: 'empty', name: config.emptyScopesName || 'empty scopes' }]); | ||
} | ||
|
||
if (config.allowCustomScopes || config.allowEmptyScopes) { | ||
scopes = scopes.concat([new cz.Separator()]); | ||
} | ||
|
||
return scopes; | ||
}, | ||
when(answers) { | ||
let hasScope = false; | ||
|
||
if (scopeOverrides[answers.type]) { | ||
hasScope = !!(scopeOverrides[answers.type].length > 0); | ||
hasScope = scopeOverrides[answers.type].length > 0; | ||
} else { | ||
hasScope = !!(config.scopes && config.scopes.length > 0); | ||
hasScope = config.scopes && config.scopes.length > 0; | ||
} | ||
|
||
if (!hasScope) { | ||
// TODO: Fix when possible | ||
// eslint-disable-next-line no-param-reassign | ||
answers.scope = skipEmptyScopes ? '' : 'custom'; | ||
return false; | ||
} | ||
return isNotWip(answers); | ||
|
||
return hasScope && isNotWip(answers); | ||
}, | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'scope', | ||
name: 'customScope', | ||
message: messages.customScope, | ||
when(answers) { | ||
return answers.scope === 'custom'; | ||
|
@@ -160,13 +170,11 @@ module.exports = { | |
message: messages.breaking, | ||
when(answers) { | ||
// eslint-disable-next-line max-len | ||
if ( | ||
return !!( | ||
config.askForBreakingChangeFirst || | ||
(config.allowBreakingChanges && config.allowBreakingChanges.indexOf(answers.type.toLowerCase()) >= 0) | ||
) { | ||
return true; | ||
} | ||
return false; // no breaking changes allowed unless specifed | ||
); | ||
// no breaking changes allowed unless specifed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may not need this comment anymore with the direct function return. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you can remove comments |
||
}, | ||
}, | ||
{ | ||
|
@@ -192,10 +200,10 @@ module.exports = { | |
}, | ||
]; | ||
|
||
questions = questions.filter(item => !skipQuestions.includes(item.name)); | ||
questions = questions.filter((item) => !skipQuestions.includes(item.name)); | ||
|
||
if (config.askForBreakingChangeFirst) { | ||
const isBreaking = oneQuestion => oneQuestion.name === 'breaking'; | ||
const isBreaking = (oneQuestion) => oneQuestion.name === 'breaking'; | ||
|
||
const breakingQuestion = _.filter(questions, isBreaking); | ||
const questionWithoutBreaking = _.reject(questions, isBreaking); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
allowEmptyScopes
default should be true because it makes it easier for people to use this tool. What are your thoughts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we make
allowEmptyScopes
defaulttrue
, would that be a breaking change? No problems if so, we just need to make the commit text have: