@@ -1154,7 +1154,7 @@ export class FolderRepositoryManager extends Disposable {
1154
1154
Logger . debug ( `Fetch pull request category ${ categoryQuery } - enter` , this . id ) ;
1155
1155
const { octokit, query, schema } = await githubRepository . ensure ( ) ;
1156
1156
1157
- const user = await githubRepository . getAuthenticatedUser ( ) ;
1157
+ const user = ( await githubRepository . getAuthenticatedUser ( ) ) . login ;
1158
1158
// Search api will not try to resolve repo that redirects, so get full name first
1159
1159
repo = await githubRepository . getMetadata ( ) ;
1160
1160
const { data, headers } = await octokit . call ( octokit . api . search . issuesAndPullRequests , {
@@ -1749,8 +1749,12 @@ export class FolderRepositoryManager extends Disposable {
1749
1749
}
1750
1750
1751
1751
private async getBranchDeletionItems ( ) {
1752
+ interface BranchDeletionMetadata extends PullRequestMetadata {
1753
+ isOpen ?: boolean ;
1754
+ }
1755
+
1752
1756
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 ( ) ;
1754
1758
1755
1759
allConfigs . forEach ( config => {
1756
1760
const key = config . key ;
@@ -1763,14 +1767,23 @@ export class FolderRepositoryManager extends Disposable {
1763
1767
branchInfos . set ( branchName , { } ) ;
1764
1768
}
1765
1769
1766
- const value = branchInfos . get ( branchName ) ;
1770
+ const value = branchInfos . get ( branchName ) ! ;
1767
1771
if ( matches [ 2 ] === 'remote' ) {
1768
- value ! [ 'remote' ] = config . value ;
1772
+ value [ 'remote' ] = config . value ;
1769
1773
}
1770
1774
1771
1775
if ( matches [ 2 ] === 'github-pr-owner-number' ) {
1772
1776
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
+ }
1774
1787
}
1775
1788
1776
1789
branchInfos . set ( branchName , value ! ) ;
@@ -1779,67 +1792,73 @@ export class FolderRepositoryManager extends Disposable {
1779
1792
Logger . debug ( `Found ${ branchInfos . size } possible branches to delete` , this . id ) ;
1780
1793
Logger . trace ( `Branches to delete: ${ JSON . stringify ( Array . from ( branchInfos . keys ( ) ) ) } ` , this . id ) ;
1781
1794
1782
- const actions : ( vscode . QuickPickItem & { metadata : PullRequestMetadata ; legacy ?: boolean } ) [ ] = [ ] ;
1795
+ const actions : ( vscode . QuickPickItem & { metadata : BranchDeletionMetadata [ ] ; legacy ?: boolean } ) [ ] = [ ] ;
1783
1796
branchInfos . forEach ( ( value , key ) => {
1784
1797
if ( value . metadata ) {
1785
1798
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
+ ) ;
1791
1804
1792
- if ( ! matchesActiveBranch ) {
1805
+ if ( ! activeMetadata ) {
1793
1806
actions . push ( {
1794
1807
label : `${ key } ` ,
1795
- description : `${ value . metadata ! . repositoryName } /${ value . metadata ! . owner } #${ value . metadata . prNumber
1796
- } `,
1797
1808
picked : false ,
1798
- metadata : value . metadata ! ,
1809
+ metadata : value . metadata ,
1799
1810
} ) ;
1800
1811
} 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 ) ;
1802
1813
Logger . trace ( `Skipping active branch ${ key } ` , this . id ) ;
1803
1814
}
1804
1815
}
1805
1816
} ) ;
1806
1817
1807
1818
const results = await Promise . all (
1808
1819
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
+ }
1815
1831
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 ;
1818
1849
}
1819
1850
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
-
1834
1851
return action ;
1835
1852
} ) ,
1836
1853
) ;
1837
1854
1838
1855
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 ( ', ' ) } `;
1839
1860
if ( result . legacy ) {
1840
1861
result . picked = true ;
1841
- } else {
1842
- result . description = vscode . l10n . t ( '{0} is still Open' , result . description ! ) ;
1843
1862
}
1844
1863
} ) ;
1845
1864
@@ -2011,7 +2030,7 @@ export class FolderRepositoryManager extends Disposable {
2011
2030
quickPick . items = results ;
2012
2031
quickPick . selectedItems = results . filter ( result => {
2013
2032
// 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 ) ) ) ;
2015
2034
} ) ;
2016
2035
quickPick . busy = false ;
2017
2036
if ( results . length === 0 ) {
0 commit comments