fix: harmonize parameters passed to getError
				
					
				
			This commit is contained in:
		
							parent
							
								
									4aad9cd490
								
							
						
					
					
						commit
						f96c660c1b
					
				
							
								
								
									
										6
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								index.js
									
									
									
									
									
								
							| @ -86,7 +86,7 @@ async function run(context, plugins) { | ||||
|     } | ||||
|   } catch (error) { | ||||
|     logger.error(`The command "${error.cmd}" failed with the error message ${error.stderr}.`); | ||||
|     throw getError('EGITNOPERMISSION', {options}); | ||||
|     throw getError('EGITNOPERMISSION', context); | ||||
|   } | ||||
| 
 | ||||
|   logger.success(`Allowed to push to the Git repository`); | ||||
| @ -98,8 +98,8 @@ async function run(context, plugins) { | ||||
|   context.releases = []; | ||||
| 
 | ||||
|   await pEachSeries(releasesToAdd, async ({lastRelease, currentRelease, nextRelease}) => { | ||||
|     if (context.branch['merge-range'] && !semver.satisfies(nextRelease.version, context.branch['merge-range'])) { | ||||
|       errors.push(getError('EINVALIDMAINTENANCEMERGE', {nextRelease, branch: context.branch})); | ||||
|     if (context.branch.mergeRange && !semver.satisfies(nextRelease.version, context.branch.mergeRange)) { | ||||
|       errors.push(getError('EINVALIDMAINTENANCEMERGE', {...context, nextRelease})); | ||||
|       return; | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -51,7 +51,7 @@ function maintenance({maintenance, release}) { | ||||
|       tags, | ||||
|       range: getRange(min, max), | ||||
|       accept: diff ? RELEASE_TYPE.slice(0, RELEASE_TYPE.indexOf(diff)) : [], | ||||
|       'merge-range': getRange(maintenanceMin, getUpperBound(range)), | ||||
|       mergeRange: getRange(maintenanceMin, getUpperBound(range)), | ||||
|     }; | ||||
|   }); | ||||
| } | ||||
|  | ||||
| @ -29,11 +29,9 @@ Please make sure to add the \`repositoryUrl\` to the [semantic-release configura | ||||
|       'docs/usage/configuration.md' | ||||
|     )}).`,
 | ||||
|   }), | ||||
|   EGITNOPERMISSION: ({options}) => ({ | ||||
|   EGITNOPERMISSION: ({options: {repositoryUrl}, branch: {name}}) => ({ | ||||
|     message: 'The push permission to the Git repository is required.', | ||||
|     details: `**semantic-release** cannot push the version tag to the branch \`${ | ||||
|       options.branch | ||||
|     }\` on remote Git repository with URL \`${options.repositoryUrl}\`.
 | ||||
|     details: `**semantic-release** cannot push the version tag to the branch \`${name}\` on remote Git repository with URL \`${repositoryUrl}\`.
 | ||||
| 
 | ||||
| Please refer to the [authentication configuration documentation](${linkify( | ||||
|       'docs/usage/ci-configuration.md#authentication' | ||||
| @ -41,7 +39,7 @@ Please refer to the [authentication configuration documentation](${linkify( | ||||
|       'docs/usage/configuration.md#repositoryurl' | ||||
|     )}) is configured with a [valid Git URL](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols).`,
 | ||||
|   }), | ||||
|   EINVALIDTAGFORMAT: ({tagFormat}) => ({ | ||||
|   EINVALIDTAGFORMAT: ({options: {tagFormat}}) => ({ | ||||
|     message: 'Invalid `tagFormat` option.', | ||||
|     details: `The [tagFormat](${linkify( | ||||
|       'docs/usage/configuration.md#tagformat' | ||||
| @ -49,7 +47,7 @@ Please refer to the [authentication configuration documentation](${linkify( | ||||
| 
 | ||||
| Your configuration for the \`tagFormat\` option is \`${stringify(tagFormat)}\`.`, | ||||
|   }), | ||||
|   ETAGNOVERSION: ({tagFormat}) => ({ | ||||
|   ETAGNOVERSION: ({options: {tagFormat}}) => ({ | ||||
|     message: 'Invalid `tagFormat` option.', | ||||
|     details: `The [tagFormat](${linkify( | ||||
|       'docs/usage/configuration.md#tagformat' | ||||
| @ -205,40 +203,26 @@ Your configuration for the problematic branch is \`${stringify(branch)}\`.`, | ||||
| 
 | ||||
| Your configuration for the problematic branches is \`${stringify(branches)}\`.`, | ||||
|   }), | ||||
|   EINVALIDNEXTVERSION: ({nextRelease, branch, commits, validBranches}) => ({ | ||||
|     message: `The release \`${nextRelease.version}\` on branch \`${ | ||||
|       branch.name | ||||
|     }\` cannot be published as it is out of range.`, | ||||
|     details: `Based on the releases published on other branches, only versions within the range \`${ | ||||
|       branch.range | ||||
|     }\` can be published from branch \`${branch.name}\`.
 | ||||
|   EINVALIDNEXTVERSION: ({nextRelease: {version}, branch: {name, range}, commits, validBranches}) => ({ | ||||
|     message: `The release \`${version}\` on branch \`${name}\` cannot be published as it is out of range.`, | ||||
|     details: `Based on the releases published on other branches, only versions within the range \`${range}\` can be published from branch \`${name}\`.
 | ||||
| 
 | ||||
| The following commit${commits.length > 1 ? 's are' : ' is'} responsible for the invalid release: | ||||
| ${commits.map(({commit: {short}, subject}) => `- ${subject} (${short})`).join('\n')} | ||||
| 
 | ||||
| ${ | ||||
|       commits.length > 1 ? 'Those commits' : 'This commit' | ||||
|     } should be moved to a valid branch with [git merge](https://git-scm.com/docs/git-merge) or [git cherry-pick](https://git-scm.com/docs/git-cherry-pick) and removed from branch \`${
 | ||||
|       branch.name | ||||
|     }\` with [git revert](https://git-scm.com/docs/git-revert) or [git reset](https://git-scm.com/docs/git-reset).
 | ||||
|     } should be moved to a valid branch with [git merge](https://git-scm.com/docs/git-merge) or [git cherry-pick](https://git-scm.com/docs/git-cherry-pick) and removed from branch \`${name}\` with [git revert](https://git-scm.com/docs/git-revert) or [git reset](https://git-scm.com/docs/git-reset).
 | ||||
| 
 | ||||
| A valid branch could be ${wordsList(validBranches.map(({name}) => `\`${name}\``))}. | ||||
| 
 | ||||
| See the [workflow configuration documentation](${linkify('docs/usage/workflow-configuration.md')}) for more details.`,
 | ||||
|   }), | ||||
|   EINVALIDMAINTENANCEMERGE: ({nextRelease, branch}) => ({ | ||||
|     message: `The release \`${nextRelease.version}\` on branch \`${ | ||||
|       branch.name | ||||
|     }\` cannot be published as it is out of range.`, | ||||
|     details: `Only releases within the range \`${branch['merge-range']}\` can be merged into the maintenance branch \`${ | ||||
|       branch.name | ||||
|     }\` and published to the \`${nextRelease.channel}\` distribution channel.
 | ||||
|   EINVALIDMAINTENANCEMERGE: ({nextRelease: {channel, gitTag, version}, branch: {mergeRange, name}}) => ({ | ||||
|     message: `The release \`${version}\` on branch \`${name}\` cannot be published as it is out of range.`, | ||||
|     details: `Only releases within the range \`${mergeRange}\` can be merged into the maintenance branch \`${name}\` and published to the \`${channel}\` distribution channel.
 | ||||
| 
 | ||||
| The branch \`${ | ||||
|       branch.name | ||||
|     }\` head should be [reset](https://git-scm.com/docs/git-reset) to a previous commit so the commit with tag \`${ | ||||
|       nextRelease.gitTag | ||||
|     }\` is removed from the branch history.
 | ||||
| The branch \`${name}\` head should be [reset](https://git-scm.com/docs/git-reset) to a previous commit so the commit with tag \`${gitTag}\` is removed from the branch history.
 | ||||
| 
 | ||||
| See the [workflow configuration documentation](${linkify('docs/usage/workflow-configuration.md')}) for more details.`,
 | ||||
|   }), | ||||
|  | ||||
| @ -34,7 +34,7 @@ module.exports = context => { | ||||
|               ({channel, version}) => | ||||
|                 channel === higherBranch.channel && | ||||
|                 channel !== branch.channel && | ||||
|                 (branch.type !== 'maintenance' || semver.gte(version, getLowerBound(branch['merge-range']))) | ||||
|                 (branch.type !== 'maintenance' || semver.gte(version, getLowerBound(branch.mergeRange))) | ||||
|             ) | ||||
|           ) | ||||
|             // Find ones that are not released on the building branch channel
 | ||||
|  | ||||
| @ -3,7 +3,12 @@ const AggregateError = require('aggregate-error'); | ||||
| const {isGitRepo, verifyTagName} = require('./git'); | ||||
| const getError = require('./get-error'); | ||||
| 
 | ||||
| module.exports = async ({cwd, env, options: {repositoryUrl, tagFormat, branches}}) => { | ||||
| module.exports = async context => { | ||||
|   const { | ||||
|     cwd, | ||||
|     env, | ||||
|     options: {repositoryUrl, tagFormat, branches}, | ||||
|   } = context; | ||||
|   const errors = []; | ||||
| 
 | ||||
|   if (!(await isGitRepo({cwd, env}))) { | ||||
| @ -14,14 +19,14 @@ module.exports = async ({cwd, env, options: {repositoryUrl, tagFormat, branches} | ||||
| 
 | ||||
|   // Verify that compiling the `tagFormat` produce a valid Git tag
 | ||||
|   if (!(await verifyTagName(template(tagFormat)({version: '0.0.0'})))) { | ||||
|     errors.push(getError('EINVALIDTAGFORMAT', {tagFormat})); | ||||
|     errors.push(getError('EINVALIDTAGFORMAT', context)); | ||||
|   } | ||||
| 
 | ||||
|   // Verify the `tagFormat` contains the variable `version` by compiling the `tagFormat` template
 | ||||
|   // with a space as the `version` value and verify the result contains the space.
 | ||||
|   // The space is used as it's an invalid tag character, so it's guaranteed to no be present in the `tagFormat`.
 | ||||
|   if ((template(tagFormat)({version: ' '}).match(/ /g) || []).length !== 1) { | ||||
|     errors.push(getError('ETAGNOVERSION', {tagFormat})); | ||||
|     errors.push(getError('ETAGNOVERSION', context)); | ||||
|   } | ||||
| 
 | ||||
|   branches.forEach(branch => { | ||||
|  | ||||
| @ -7,16 +7,14 @@ test('Maintenance branches - initial state', t => { | ||||
|   const maintenance = [{name: '1.x', channel: '1.x', tags: []}, {name: '1.1.x', tags: []}, {name: '1.2.x', tags: []}]; | ||||
|   const release = [{name: 'master', tags: []}]; | ||||
|   t.deepEqual( | ||||
|     normalize | ||||
|       .maintenance({maintenance, release}) | ||||
|       .map(({type, name, range, accept, channel, 'merge-range': maintenanceRange}) => ({ | ||||
|         type, | ||||
|         name, | ||||
|         range, | ||||
|         accept, | ||||
|         channel, | ||||
|         'merge-range': maintenanceRange, | ||||
|       })), | ||||
|     normalize.maintenance({maintenance, release}).map(({type, name, range, accept, channel, mergeRange}) => ({ | ||||
|       type, | ||||
|       name, | ||||
|       range, | ||||
|       accept, | ||||
|       channel, | ||||
|       mergeRange, | ||||
|     })), | ||||
|     [ | ||||
|       { | ||||
|         type: 'maintenance', | ||||
| @ -24,7 +22,7 @@ test('Maintenance branches - initial state', t => { | ||||
|         range: '>=1.1.0 <1.0.0', | ||||
|         accept: [], | ||||
|         channel: '1.1.x', | ||||
|         'merge-range': '>=1.1.0 <1.2.0', | ||||
|         mergeRange: '>=1.1.0 <1.2.0', | ||||
|       }, | ||||
|       { | ||||
|         type: 'maintenance', | ||||
| @ -32,7 +30,7 @@ test('Maintenance branches - initial state', t => { | ||||
|         range: '>=1.2.0 <1.0.0', | ||||
|         accept: [], | ||||
|         channel: '1.2.x', | ||||
|         'merge-range': '>=1.2.0 <1.3.0', | ||||
|         mergeRange: '>=1.2.0 <1.3.0', | ||||
|       }, | ||||
|       { | ||||
|         type: 'maintenance', | ||||
| @ -40,7 +38,7 @@ test('Maintenance branches - initial state', t => { | ||||
|         range: '>=1.3.0 <1.0.0', | ||||
|         accept: [], | ||||
|         channel: '1.x', | ||||
|         'merge-range': '>=1.3.0 <2.0.0', | ||||
|         mergeRange: '>=1.3.0 <2.0.0', | ||||
|       }, | ||||
|     ] | ||||
|   ); | ||||
| @ -63,13 +61,13 @@ test('Maintenance branches - cap range to first release present on default branc | ||||
|   t.deepEqual( | ||||
|     normalize | ||||
|       .maintenance({maintenance, release}) | ||||
|       .map(({type, name, range, accept, channel, 'merge-range': maintenanceRange}) => ({ | ||||
|       .map(({type, name, range, accept, channel, mergeRange: maintenanceRange}) => ({ | ||||
|         type, | ||||
|         name, | ||||
|         range, | ||||
|         accept, | ||||
|         channel, | ||||
|         'merge-range': maintenanceRange, | ||||
|         mergeRange: maintenanceRange, | ||||
|       })), | ||||
|     [ | ||||
|       { | ||||
| @ -78,7 +76,7 @@ test('Maintenance branches - cap range to first release present on default branc | ||||
|         range: '>=1.1.1 <1.2.0', | ||||
|         accept: ['patch'], | ||||
|         channel: 'name', | ||||
|         'merge-range': '>=1.1.0 <1.2.0', | ||||
|         mergeRange: '>=1.1.0 <1.2.0', | ||||
|       }, | ||||
|       { | ||||
|         type: 'maintenance', | ||||
| @ -86,7 +84,7 @@ test('Maintenance branches - cap range to first release present on default branc | ||||
|         range: '>=1.2.1 <1.3.0', | ||||
|         accept: ['patch'], | ||||
|         channel: '1.2.x', | ||||
|         'merge-range': '>=1.2.0 <1.3.0', | ||||
|         mergeRange: '>=1.2.0 <1.3.0', | ||||
|       }, | ||||
|       { | ||||
|         type: 'maintenance', | ||||
| @ -94,7 +92,7 @@ test('Maintenance branches - cap range to first release present on default branc | ||||
|         range: '>=1.5.0 <1.6.0', | ||||
|         accept: ['patch'], | ||||
|         channel: '1.x', | ||||
|         'merge-range': '>=1.3.0 <2.0.0', | ||||
|         mergeRange: '>=1.3.0 <2.0.0', | ||||
|       }, | ||||
|       { | ||||
|         type: 'maintenance', | ||||
| @ -102,7 +100,7 @@ test('Maintenance branches - cap range to first release present on default branc | ||||
|         range: '>=2.0.0 <1.6.0', | ||||
|         accept: [], | ||||
|         channel: '2.x.x', | ||||
|         'merge-range': '>=2.0.0 <3.0.0', | ||||
|         mergeRange: '>=2.0.0 <3.0.0', | ||||
|       }, | ||||
|     ] | ||||
|   ); | ||||
| @ -116,16 +114,14 @@ test('Maintenance branches - cap range to default branch last release if all rel | ||||
|   const release = [{name: 'master', tags: toTags(['1.0.0', '1.2.0', '1.3.0', '2.0.0'])}]; | ||||
| 
 | ||||
|   t.deepEqual( | ||||
|     normalize | ||||
|       .maintenance({maintenance, release}) | ||||
|       .map(({type, name, range, accept, channel, 'merge-range': maintenanceRange}) => ({ | ||||
|         type, | ||||
|         name, | ||||
|         range, | ||||
|         accept, | ||||
|         channel, | ||||
|         'merge-range': maintenanceRange, | ||||
|       })), | ||||
|     normalize.maintenance({maintenance, release}).map(({type, name, range, accept, channel, mergeRange}) => ({ | ||||
|       type, | ||||
|       name, | ||||
|       range, | ||||
|       accept, | ||||
|       channel, | ||||
|       mergeRange, | ||||
|     })), | ||||
|     [ | ||||
|       { | ||||
|         type: 'maintenance', | ||||
| @ -133,7 +129,7 @@ test('Maintenance branches - cap range to default branch last release if all rel | ||||
|         range: '>=1.3.0 <2.0.0', | ||||
|         accept: ['patch', 'minor'], | ||||
|         channel: '1.x', | ||||
|         'merge-range': '>=1.0.0 <2.0.0', | ||||
|         mergeRange: '>=1.0.0 <2.0.0', | ||||
|       }, | ||||
|       { | ||||
|         type: 'maintenance', | ||||
| @ -141,7 +137,7 @@ test('Maintenance branches - cap range to default branch last release if all rel | ||||
|         range: '>=2.0.0 <2.0.0', | ||||
|         accept: [], | ||||
|         channel: '2.x.x', | ||||
|         'merge-range': '>=2.0.0 <3.0.0', | ||||
|         mergeRange: '>=2.0.0 <3.0.0', | ||||
|       }, | ||||
|     ] | ||||
|   ); | ||||
|  | ||||
| @ -7,7 +7,7 @@ test('Return versions merged from release to maintenance branch, excluding lower | ||||
|       name: '2.x', | ||||
|       channel: '2.x', | ||||
|       type: 'maintenance', | ||||
|       'merge-range': '>=2.0.0 <3.0.0', | ||||
|       mergeRange: '>=2.0.0 <3.0.0', | ||||
|       tags: [ | ||||
|         {gitTag: 'v2.0.0@2.x', version: '2.0.0', channel: '2.x', gitHead: '111'}, | ||||
|         {gitTag: 'v2.0.0', version: '2.0.0', gitHead: '111'}, | ||||
| @ -255,7 +255,7 @@ test('Exclude versions merged from release to maintenance branch if they have th | ||||
|       name: '2.x', | ||||
|       channel: 'latest', | ||||
|       type: 'maintenance', | ||||
|       'merge-range': '>=2.0.0 <3.0.0', | ||||
|       mergeRange: '>=2.0.0 <3.0.0', | ||||
|       tags: [ | ||||
|         {gitTag: 'v2.0.0', version: '2.0.0', gitHead: '111'}, | ||||
|         {gitTag: 'v2.0.0', version: '2.0.0', gitHead: '111'}, | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user