From 4e31636181a2d847a9c6dbb6c186e387951f86af Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Fri, 12 Jan 2018 21:25:30 -0800 Subject: [PATCH] Allow the caller to wait for the mergeable state to change. This approaches #394 differently. The problem with the original #394 is that the supposed behaviour is only useful for people waiting for `getMergeable()` to return non-null in a busy loop, yet it impacts all the other methods of this object. --- .../java/org/kohsuke/github/GHPullRequest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index 934262382..6c8c9aac0 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -182,6 +182,13 @@ public class GHPullRequest extends GHIssue { return maintainer_can_modify; } + /** + * Is this PR mergeable? + * + * @return + * null if the state has not been determined yet, for example when a PR is newly created. + * Use {@link #refresh()} after some interval to wait until the value is determined. + */ public Boolean getMergeable() throws IOException { populate(); return mergeable; @@ -217,6 +224,13 @@ public class GHPullRequest extends GHIssue { */ private void populate() throws IOException { if (mergeable_state!=null) return; // already populated + refresh(); + } + + /** + * Repopulates this object. + */ + public void refresh() throws IOException { if (root.isOffline()) { return; // cannot populate, will have to live with what we have }