/** Checks if given fork owner exists */
  public FormValidation checkDepFork(@QueryParameter String value, @QueryParameter String name)
      throws IOException, ServletException {

    doFillForkItems(value, name);

    if (value.length() == 0) {
      return FormValidation.error(Messages.Fork_NoFork());
    }

    // check if given fork owner is in fork list
    /*for (String fork : this.forkItems) {
    	if (fork.equals(value)) {
    		return (msg.length()==0) ? FormValidation.ok() : FormValidation.ok(msg);
    	}
    }*/

    // if fork owner was not in list
    try {
      // check if user exists
      try {
        UserService githubUserSrv = new UserService(this.githubClient);
        githubUserSrv.getUser(value);
      } catch (Exception ex) {
        return FormValidation.error(Messages.Fork_OwnerNotFound() + "\n" + ex.getMessage());
      }
      // check if user has public repository with given name
      try {
        RepositoryService githubRepoSrv = new RepositoryService(this.githubClient);
        List<org.eclipse.egit.github.core.Repository> repos = githubRepoSrv.getRepositories(value);
        for (org.eclipse.egit.github.core.Repository repo : repos) {
          if (repo.getName().equals(name)) return FormValidation.ok(Messages.Fork_Found());
        }
      } catch (Exception ex) {
        return FormValidation.error(Messages.Fork_GetReposFailed() + "\n" + ex.getMessage());
      }
      return FormValidation.ok();
    } catch (Exception ex) {
      return FormValidation.error(Messages.Fork_AuthFailed() + "\n" + ex.getMessage());
    }
  }
  @JavaScriptMethod
  public String checkFork(String fork, String repo) {

    doFillForkItems(fork, repo);

    if (fork.length() == 0) {
      return Messages.Fork_NoFork();
    }

    // check if given fork owner is in fork list
    for (String f : this.forkItems) {
      if (f.equals(fork)) {
        return "__succeeded";
      }
    }

    // if fork owner was not in list
    try {
      // check if user exists
      try {
        UserService githubUserSrv = new UserService(this.githubClient);
        githubUserSrv.getUser(fork);
      } catch (Exception ex) {
        return Messages.Fork_OwnerNotFound() + "\n" + ex.getMessage();
      }
      // check if user has public repository with given name
      try {
        RepositoryService githubRepoSrv = new RepositoryService(this.githubClient);
        List<org.eclipse.egit.github.core.Repository> repos = githubRepoSrv.getRepositories(fork);
        for (org.eclipse.egit.github.core.Repository r : repos) {
          if (r.getName().equals(repo)) return Messages.Fork_Found() + "__succeeded";
        }
      } catch (Exception ex) {
        return Messages.Fork_GetReposFailed() + "\n" + ex.getMessage();
      }
      return "__succeeded";
    } catch (Exception ex) {
      return Messages.Fork_AuthFailed() + "\n" + ex.getMessage();
    }
  }