@@ -189,6 +189,64 @@ describe('PullRequestGitHelper', function () {
189189 } ) ;
190190 } ) ;
191191
192+ describe ( 'associateBranchWithPullRequest' , function ( ) {
193+ const pullRequest = ( number : number ) => ( {
194+ number,
195+ base : {
196+ repositoryCloneUrl : {
197+ owner : 'owner' ,
198+ repositoryName : 'name' ,
199+ } ,
200+ } ,
201+ } ) as PullRequestModel ;
202+
203+ it ( 'replaces pull request metadata instead of appending values' , async function ( ) {
204+ await PullRequestGitHelper . associateBranchWithPullRequest ( repository , pullRequest ( 100 ) , 'feature' ) ;
205+ await PullRequestGitHelper . associateBranchWithPullRequest ( repository , pullRequest ( 100 ) , 'feature' ) ;
206+ await PullRequestGitHelper . associateBranchWithPullRequest ( repository , pullRequest ( 101 ) , 'feature' ) ;
207+
208+ const key = 'branch.feature.github-pr-owner-number' ;
209+ assert . deepStrictEqual ( ( await repository . getConfigs ( ) ) . filter ( config => config . key === key ) , [
210+ { key, value : 'owner#name#101' } ,
211+ ] ) ;
212+ } ) ;
213+
214+ it ( 'does not append metadata during concurrent associations' , async function ( ) {
215+ await Promise . all ( [
216+ PullRequestGitHelper . associateBranchWithPullRequest ( repository , pullRequest ( 100 ) , 'feature' ) ,
217+ PullRequestGitHelper . associateBranchWithPullRequest ( repository , pullRequest ( 100 ) , 'feature' ) ,
218+ ] ) ;
219+
220+ const key = 'branch.feature.github-pr-owner-number' ;
221+ assert . deepStrictEqual ( ( await repository . getConfigs ( ) ) . filter ( config => config . key === key ) , [
222+ { key, value : 'owner#name#100' } ,
223+ ] ) ;
224+ } ) ;
225+
226+ it ( 'does not append to existing duplicate metadata' , async function ( ) {
227+ const key = 'branch.feature.github-pr-owner-number' ;
228+ await repository . setConfig ( key , 'owner#name#100' ) ;
229+ await repository . setConfig ( key , 'owner#name#100' ) ;
230+
231+ await PullRequestGitHelper . associateBranchWithPullRequest ( repository , pullRequest ( 100 ) , 'feature' ) ;
232+
233+ assert . strictEqual ( ( await repository . getConfigs ( ) ) . filter ( config => config . key === key ) . length , 2 ) ;
234+ } ) ;
235+ } ) ;
236+
237+ describe ( 'associateBaseBranchWithBranch' , function ( ) {
238+ it ( 'replaces base branch metadata instead of appending values' , async function ( ) {
239+ await PullRequestGitHelper . associateBaseBranchWithBranch ( repository , 'feature' , { owner : 'owner' , repo : 'name' , branch : 'main' } ) ;
240+ await PullRequestGitHelper . associateBaseBranchWithBranch ( repository , 'feature' , { owner : 'owner' , repo : 'name' , branch : 'main' } ) ;
241+ await PullRequestGitHelper . associateBaseBranchWithBranch ( repository , 'feature' , { owner : 'owner' , repo : 'name' , branch : 'next' } ) ;
242+
243+ const key = 'branch.feature.github-pr-base-branch' ;
244+ assert . deepStrictEqual ( ( await repository . getConfigs ( ) ) . filter ( config => config . key === key ) , [
245+ { key, value : 'owner#name#next' } ,
246+ ] ) ;
247+ } ) ;
248+ } ) ;
249+
192250 describe ( 'getMatchingPullRequestMetadataForBranch' , function ( ) {
193251 it ( 'returns the highest-numbered PR when duplicate config entries exist for the branch' , async function ( ) {
194252 // Simulate the case where a branch name has been associated with multiple
0 commit comments