File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
src/plus/integrations/providers/azure Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -98,14 +98,32 @@ export class AzureDevOpsApi implements Disposable {
98
98
provider ,
99
99
token ,
100
100
options ?. baseUrl ,
101
- `${ owner } /${ projectName } /_apis/git/repositories/${ repoName } /pullRequests` ,
101
+ `${ owner } /${ projectName } /_apis/git/repositories/${ repoName } /pullRequests?searchCriteria.status=all&searchCriteria.sourceRefName=refs/heads/ ${ branch } ` ,
102
102
{
103
103
method : 'GET' ,
104
104
} ,
105
105
scope ,
106
106
) ;
107
107
108
- const pr = prResult ?. value . find ( pr => pr . sourceRefName . endsWith ( branch ) ) ;
108
+ // Sort PRs: open PRs first, then by most recent activity (creation or closure date)
109
+ const sortedPRs = prResult ?. value . sort ( ( a , b ) => {
110
+ // First, prioritize open PRs (active/notSet) over closed ones (abandoned/completed)
111
+ const aIsOpen = a . status === 'active' || a . status === 'notSet' ;
112
+ const bIsOpen = b . status === 'active' || b . status === 'notSet' ;
113
+
114
+ if ( aIsOpen !== bIsOpen ) {
115
+ return aIsOpen ? - 1 : 1 ; // Open PRs come first
116
+ }
117
+
118
+ // Among PRs with the same status, sort by most recent activity
119
+ // Use closedDate if available, otherwise use creationDate
120
+ const aDate = new Date ( a . closedDate || a . creationDate ) ;
121
+ const bDate = new Date ( b . closedDate || b . creationDate ) ;
122
+
123
+ return bDate . getTime ( ) - aDate . getTime ( ) ; // Most recent first
124
+ } ) ;
125
+
126
+ const pr = sortedPRs ?. [ 0 ] ;
109
127
if ( pr == null ) return undefined ;
110
128
111
129
return fromAzurePullRequest ( pr , provider , owner ) ;
You can’t perform that action at this time.
0 commit comments