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) { |   } catch (error) { | ||||||
|     logger.error(`The command "${error.cmd}" failed with the error message ${error.stderr}.`); |     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`); |   logger.success(`Allowed to push to the Git repository`); | ||||||
| @ -98,8 +98,8 @@ async function run(context, plugins) { | |||||||
|   context.releases = []; |   context.releases = []; | ||||||
| 
 | 
 | ||||||
|   await pEachSeries(releasesToAdd, async ({lastRelease, currentRelease, nextRelease}) => { |   await pEachSeries(releasesToAdd, async ({lastRelease, currentRelease, nextRelease}) => { | ||||||
|     if (context.branch['merge-range'] && !semver.satisfies(nextRelease.version, context.branch['merge-range'])) { |     if (context.branch.mergeRange && !semver.satisfies(nextRelease.version, context.branch.mergeRange)) { | ||||||
|       errors.push(getError('EINVALIDMAINTENANCEMERGE', {nextRelease, branch: context.branch})); |       errors.push(getError('EINVALIDMAINTENANCEMERGE', {...context, nextRelease})); | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -51,7 +51,7 @@ function maintenance({maintenance, release}) { | |||||||
|       tags, |       tags, | ||||||
|       range: getRange(min, max), |       range: getRange(min, max), | ||||||
|       accept: diff ? RELEASE_TYPE.slice(0, RELEASE_TYPE.indexOf(diff)) : [], |       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' |       'docs/usage/configuration.md' | ||||||
|     )}).`,
 |     )}).`,
 | ||||||
|   }), |   }), | ||||||
|   EGITNOPERMISSION: ({options}) => ({ |   EGITNOPERMISSION: ({options: {repositoryUrl}, branch: {name}}) => ({ | ||||||
|     message: 'The push permission to the Git repository is required.', |     message: 'The push permission to the Git repository is required.', | ||||||
|     details: `**semantic-release** cannot push the version tag to the branch \`${ |     details: `**semantic-release** cannot push the version tag to the branch \`${name}\` on remote Git repository with URL \`${repositoryUrl}\`.
 | ||||||
|       options.branch |  | ||||||
|     }\` on remote Git repository with URL \`${options.repositoryUrl}\`.
 |  | ||||||
| 
 | 
 | ||||||
| Please refer to the [authentication configuration documentation](${linkify( | Please refer to the [authentication configuration documentation](${linkify( | ||||||
|       'docs/usage/ci-configuration.md#authentication' |       'docs/usage/ci-configuration.md#authentication' | ||||||
| @ -41,7 +39,7 @@ Please refer to the [authentication configuration documentation](${linkify( | |||||||
|       'docs/usage/configuration.md#repositoryurl' |       '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).`,
 |     )}) 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.', |     message: 'Invalid `tagFormat` option.', | ||||||
|     details: `The [tagFormat](${linkify( |     details: `The [tagFormat](${linkify( | ||||||
|       'docs/usage/configuration.md#tagformat' |       '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)}\`.`, | Your configuration for the \`tagFormat\` option is \`${stringify(tagFormat)}\`.`, | ||||||
|   }), |   }), | ||||||
|   ETAGNOVERSION: ({tagFormat}) => ({ |   ETAGNOVERSION: ({options: {tagFormat}}) => ({ | ||||||
|     message: 'Invalid `tagFormat` option.', |     message: 'Invalid `tagFormat` option.', | ||||||
|     details: `The [tagFormat](${linkify( |     details: `The [tagFormat](${linkify( | ||||||
|       'docs/usage/configuration.md#tagformat' |       '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)}\`.`, | Your configuration for the problematic branches is \`${stringify(branches)}\`.`, | ||||||
|   }), |   }), | ||||||
|   EINVALIDNEXTVERSION: ({nextRelease, branch, commits, validBranches}) => ({ |   EINVALIDNEXTVERSION: ({nextRelease: {version}, branch: {name, range}, commits, validBranches}) => ({ | ||||||
|     message: `The release \`${nextRelease.version}\` on branch \`${ |     message: `The release \`${version}\` on branch \`${name}\` cannot be published as it is out of range.`, | ||||||
|       branch.name |     details: `Based on the releases published on other branches, only versions within the range \`${range}\` can be published from 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}\`.
 |  | ||||||
| 
 | 
 | ||||||
| The following commit${commits.length > 1 ? 's are' : ' is'} responsible for the invalid release: | The following commit${commits.length > 1 ? 's are' : ' is'} responsible for the invalid release: | ||||||
| ${commits.map(({commit: {short}, subject}) => `- ${subject} (${short})`).join('\n')} | ${commits.map(({commit: {short}, subject}) => `- ${subject} (${short})`).join('\n')} | ||||||
| 
 | 
 | ||||||
| ${ | ${ | ||||||
|       commits.length > 1 ? 'Those commits' : 'This commit' |       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 \`${
 |     } 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).
 | ||||||
|       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}\``))}. | A valid branch could be ${wordsList(validBranches.map(({name}) => `\`${name}\``))}. | ||||||
| 
 | 
 | ||||||
| See the [workflow configuration documentation](${linkify('docs/usage/workflow-configuration.md')}) for more details.`,
 | See the [workflow configuration documentation](${linkify('docs/usage/workflow-configuration.md')}) for more details.`,
 | ||||||
|   }), |   }), | ||||||
|   EINVALIDMAINTENANCEMERGE: ({nextRelease, branch}) => ({ |   EINVALIDMAINTENANCEMERGE: ({nextRelease: {channel, gitTag, version}, branch: {mergeRange, name}}) => ({ | ||||||
|     message: `The release \`${nextRelease.version}\` on branch \`${ |     message: `The release \`${version}\` on branch \`${name}\` cannot be published as it is out of range.`, | ||||||
|       branch.name |     details: `Only releases within the range \`${mergeRange}\` can be merged into the maintenance branch \`${name}\` and published to the \`${channel}\` distribution channel.
 | ||||||
|     }\` 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.
 |  | ||||||
| 
 | 
 | ||||||
| The branch \`${ | 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.
 | ||||||
|       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.
 |  | ||||||
| 
 | 
 | ||||||
| See the [workflow configuration documentation](${linkify('docs/usage/workflow-configuration.md')}) for more details.`,
 | See the [workflow configuration documentation](${linkify('docs/usage/workflow-configuration.md')}) for more details.`,
 | ||||||
|   }), |   }), | ||||||
|  | |||||||
| @ -34,7 +34,7 @@ module.exports = context => { | |||||||
|               ({channel, version}) => |               ({channel, version}) => | ||||||
|                 channel === higherBranch.channel && |                 channel === higherBranch.channel && | ||||||
|                 channel !== branch.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
 |             // 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 {isGitRepo, verifyTagName} = require('./git'); | ||||||
| const getError = require('./get-error'); | 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 = []; |   const errors = []; | ||||||
| 
 | 
 | ||||||
|   if (!(await isGitRepo({cwd, env}))) { |   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
 |   // Verify that compiling the `tagFormat` produce a valid Git tag
 | ||||||
|   if (!(await verifyTagName(template(tagFormat)({version: '0.0.0'})))) { |   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
 |   // 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.
 |   // 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`.
 |   // 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) { |   if ((template(tagFormat)({version: ' '}).match(/ /g) || []).length !== 1) { | ||||||
|     errors.push(getError('ETAGNOVERSION', {tagFormat})); |     errors.push(getError('ETAGNOVERSION', context)); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   branches.forEach(branch => { |   branches.forEach(branch => { | ||||||
|  | |||||||
| @ -7,15 +7,13 @@ 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 maintenance = [{name: '1.x', channel: '1.x', tags: []}, {name: '1.1.x', tags: []}, {name: '1.2.x', tags: []}]; | ||||||
|   const release = [{name: 'master', tags: []}]; |   const release = [{name: 'master', tags: []}]; | ||||||
|   t.deepEqual( |   t.deepEqual( | ||||||
|     normalize |     normalize.maintenance({maintenance, release}).map(({type, name, range, accept, channel, mergeRange}) => ({ | ||||||
|       .maintenance({maintenance, release}) |  | ||||||
|       .map(({type, name, range, accept, channel, 'merge-range': maintenanceRange}) => ({ |  | ||||||
|       type, |       type, | ||||||
|       name, |       name, | ||||||
|       range, |       range, | ||||||
|       accept, |       accept, | ||||||
|       channel, |       channel, | ||||||
|         'merge-range': maintenanceRange, |       mergeRange, | ||||||
|     })), |     })), | ||||||
|     [ |     [ | ||||||
|       { |       { | ||||||
| @ -24,7 +22,7 @@ test('Maintenance branches - initial state', t => { | |||||||
|         range: '>=1.1.0 <1.0.0', |         range: '>=1.1.0 <1.0.0', | ||||||
|         accept: [], |         accept: [], | ||||||
|         channel: '1.1.x', |         channel: '1.1.x', | ||||||
|         'merge-range': '>=1.1.0 <1.2.0', |         mergeRange: '>=1.1.0 <1.2.0', | ||||||
|       }, |       }, | ||||||
|       { |       { | ||||||
|         type: 'maintenance', |         type: 'maintenance', | ||||||
| @ -32,7 +30,7 @@ test('Maintenance branches - initial state', t => { | |||||||
|         range: '>=1.2.0 <1.0.0', |         range: '>=1.2.0 <1.0.0', | ||||||
|         accept: [], |         accept: [], | ||||||
|         channel: '1.2.x', |         channel: '1.2.x', | ||||||
|         'merge-range': '>=1.2.0 <1.3.0', |         mergeRange: '>=1.2.0 <1.3.0', | ||||||
|       }, |       }, | ||||||
|       { |       { | ||||||
|         type: 'maintenance', |         type: 'maintenance', | ||||||
| @ -40,7 +38,7 @@ test('Maintenance branches - initial state', t => { | |||||||
|         range: '>=1.3.0 <1.0.0', |         range: '>=1.3.0 <1.0.0', | ||||||
|         accept: [], |         accept: [], | ||||||
|         channel: '1.x', |         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( |   t.deepEqual( | ||||||
|     normalize |     normalize | ||||||
|       .maintenance({maintenance, release}) |       .maintenance({maintenance, release}) | ||||||
|       .map(({type, name, range, accept, channel, 'merge-range': maintenanceRange}) => ({ |       .map(({type, name, range, accept, channel, mergeRange: maintenanceRange}) => ({ | ||||||
|         type, |         type, | ||||||
|         name, |         name, | ||||||
|         range, |         range, | ||||||
|         accept, |         accept, | ||||||
|         channel, |         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', |         range: '>=1.1.1 <1.2.0', | ||||||
|         accept: ['patch'], |         accept: ['patch'], | ||||||
|         channel: 'name', |         channel: 'name', | ||||||
|         'merge-range': '>=1.1.0 <1.2.0', |         mergeRange: '>=1.1.0 <1.2.0', | ||||||
|       }, |       }, | ||||||
|       { |       { | ||||||
|         type: 'maintenance', |         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', |         range: '>=1.2.1 <1.3.0', | ||||||
|         accept: ['patch'], |         accept: ['patch'], | ||||||
|         channel: '1.2.x', |         channel: '1.2.x', | ||||||
|         'merge-range': '>=1.2.0 <1.3.0', |         mergeRange: '>=1.2.0 <1.3.0', | ||||||
|       }, |       }, | ||||||
|       { |       { | ||||||
|         type: 'maintenance', |         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', |         range: '>=1.5.0 <1.6.0', | ||||||
|         accept: ['patch'], |         accept: ['patch'], | ||||||
|         channel: '1.x', |         channel: '1.x', | ||||||
|         'merge-range': '>=1.3.0 <2.0.0', |         mergeRange: '>=1.3.0 <2.0.0', | ||||||
|       }, |       }, | ||||||
|       { |       { | ||||||
|         type: 'maintenance', |         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', |         range: '>=2.0.0 <1.6.0', | ||||||
|         accept: [], |         accept: [], | ||||||
|         channel: '2.x.x', |         channel: '2.x.x', | ||||||
|         'merge-range': '>=2.0.0 <3.0.0', |         mergeRange: '>=2.0.0 <3.0.0', | ||||||
|       }, |       }, | ||||||
|     ] |     ] | ||||||
|   ); |   ); | ||||||
| @ -116,15 +114,13 @@ 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'])}]; |   const release = [{name: 'master', tags: toTags(['1.0.0', '1.2.0', '1.3.0', '2.0.0'])}]; | ||||||
| 
 | 
 | ||||||
|   t.deepEqual( |   t.deepEqual( | ||||||
|     normalize |     normalize.maintenance({maintenance, release}).map(({type, name, range, accept, channel, mergeRange}) => ({ | ||||||
|       .maintenance({maintenance, release}) |  | ||||||
|       .map(({type, name, range, accept, channel, 'merge-range': maintenanceRange}) => ({ |  | ||||||
|       type, |       type, | ||||||
|       name, |       name, | ||||||
|       range, |       range, | ||||||
|       accept, |       accept, | ||||||
|       channel, |       channel, | ||||||
|         'merge-range': maintenanceRange, |       mergeRange, | ||||||
|     })), |     })), | ||||||
|     [ |     [ | ||||||
|       { |       { | ||||||
| @ -133,7 +129,7 @@ test('Maintenance branches - cap range to default branch last release if all rel | |||||||
|         range: '>=1.3.0 <2.0.0', |         range: '>=1.3.0 <2.0.0', | ||||||
|         accept: ['patch', 'minor'], |         accept: ['patch', 'minor'], | ||||||
|         channel: '1.x', |         channel: '1.x', | ||||||
|         'merge-range': '>=1.0.0 <2.0.0', |         mergeRange: '>=1.0.0 <2.0.0', | ||||||
|       }, |       }, | ||||||
|       { |       { | ||||||
|         type: 'maintenance', |         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', |         range: '>=2.0.0 <2.0.0', | ||||||
|         accept: [], |         accept: [], | ||||||
|         channel: '2.x.x', |         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', |       name: '2.x', | ||||||
|       channel: '2.x', |       channel: '2.x', | ||||||
|       type: 'maintenance', |       type: 'maintenance', | ||||||
|       'merge-range': '>=2.0.0 <3.0.0', |       mergeRange: '>=2.0.0 <3.0.0', | ||||||
|       tags: [ |       tags: [ | ||||||
|         {gitTag: 'v2.0.0@2.x', version: '2.0.0', channel: '2.x', gitHead: '111'}, |         {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'}, |         {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', |       name: '2.x', | ||||||
|       channel: 'latest', |       channel: 'latest', | ||||||
|       type: 'maintenance', |       type: 'maintenance', | ||||||
|       'merge-range': '>=2.0.0 <3.0.0', |       mergeRange: '>=2.0.0 <3.0.0', | ||||||
|       tags: [ |       tags: [ | ||||||
|         {gitTag: 'v2.0.0', version: '2.0.0', gitHead: '111'}, |         {gitTag: 'v2.0.0', version: '2.0.0', gitHead: '111'}, | ||||||
|         {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