From 1bfe7dd99b658f6d6fd254b9ed4eabaef5fdd6d8 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 2 Jun 2016 23:50:18 -0700 Subject: [PATCH] Issue #264: wait for the repo to finish forking --- src/main/java/org/kohsuke/github/GHRepository.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index dab8166cc3..75a4849305 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -587,7 +587,19 @@ protected void wrapUp(GHRepository[] page) { * Newly forked repository that belong to you. */ public GHRepository fork() throws IOException { - return new Requester(root).method("POST").to(getApiTailUrl("forks"), GHRepository.class).wrap(root); + new Requester(root).method("POST").to(getApiTailUrl("forks"), null); + + // this API is asynchronous. we need to wait for a bit + for (int i=0; i<10; i++) { + GHRepository r = root.getMyself().getRepository(name); + if (r!=null) return r; + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + throw (IOException)new InterruptedIOException().initCause(e); + } + } + throw new IOException(this+" was forked but can't find the new repository"); } /**