Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For #1526: support to github pull request draft #1527

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/com/jcabi/github/Pull.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/com/jcabi/github/PullTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
);
}
}