Skip to content

Commit f73fbae

Browse files
committed
feat: add GHPullRequest.markReadyForReview() for draft PRs
1 parent c57be3c commit f73fbae

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

src/main/java/org/kohsuke/github/GHPullRequest.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,6 @@ public int getChangedFiles() throws IOException {
287287
return changedFiles;
288288
}
289289

290-
//
291-
// details that are only available via get with ID
292-
//
293-
294290
/**
295291
* Gets the closed by.
296292
*
@@ -539,6 +535,30 @@ public PagedIterable<GHPullRequestReview> listReviews() {
539535
.toIterable(GHPullRequestReview[].class, item -> item.wrapUp(this));
540536
}
541537

538+
/**
539+
* Converts a draft pull request to ready for review.
540+
*
541+
* @throws IOException
542+
* the io exception
543+
* @throws IllegalStateException
544+
* if the pull request is not a draft
545+
*/
546+
public void markReadyForReview() throws IOException {
547+
if (!draft) {
548+
throw new IllegalStateException("Pull request is not a draft");
549+
}
550+
551+
StringBuilder inputBuilder = new StringBuilder();
552+
addParameter(inputBuilder, "pullRequestId", this.getNodeId());
553+
554+
String graphqlBody = "mutation MarkReadyForReview { markPullRequestReadyForReview(input: {" + inputBuilder
555+
+ "}) { pullRequest { id } } }";
556+
557+
root().createGraphQLRequest(graphqlBody).sendGraphQL();
558+
559+
refresh();
560+
}
561+
542562
/**
543563
* Merge this pull request.
544564
*

src/test/java/org/kohsuke/github/GHPullRequestTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,25 @@ public void getUserTest() throws IOException {
416416
}
417417
}
418418

419+
/**
420+
* Test marking a draft pull request as ready for review.
421+
*
422+
* @throws Exception
423+
* the exception
424+
*/
425+
@Test
426+
public void markReadyForReview() throws Exception {
427+
// Create a draft PR first
428+
GHPullRequest p = getRepository().createPullRequest("markReadyForReview", "test/mark_ready_for_review", "main", "## test", false, true);
429+
assertThat(p.isDraft(), is(true));
430+
431+
// Mark it ready for review
432+
p.markReadyForReview();
433+
434+
// Verify it's no longer a draft
435+
assertThat(p.isDraft(), is(false));
436+
}
437+
419438
/**
420439
* Merge commit SHA.
421440
*

0 commit comments

Comments
 (0)