@@ -25,6 +25,7 @@ import {
25
25
MentionableUsersResponse ,
26
26
MilestoneIssuesResponse ,
27
27
PullRequestResponse ,
28
+ PullRequestsResponse ,
28
29
ViewerPermissionResponse ,
29
30
} from './graphql' ;
30
31
import { IAccount , IMilestone , Issue , PullRequest , RepoAccessAndMergeMethods } from './interface' ;
@@ -364,26 +365,23 @@ export class GitHubRepository implements vscode.Disposable {
364
365
return undefined ;
365
366
}
366
367
367
- async getPullRequestForBranch ( remoteAndBranch : string ) : Promise < PullRequestModel [ ] | undefined > {
368
+ async getPullRequestForBranch ( branch : string ) : Promise < PullRequestModel | undefined > {
368
369
try {
369
370
Logger . debug ( `Fetch pull requests for branch - enter` , GitHubRepository . ID ) ;
370
- const { octokit, remote } = await this . ensure ( ) ;
371
- const result = await octokit . pulls . list ( {
372
- owner : remote . owner ,
373
- repo : remote . repositoryName ,
374
- head : remoteAndBranch
371
+ const { query, remote, schema } = await this . ensure ( ) ;
372
+ const { data } = await query < PullRequestsResponse > ( {
373
+ query : schema . PullRequestForHead ,
374
+ variables : {
375
+ owner : remote . owner ,
376
+ name : remote . repositoryName ,
377
+ headRefName : branch ,
378
+ } ,
375
379
} ) ;
376
-
377
- const pullRequests = result . data
378
- . map ( pullRequest => {
379
- return this . createOrUpdatePullRequestModel (
380
- convertRESTPullRequestToRawPullRequest ( pullRequest , this ) ,
381
- ) ;
382
- } )
383
- . filter ( item => item !== null ) as PullRequestModel [ ] ;
384
-
385
380
Logger . debug ( `Fetch pull requests for branch - done` , GitHubRepository . ID ) ;
386
- return pullRequests ;
381
+
382
+ if ( data . repository . pullRequests . nodes . length > 0 ) {
383
+ return this . createOrUpdatePullRequestModel ( parseGraphQLPullRequest ( data . repository . pullRequests . nodes [ 0 ] , this ) ) ;
384
+ }
387
385
} catch ( e ) {
388
386
Logger . appendLine ( `Fetching pull requests for branch failed: ${ e } ` , GitHubRepository . ID ) ;
389
387
if ( e . code === 404 ) {
@@ -702,7 +700,7 @@ export class GitHubRepository implements vscode.Disposable {
702
700
} ,
703
701
} ) ;
704
702
Logger . debug ( `Fetch pull request ${ id } - done` , GitHubRepository . ID ) ;
705
- return this . createOrUpdatePullRequestModel ( parseGraphQLPullRequest ( data , this ) ) ;
703
+ return this . createOrUpdatePullRequestModel ( parseGraphQLPullRequest ( data . repository . pullRequest , this ) ) ;
706
704
} catch ( e ) {
707
705
Logger . appendLine ( `GithubRepository> Unable to fetch PR: ${ e } ` ) ;
708
706
return ;
0 commit comments