From 756cdde3e6abf7cb0f8061a2baae71de87e927e4 Mon Sep 17 00:00:00 2001 From: paulodamaso Date: Wed, 11 Mar 2020 23:05:40 -0300 Subject: [PATCH] For #1526: support to github pull request draft --- src/main/java/com/jcabi/github/Pull.java | 8 ++++++ src/test/java/com/jcabi/github/PullTest.java | 26 ++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/main/java/com/jcabi/github/Pull.java b/src/main/java/com/jcabi/github/Pull.java index 52ac4e656..a51277b9b 100644 --- a/src/main/java/com/jcabi/github/Pull.java +++ b/src/main/java/com/jcabi/github/Pull.java @@ -319,6 +319,14 @@ public Issue issue() { public int commentsCount() throws IOException { return this.jsn.number("comments"); } + /** + * Is it a draft pull request? + * @return TRUE if it's a draft pull request + * @throws IOException If there is any I/O problem + */ + public boolean isDraft() throws IOException { + return this.jsn.json().getBoolean("draft"); + } @Override public Repo repo() { return this.pull.repo(); diff --git a/src/test/java/com/jcabi/github/PullTest.java b/src/test/java/com/jcabi/github/PullTest.java index 02e5bea82..cec931b99 100644 --- a/src/test/java/com/jcabi/github/PullTest.java +++ b/src/test/java/com/jcabi/github/PullTest.java @@ -34,6 +34,7 @@ import javax.json.Json; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; +import org.hamcrest.core.IsEqual; import org.junit.Test; import org.mockito.Mockito; @@ -127,4 +128,29 @@ public void getsAuthor() throws IOException { Matchers.equalTo(login) ); } + + /** + * Pull.Smart can get the pull request draft state. + * @throws IOException If some problem inside + */ + @Test + public void getDraftState() throws IOException { + final Repo repo = Mockito.mock(Repo.class); + Mockito.when(repo.github()).thenReturn(new MkGithub()); + final Pull pull = Mockito.mock(Pull.class); + Mockito.when(pull.json()).thenReturn( + Json.createObjectBuilder() + .add( + "draft", + true + ) + .build() + ); + Mockito.when(pull.repo()).thenReturn(repo); + MatcherAssert.assertThat( + "Could not retrieve correct draft status", + new Pull.Smart(pull).isDraft(), + new IsEqual<>(true) + ); + } }