@@ -29,6 +29,7 @@ var opt = require('node-getopt').create([
2929 [ '' , 'dryrun' , 'Dry run only, do not actually commit new release' ] ,
3030 [ '' , 'derivedFrom=version' , 'Used to get PRs merged since this release was created' , 'lastMinorRelease' ] ,
3131 [ '' , 'branch=branch' , 'Branch to select PRs merged into' , 'master' ] ,
32+ [ '' , 'targetCommitId=commit' , 'Fetch PRs merged since this commit' , '' ] ,
3233 [ 'h' , 'help' , 'Display this help' ] ,
3334] )
3435 . setHelp (
@@ -68,6 +69,24 @@ function writeAgentVersionFile(newRelease) {
6869 return newRelease ;
6970}
7071
72+ function filterCommitsUpToTarget ( commitList ) {
73+ try {
74+ var targetCommitId = opt . options . targetCommitId ;
75+ var targetIndex = commitList . indexOf ( targetCommitId ) ;
76+
77+ if ( targetIndex === - 1 ) {
78+ console . log ( `Debug: Commit ID ${ targetCommitId } not found in the list.` ) ;
79+ return commitList ;
80+ }
81+ // Return commits up to and including the target commit
82+ return commitList . slice ( 0 , targetIndex + 1 ) ;
83+ } catch ( e ) {
84+ console . log ( e ) ;
85+ console . error ( `Unexpected error while filtering commits` ) ;
86+ process . exit ( - 1 ) ;
87+ }
88+ }
89+
7190async function fetchPRsForSHAsGraphQL ( commitSHAs ) {
7291
7392 var queryParts = commitSHAs . map ( ( sha , index ) => `
@@ -126,20 +145,20 @@ async function fetchPRsSincePreviousReleaseAndEditReleaseNotes(newRelease, callb
126145 var latestReleaseInfo = filteredReleases . find ( release => release . tag_name . toLowerCase ( ) . startsWith ( releaseTagPrefix . toLowerCase ( ) ) ) ;
127146 console . log ( `Previous release tag with ${ latestReleaseInfo . tag_name } and published date is: ${ latestReleaseInfo . published_at } ` )
128147
129- var headBranchTag = 'v' + newRelease
130148 try {
131149 var comparison = await octokit . repos . compareCommits ( {
132150 owner : OWNER ,
133151 repo : REPO ,
134152 base : latestReleaseInfo . tag_name ,
135- head : headBranchTag ,
153+ head : 'master' ,
136154 } ) ;
137155
138156 var commitSHAs = comparison . data . commits . map ( commit => commit . sha ) ;
157+ var filteredCommits = filterCommitsUpToTarget ( commitSHAs ) ;
139158
140159 try {
141160
142- var allPRs = await fetchPRsForSHAsGraphQL ( commitSHAs ) ;
161+ var allPRs = await fetchPRsForSHAsGraphQL ( filteredCommits ) ;
143162 editReleaseNotesFile ( { items : allPRs } ) ;
144163 } catch ( e ) {
145164 console . log ( e ) ;
0 commit comments