@SuppressWarnings("SleepWhileInLoop")
    private Repository forkAndWait(GitHubClient gitHubClient, Repository masterRepository) throws IOException {
        Properties properties = ApplicationProperties.getProperties();
        RepositoryService repositoryService = new RepositoryService(gitHubClient);
        Repository repositoryFork = repositoryService.forkRepository(masterRepository);
        
        int maxAttempts = 5;
        for (int i = 0; i < maxAttempts; i++) {
            try {
                logger.log(Level.INFO, "Waiting for fork of {0} to become available...", masterRepository.getName());
                Thread.sleep(5 * 1000);
                
                List<SearchRepository> searchRepositories = repositoryService.searchRepositories(
                        masterRepository.getName()
                        + " user:" + properties.getProperty(PropertiesConstants.GITHUB_ANON_USERNAME) 
                        + " fork:only");
                
                if (searchRepositories.size() == 1) {
                    return repositoryFork;
                }
            }
            catch (InterruptedException | IOException e) {
                logger.log(Level.INFO, "Error waiting for fork of {0} to create: {1}", new String[] {masterRepository.getName(), e.getMessage()});
            }
        }
        
        logger.log(Level.INFO, "Fork for {0} took too long to create.", masterRepository.getName());
        gitHubClient.delete("/repos/" + properties.getProperty(PropertiesConstants.GITHUB_ANON_USERNAME) + "/" + masterRepository.getName());
        throw new IOException("Repository fork could not be created.");
    }