@@ -37,6 +37,7 @@ import {PullRequestBody} from '../src/util/pull-request-body';
3737import { PullRequestTitle } from '../src/util/pull-request-title' ;
3838import * as codeSuggester from 'code-suggester' ;
3939import { RawContent } from '../src/updaters/raw-content' ;
40+ import { ReleasePleaseManifest } from '../src/updaters/release-please-manifest' ;
4041import { HttpsProxyAgent } from 'https-proxy-agent' ;
4142import { HttpProxyAgent } from 'http-proxy-agent' ;
4243import { Commit } from '../src/commit' ;
@@ -1062,6 +1063,64 @@ describe('GitHub', () => {
10621063 } ) ;
10631064 } ) ;
10641065
1066+ describe ( 'buildChangeSet' , ( ) => {
1067+ it ( 'should merge updates for the same file' , async ( ) => {
1068+ const manifestPath = '.release-please-manifest.json' ;
1069+ const initialContent = JSON . stringify (
1070+ {
1071+ path1 : '1.0.0' ,
1072+ path2 : '2.0.0' ,
1073+ } ,
1074+ null ,
1075+ 2
1076+ ) ;
1077+ sandbox
1078+ . stub ( github , 'getFileContentsOnBranch' )
1079+ . withArgs ( manifestPath , 'main' )
1080+ . resolves ( {
1081+ sha : 'abc123' ,
1082+ content : Buffer . from ( initialContent ) . toString ( 'base64' ) ,
1083+ parsedContent : initialContent ,
1084+ mode : '100644' ,
1085+ } ) ;
1086+
1087+ const updates = [
1088+ {
1089+ path : manifestPath ,
1090+ createIfMissing : false ,
1091+ updater : new ReleasePleaseManifest ( {
1092+ version : Version . parse ( '1.1.0' ) ,
1093+ versionsMap : new Map ( [ [ 'path1' , Version . parse ( '1.1.0' ) ] ] ) ,
1094+ } ) ,
1095+ } ,
1096+ {
1097+ path : manifestPath ,
1098+ createIfMissing : false ,
1099+ updater : new ReleasePleaseManifest ( {
1100+ version : Version . parse ( '1.1.0' ) ,
1101+ versionsMap : new Map ( ) ,
1102+ } ) ,
1103+ } ,
1104+ ] ;
1105+
1106+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1107+ const changes = await ( github as any ) . buildChangeSet ( updates , 'main' ) ;
1108+
1109+ expect ( changes ) . to . not . be . undefined ;
1110+ expect ( changes ! . size ) . to . eql ( 1 ) ;
1111+ const updatedContent = changes ! . get ( manifestPath ) ! . content ;
1112+ const expectedContent = JSON . stringify (
1113+ {
1114+ path1 : '1.1.0' ,
1115+ path2 : '2.0.0' ,
1116+ } ,
1117+ null ,
1118+ 2
1119+ ) ;
1120+ expect ( updatedContent ) . to . eql ( expectedContent ) ;
1121+ } ) ;
1122+ } ) ;
1123+
10651124 describe ( 'createFileOnNewBranch' , ( ) => {
10661125 it ( 'forks a new branch if the branch does not exist' , async ( ) => {
10671126 req = req
0 commit comments