@@ -1154,7 +1154,7 @@ export class FolderRepositoryManager extends Disposable {
11541154 Logger . debug ( `Fetch pull request category ${ categoryQuery } - enter` , this . id ) ;
11551155 const { octokit, query, schema } = await githubRepository . ensure ( ) ;
11561156
1157- const user = await githubRepository . getAuthenticatedUser ( ) ;
1157+ const user = ( await githubRepository . getAuthenticatedUser ( ) ) . login ;
11581158 // Search api will not try to resolve repo that redirects, so get full name first
11591159 repo = await githubRepository . getMetadata ( ) ;
11601160 const { data, headers } = await octokit . call ( octokit . api . search . issuesAndPullRequests , {
@@ -1749,8 +1749,12 @@ export class FolderRepositoryManager extends Disposable {
17491749 }
17501750
17511751 private async getBranchDeletionItems ( ) {
1752+ interface BranchDeletionMetadata extends PullRequestMetadata {
1753+ isOpen ?: boolean ;
1754+ }
1755+
17521756 const allConfigs = await this . repository . getConfigs ( ) ;
1753- const branchInfos : Map < string , { remote ?: string ; metadata ?: PullRequestMetadata } > = new Map ( ) ;
1757+ const branchInfos : Map < string , { remote ?: string ; metadata ?: BranchDeletionMetadata [ ] } > = new Map ( ) ;
17541758
17551759 allConfigs . forEach ( config => {
17561760 const key = config . key ;
@@ -1763,14 +1767,23 @@ export class FolderRepositoryManager extends Disposable {
17631767 branchInfos . set ( branchName , { } ) ;
17641768 }
17651769
1766- const value = branchInfos . get ( branchName ) ;
1770+ const value = branchInfos . get ( branchName ) ! ;
17671771 if ( matches [ 2 ] === 'remote' ) {
1768- value ! [ 'remote' ] = config . value ;
1772+ value [ 'remote' ] = config . value ;
17691773 }
17701774
17711775 if ( matches [ 2 ] === 'github-pr-owner-number' ) {
17721776 const metadata = PullRequestGitHelper . parsePullRequestMetadata ( config . value ) ;
1773- value ! [ 'metadata' ] = metadata ;
1777+ if ( ! value ?. metadata ) {
1778+ value [ 'metadata' ] = [ ] ;
1779+ }
1780+ if ( metadata ) {
1781+ // Check if the metadata already exists in the array
1782+ const existingMetadata = value . metadata . find ( m => m . owner === metadata . owner && m . repositoryName === metadata . repositoryName && m . prNumber === metadata . prNumber ) ;
1783+ if ( ! existingMetadata ) {
1784+ value [ 'metadata' ] . push ( metadata ) ;
1785+ }
1786+ }
17741787 }
17751788
17761789 branchInfos . set ( branchName , value ! ) ;
@@ -1779,67 +1792,73 @@ export class FolderRepositoryManager extends Disposable {
17791792 Logger . debug ( `Found ${ branchInfos . size } possible branches to delete` , this . id ) ;
17801793 Logger . trace ( `Branches to delete: ${ JSON . stringify ( Array . from ( branchInfos . keys ( ) ) ) } ` , this . id ) ;
17811794
1782- const actions : ( vscode . QuickPickItem & { metadata : PullRequestMetadata ; legacy ?: boolean } ) [ ] = [ ] ;
1795+ const actions : ( vscode . QuickPickItem & { metadata : BranchDeletionMetadata [ ] ; legacy ?: boolean } ) [ ] = [ ] ;
17831796 branchInfos . forEach ( ( value , key ) => {
17841797 if ( value . metadata ) {
17851798 const activePRUrl = this . activePullRequest && this . activePullRequest . base . repositoryCloneUrl ;
1786- const matchesActiveBranch = activePRUrl
1787- ? ( activePRUrl . owner === value . metadata . owner &&
1788- activePRUrl . repositoryName === value . metadata . repositoryName &&
1789- this . activePullRequest ?. number === value . metadata . prNumber )
1790- : false ;
1799+ const activeMetadata = value . metadata . find ( metadata =>
1800+ metadata . owner === activePRUrl ? .owner &&
1801+ metadata . repositoryName === activePRUrl ? .repositoryName &&
1802+ metadata . prNumber === this . activePullRequest ?. number
1803+ ) ;
17911804
1792- if ( ! matchesActiveBranch ) {
1805+ if ( ! activeMetadata ) {
17931806 actions . push ( {
17941807 label : `${ key } ` ,
1795- description : `${ value . metadata ! . repositoryName } /${ value . metadata ! . owner } #${ value . metadata . prNumber
1796- } `,
17971808 picked : false ,
1798- metadata : value . metadata ! ,
1809+ metadata : value . metadata ,
17991810 } ) ;
18001811 } else {
1801- Logger . debug ( `Skipping ${ value . metadata . prNumber } , active PR is #${ this . activePullRequest ?. number } ` , this . id ) ;
1812+ Logger . debug ( `Skipping ${ activeMetadata . prNumber } , active PR is #${ this . activePullRequest ?. number } ` , this . id ) ;
18021813 Logger . trace ( `Skipping active branch ${ key } ` , this . id ) ;
18031814 }
18041815 }
18051816 } ) ;
18061817
18071818 const results = await Promise . all (
18081819 actions . map ( async action => {
1809- const metadata = action . metadata ;
1810- const githubRepo = this . _githubRepositories . find (
1811- repo =>
1812- repo . remote . owner . toLowerCase ( ) === metadata ! . owner . toLowerCase ( ) &&
1813- repo . remote . repositoryName . toLowerCase ( ) === metadata ! . repositoryName . toLowerCase ( ) ,
1814- ) ;
1820+ const allOld = ( await Promise . all (
1821+ action . metadata . map ( async metadata => {
1822+ const githubRepo = this . _githubRepositories . find (
1823+ repo =>
1824+ repo . remote . owner . toLowerCase ( ) === metadata ! . owner . toLowerCase ( ) &&
1825+ repo . remote . repositoryName . toLowerCase ( ) === metadata ! . repositoryName . toLowerCase ( ) ,
1826+ ) ;
1827+
1828+ if ( ! githubRepo ) {
1829+ return action ;
1830+ }
18151831
1816- if ( ! githubRepo ) {
1817- return action ;
1832+ const { remote, query, schema } = await githubRepo . ensure ( ) ;
1833+ try {
1834+ const { data } = await query < PullRequestState > ( {
1835+ query : schema . PullRequestState ,
1836+ variables : {
1837+ owner : remote . owner ,
1838+ name : remote . repositoryName ,
1839+ number : metadata ! . prNumber ,
1840+ } ,
1841+ } ) ;
1842+ metadata . isOpen = data . repository ?. pullRequest . state === 'OPEN' ;
1843+ return data . repository ?. pullRequest . state !== 'OPEN' ;
1844+ } catch { }
1845+ return false ;
1846+ } ) ) ) . every ( result => result ) ;
1847+ if ( allOld ) {
1848+ action . legacy = true ;
18181849 }
18191850
1820- const { remote, query, schema } = await githubRepo . ensure ( ) ;
1821- try {
1822- const { data } = await query < PullRequestState > ( {
1823- query : schema . PullRequestState ,
1824- variables : {
1825- owner : remote . owner ,
1826- name : remote . repositoryName ,
1827- number : metadata ! . prNumber ,
1828- } ,
1829- } ) ;
1830-
1831- action . legacy = data . repository ?. pullRequest . state !== 'OPEN' ;
1832- } catch { }
1833-
18341851 return action ;
18351852 } ) ,
18361853 ) ;
18371854
18381855 results . forEach ( result => {
1856+ result . description = `${ result . metadata [ 0 ] . repositoryName } /${ result . metadata [ 0 ] . owner } ${ result . metadata . map ( metadata => {
1857+ const prString = `#${ metadata . prNumber } ` ;
1858+ return metadata . isOpen ? vscode . l10n . t ( '{0} is open' , prString ) : prString ;
1859+ } ) . join ( ', ' ) } `;
18391860 if ( result . legacy ) {
18401861 result . picked = true ;
1841- } else {
1842- result . description = vscode . l10n . t ( '{0} is still Open' , result . description ! ) ;
18431862 }
18441863 } ) ;
18451864
@@ -2011,7 +2030,7 @@ export class FolderRepositoryManager extends Disposable {
20112030 quickPick . items = results ;
20122031 quickPick . selectedItems = results . filter ( result => {
20132032 // Do not pick the default branch for the repo.
2014- return result . picked && ! ( ( result . label === defaults . base ) && ( result . metadata . owner === defaults . owner ) && ( result . metadata . repositoryName === defaults . repo ) ) ;
2033+ return result . picked && ! ( ( result . label === defaults . base ) && ( result . metadata . find ( metadata => metadata . owner === defaults . owner && metadata . repositoryName === defaults . repo ) ) ) ;
20152034 } ) ;
20162035 quickPick . busy = false ;
20172036 if ( results . length === 0 ) {
0 commit comments