private boolean hookExist() throws IOException {
   GHRepository ghRepository = getGitHubRepo();
   for (GHHook h : ghRepository.getHooks()) {
     if (!"web".equals(h.getName())) {
       continue;
     }
     if (!getHookUrl().equals(h.getConfig().get("url"))) {
       continue;
     }
     return true;
   }
   return false;
 }
 public boolean createHook() {
   if (ghRepository == null) {
     logger.log(
         Level.INFO,
         "Repository not available, cannot set pull request hook for repository {0}",
         reponame);
     return false;
   }
   try {
     if (hookExist()) {
       return true;
     }
     Map<String, String> config = new HashMap<String, String>();
     String secret = getSecret();
     config.put("url", new URL(getHookUrl()).toExternalForm());
     config.put("insecure_ssl", "1");
     if (secret != "") {
       config.put("secret", secret);
     }
     ghRepository.createHook("web", config, HOOK_EVENTS, true);
     return true;
   } catch (IOException ex) {
     logger.log(
         Level.SEVERE,
         "Couldn''t create web hook for repository {0}. Does the user (from global configuration) have admin rights to the repository?",
         reponame);
     return false;
   }
 }
  public void check() {
    if (!initGhRepository()) {
      return;
    }

    if (helper.isProjectDisabled()) {
      logger.log(Level.FINE, "Project is disabled, not checking github state");
      return;
    }

    List<GHPullRequest> openPulls;
    try {
      openPulls = ghRepository.getPullRequests(GHIssueState.OPEN);
    } catch (IOException ex) {
      logger.log(Level.SEVERE, "Could not retrieve open pull requests.", ex);
      return;
    }

    ConcurrentMap<Integer, GhprbPullRequest> pulls = helper.getTrigger().getPulls();

    Set<Integer> closedPulls = new HashSet<Integer>(pulls.keySet());

    for (GHPullRequest pr : openPulls) {
      if (pr.getHead() == null) {
        try {
          pr = ghRepository.getPullRequest(pr.getNumber());
        } catch (IOException ex) {
          logger.log(Level.SEVERE, "Could not retrieve pr " + pr.getNumber(), ex);
          return;
        }
      }
      try {
        check(pr);
      } catch (IOException ex) {
        logger.log(Level.SEVERE, "Could not retrieve pr " + pr.getNumber(), ex);
        return;
      }
      closedPulls.remove(pr.getNumber());
    }

    // remove closed pulls so we don't check them again
    for (Integer id : closedPulls) {
      pulls.remove(id);
    }
  }