build: add --unique option to release notes script (#34296)
Useful when looking for changes unique to a single branch
This commit is contained in:
		
					parent
					
						
							
								4f99e3e46c
							
						
					
				
			
			
				commit
				
					
						92b0f3e808
					
				
			
		
					 2 changed files with 17 additions and 12 deletions
				
			
		|  | @ -147,7 +147,7 @@ const getPreviousPoint = async (point) => { | ||||||
|   } |   } | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| async function getReleaseNotes (range, newVersion) { | async function getReleaseNotes (range, newVersion, unique) { | ||||||
|   const rangeList = range.split('..') || ['HEAD']; |   const rangeList = range.split('..') || ['HEAD']; | ||||||
|   const to = rangeList.pop(); |   const to = rangeList.pop(); | ||||||
|   const from = rangeList.pop() || (await getPreviousPoint(to)); |   const from = rangeList.pop() || (await getPreviousPoint(to)); | ||||||
|  | @ -158,7 +158,7 @@ async function getReleaseNotes (range, newVersion) { | ||||||
| 
 | 
 | ||||||
|   const notes = await notesGenerator.get(from, to, newVersion); |   const notes = await notesGenerator.get(from, to, newVersion); | ||||||
|   const ret = { |   const ret = { | ||||||
|     text: notesGenerator.render(notes) |     text: notesGenerator.render(notes, unique) | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   if (notes.unknown.length) { |   if (notes.unknown.length) { | ||||||
|  | @ -170,7 +170,7 @@ async function getReleaseNotes (range, newVersion) { | ||||||
| 
 | 
 | ||||||
| async function main () { | async function main () { | ||||||
|   const opts = minimist(process.argv.slice(2), { |   const opts = minimist(process.argv.slice(2), { | ||||||
|     boolean: ['help'], |     boolean: ['help', 'unique'], | ||||||
|     string: ['version'] |     string: ['version'] | ||||||
|   }); |   }); | ||||||
|   opts.range = opts._.shift(); |   opts.range = opts._.shift(); | ||||||
|  | @ -179,13 +179,14 @@ async function main () { | ||||||
|     console.log(` |     console.log(` | ||||||
| easy usage: ${name} version | easy usage: ${name} version | ||||||
| 
 | 
 | ||||||
| full usage: ${name} [begin..]end [--version version] | full usage: ${name} [begin..]end [--version version] [--unique] | ||||||
| 
 | 
 | ||||||
|  * 'begin' and 'end' are two git references -- tags, branches, etc -- |  * 'begin' and 'end' are two git references -- tags, branches, etc -- | ||||||
|    from which the release notes are generated. |    from which the release notes are generated. | ||||||
|  * if omitted, 'begin' defaults to the previous tag in end's branch. |  * if omitted, 'begin' defaults to the previous tag in end's branch. | ||||||
|  * if omitted, 'version' defaults to 'end'. Specifying a version is |  * if omitted, 'version' defaults to 'end'. Specifying a version is | ||||||
|    useful if you're making notes on a new version that isn't tagged yet. |    useful if you're making notes on a new version that isn't tagged yet. | ||||||
|  |  * '--unique' omits changes that also landed in other branches. | ||||||
| 
 | 
 | ||||||
| For example, these invocations are equivalent: | For example, these invocations are equivalent: | ||||||
|   ${process.argv[1]} v4.0.1 |   ${process.argv[1]} v4.0.1 | ||||||
|  | @ -194,7 +195,7 @@ For example, these invocations are equivalent: | ||||||
|     return 0; |     return 0; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   const notes = await getReleaseNotes(opts.range, opts.version); |   const notes = await getReleaseNotes(opts.range, opts.version, opts.unique); | ||||||
|   console.log(notes.text); |   console.log(notes.text); | ||||||
|   if (notes.warning) { |   if (notes.warning) { | ||||||
|     throw new Error(notes.warning); |     throw new Error(notes.warning); | ||||||
|  |  | ||||||
|  | @ -596,10 +596,14 @@ function renderDescription (commit) { | ||||||
| const renderNote = (commit, excludeBranch) => | const renderNote = (commit, excludeBranch) => | ||||||
|   `* ${renderDescription(commit)} ${renderLink(commit)} ${renderTrops(commit, excludeBranch)}\n`; |   `* ${renderDescription(commit)} ${renderLink(commit)} ${renderTrops(commit, excludeBranch)}\n`; | ||||||
| 
 | 
 | ||||||
| const renderNotes = (notes) => { | const renderNotes = (notes, unique = false) => { | ||||||
|   const rendered = [`# Release Notes for ${notes.name}\n\n`]; |   const rendered = [`# Release Notes for ${notes.name}\n\n`]; | ||||||
| 
 | 
 | ||||||
|   const renderSection = (title, commits) => { |   const renderSection = (title, commits, unique) => { | ||||||
|  |     if (unique) { | ||||||
|  |       // omit changes that also landed in other branches
 | ||||||
|  |       commits = commits.filter((commit) => renderTrops(commit, notes.toBranch).length === 0); | ||||||
|  |     } | ||||||
|     if (commits.length > 0) { |     if (commits.length > 0) { | ||||||
|       rendered.push( |       rendered.push( | ||||||
|         `## ${title}\n\n`, |         `## ${title}\n\n`, | ||||||
|  | @ -608,17 +612,17 @@ const renderNotes = (notes) => { | ||||||
|     } |     } | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   renderSection('Breaking Changes', notes.breaking); |   renderSection('Breaking Changes', notes.breaking, unique); | ||||||
|   renderSection('Features', notes.feat); |   renderSection('Features', notes.feat, unique); | ||||||
|   renderSection('Fixes', notes.fix); |   renderSection('Fixes', notes.fix, unique); | ||||||
|   renderSection('Other Changes', notes.other); |   renderSection('Other Changes', notes.other, unique); | ||||||
| 
 | 
 | ||||||
|   if (notes.docs.length) { |   if (notes.docs.length) { | ||||||
|     const docs = notes.docs.map(commit => renderLink(commit)).sort(); |     const docs = notes.docs.map(commit => renderLink(commit)).sort(); | ||||||
|     rendered.push('## Documentation\n\n', ` * Documentation changes: ${docs.join(', ')}\n`, '\n'); |     rendered.push('## Documentation\n\n', ` * Documentation changes: ${docs.join(', ')}\n`, '\n'); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   renderSection('Unknown', notes.unknown); |   renderSection('Unknown', notes.unknown, unique); | ||||||
| 
 | 
 | ||||||
|   return rendered.join(''); |   return rendered.join(''); | ||||||
| }; | }; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Charles Kerr
				Charles Kerr