import { parseCommitMessage } from 'commitlint-jira-utils' ; import { TRuleResolver } from '../../@types' ; const jiraTaskIdProjectKeyRuleResolver = ( parsed , _when , value ) => { const rawCommitMessage = parsed . raw ; if ( ! rawCommitMessage ) return [ false , 'Commit message should not be empty' ] ; const commitMessage = parseCommitMessage ( rawCommitMessage ) ; let isRuleValid = false ; let nonValidTaskId = null ; if ( ! value ) { return [ true ] ; } if ( typeof value !== 'string' && ! Array . isArray ( value ) && value ) { return [ false , 'jira project key should be a string or an array of strings' ] ; } commitMessage . commitTaskIds . forEach ( taskId => { if ( typeof value === 'string' && new RegExp ( `^${ value }` ) . test ( taskId ) ) { nonValidTaskId = taskId ; } if ( Array . isArray ( value ) ) { value . forEach ( projectKey => { if ( new RegExp ( `^${ projectKey }` ) . test ( taskId ) ) { nonValidTaskId = taskId ; } } ) ; } } ) ; isRuleValid = ! ! nonValidTaskId ; return [ isRuleValid , `${ nonValidTaskId } taskId must start with project key ${ typeof value === 'string' ? value : Array ( value ) . join ( ' or ' ) }` , ] ; } ; export default jiraTaskIdProjectKeyRuleResolver ;