@@ -18,6 +18,7 @@ import {
1818 AddCommentResponse ,
1919 AddReactionResponse ,
2020 AddReviewThreadResponse ,
21+ ConvertPullRequestToDraftResponse ,
2122 DeleteReactionResponse ,
2223 DeleteReviewResponse ,
2324 DequeuePullRequestResponse ,
@@ -44,6 +45,7 @@ import {
4445} from './graphql' ;
4546import {
4647 AccountType ,
48+ ConvertToDraft ,
4749 GithubItemStateEnum ,
4850 IAccount ,
4951 IGitTreeItem ,
@@ -1837,6 +1839,44 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
18371839 }
18381840 }
18391841
1842+ /**
1843+ * Convert a pull request to draft.
1844+ */
1845+ async convertToDraft ( ) : Promise < ConvertToDraft > {
1846+ try {
1847+ const { mutate, schema } = await this . githubRepository . ensure ( ) ;
1848+
1849+ const { data } = await mutate < ConvertPullRequestToDraftResponse > ( {
1850+ mutation : schema . ConvertToDraft ,
1851+ variables : {
1852+ input : {
1853+ pullRequestId : this . graphNodeId ,
1854+ } ,
1855+ } ,
1856+ } ) ;
1857+
1858+ /* __GDPR__
1859+ "pr.convertToDraft.success" : {}
1860+ */
1861+ this . _telemetry . sendTelemetryEvent ( 'pr.convertToDraft.success' ) ;
1862+
1863+ const result : ConvertToDraft = {
1864+ isDraft : data ! . convertPullRequestToDraft . pullRequest . isDraft ,
1865+ mergeable : parseMergeability ( data ! . convertPullRequestToDraft . pullRequest . mergeable , data ! . convertPullRequestToDraft . pullRequest . mergeStateStatus ) ,
1866+ } ;
1867+ this . item . isDraft = result . isDraft ;
1868+ this . item . mergeable = result . mergeable ;
1869+ this . _onDidChange . fire ( { draft : true } ) ;
1870+ return result ;
1871+ } catch ( e ) {
1872+ /* __GDPR__
1873+ "pr.convertToDraft.failure" : {}
1874+ */
1875+ this . _telemetry . sendTelemetryErrorEvent ( 'pr.convertToDraft.failure' ) ;
1876+ throw e ;
1877+ }
1878+ }
1879+
18401880 private updateCommentReactions ( graphNodeId : string , reactionGroups : ReactionGroup [ ] ) {
18411881 const reviewThread = this . _reviewThreadsCache ?. find ( thread =>
18421882 thread . comments . some ( c => c . graphNodeId === graphNodeId ) ,
0 commit comments