Java Code Examples for org.kohsuke.github.GHPullRequest#getMergeable()

The following examples show how to use org.kohsuke.github.GHPullRequest#getMergeable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GitHubHelpers.java    From updatebot with Apache License 2.0 6 votes vote down vote up
public static boolean isMergeable(GHPullRequest pullRequest) throws IOException {
    boolean canMerge = false;
    Boolean mergeable = pullRequest.getMergeable();
    GHPullRequest single = null;
    if (mergeable == null) {
        single = pullRequest.getRepository().getPullRequest(pullRequest.getNumber());
        mergeable = single.getMergeable();
    }
    if (mergeable == null) {
        LOG.warn("Mergeable flag is still null on pull request " + pullRequest.getHtmlUrl() + " assuming its still mergable. Probably a caching issue and this flag may appear again later");
        return true;
    }
    if (mergeable != null && mergeable.booleanValue()) {
        canMerge = true;
    }
    return canMerge;
}
 
Example 2
Source File: GitHubHelpers.java    From updatebot with Apache License 2.0 6 votes vote down vote up
public static Boolean waitForPullRequestToHaveMergable(GHPullRequest pullRequest, long sleepMS, long maximumTimeMS) throws IOException {
    long end = System.currentTimeMillis() + maximumTimeMS;
    while (true) {
        Boolean mergeable = pullRequest.getMergeable();
        if (mergeable == null) {
            GHRepository repository = pullRequest.getRepository();
            int number = pullRequest.getNumber();
            pullRequest = repository.getPullRequest(number);
            mergeable = pullRequest.getMergeable();
        }
        if (mergeable != null) {
            return mergeable;
        }
        if (System.currentTimeMillis() > end) {
            return null;
        }
        try {
            Thread.sleep(sleepMS);
        } catch (InterruptedException e) {
            // ignore
        }
    }
}
 
Example 3
Source File: GitHubSCMSource.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
private static void ensureDetailedGHPullRequest(GHPullRequest pr, TaskListener listener, GitHub github, GHRepository ghRepository) throws IOException, InterruptedException {
    final long sleep = 1000;
    int retryCountdown = 4;

    Connector.checkApiRateLimit(listener, github);
    while (pr.getMergeable() == null && retryCountdown > 1) {
        listener.getLogger().format(
            "Waiting for GitHub to create a merge commit for pull request %d.  Retrying %d more times...%n",
            pr.getNumber(),
            retryCountdown);
        retryCountdown -= 1;
        Thread.sleep(sleep);
        Connector.checkApiRateLimit(listener, github);
    }


}
 
Example 4
Source File: GitHubPRNonMergeableEvent.java    From github-integration-plugin with MIT License 6 votes vote down vote up
@Override
public GitHubPRCause check(@Nonnull GitHubPRDecisionContext prDecisionContext) throws IOException {
    TaskListener listener = prDecisionContext.getListener();
    GHPullRequest remotePR = prDecisionContext.getRemotePR();
    final PrintStream logger = listener.getLogger();

    Boolean mergeable;
    try {
        mergeable = remotePR.getMergeable();
    } catch (IOException e) {
        listener.error(DISPLAY_NAME + ": can't get mergeable status {}", e);
        LOGGER.warn("Can't get mergeable status: {}", e);
        mergeable = false;
    }
    mergeable = mergeable != null ? mergeable : false;

    if (!mergeable) {
        return prDecisionContext.newCause(DISPLAY_NAME, isSkip());
    }

    return null;
}