@@ -25,6 +25,7 @@ import {
2525 MentionableUsersResponse ,
2626 MilestoneIssuesResponse ,
2727 PullRequestResponse ,
28+ PullRequestsResponse ,
2829 ViewerPermissionResponse ,
2930} from './graphql' ;
3031import { IAccount , IMilestone , Issue , PullRequest , RepoAccessAndMergeMethods } from './interface' ;
@@ -364,26 +365,23 @@ export class GitHubRepository implements vscode.Disposable {
364365 return undefined ;
365366 }
366367
367- async getPullRequestForBranch ( remoteAndBranch : string ) : Promise < PullRequestModel [ ] | undefined > {
368+ async getPullRequestForBranch ( branch : string ) : Promise < PullRequestModel | undefined > {
368369 try {
369370 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+ } ,
375379 } ) ;
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-
385380 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+ }
387385 } catch ( e ) {
388386 Logger . appendLine ( `Fetching pull requests for branch failed: ${ e } ` , GitHubRepository . ID ) ;
389387 if ( e . code === 404 ) {
@@ -702,7 +700,7 @@ export class GitHubRepository implements vscode.Disposable {
702700 } ,
703701 } ) ;
704702 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 ) ) ;
706704 } catch ( e ) {
707705 Logger . appendLine ( `GithubRepository> Unable to fetch PR: ${ e } ` ) ;
708706 return ;
0 commit comments