/**
   * Fills combobox with branches of given repository fork
   *
   * @param repoName
   * @param fork
   * @return
   */
  public ComboBoxModel doFillBranchItems(@QueryParameter String name, @QueryParameter String fork) {
    ComboBoxModel aux = new ComboBoxModel();

    if (this.githubClient.getUser() == null) {
      setGithubConfig();
    }

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

    try {
      RepositoryId repoId = new RepositoryId(fork, name);
      RepositoryService githubRepoSrv = new RepositoryService(this.githubClient);
      List<RepositoryBranch> branches = githubRepoSrv.getBranches(repoId);

      for (RepositoryBranch branch : branches) {
        aux.add(branch.getName());
      }

    } catch (Exception e) {
      // TODO: handle exception
    }
    Collections.sort(aux);
    return this.branchItems = aux;
  }
 /**
  * Data binding that returns all possible project names to be used in the project autocomplete.
  *
  * @return
  */
 public ComboBoxModel doFillProjectItems() {
   setGlobalConfiguration();
   ComboBoxModel names = new ComboBoxModel();
   try {
     Set<com.octopusdeploy.api.Project> projects = api.getAllProjects();
     for (com.octopusdeploy.api.Project proj : projects) {
       names.add(proj.getName());
     }
   } catch (Exception ex) {
     Logger.getLogger(OctopusDeployDeploymentRecorder.class.getName())
         .log(Level.SEVERE, null, ex);
   }
   return names;
 }
  /** Fill combobox with forks of repository */
  public ComboBoxModel doFillForkItems(@QueryParameter String value, @QueryParameter String name) {
    ComboBoxModel aux = new ComboBoxModel();

    if (this.githubClient.getUser() == null) {
      setGithubConfig();
    }

    try {
      RepositoryService githubRepoSrv = new RepositoryService(this.githubClient);
      List<org.eclipse.egit.github.core.Repository> forks;

      try {
        // get parent repository if repository itself is forked
        org.eclipse.egit.github.core.Repository parent =
            githubRepoSrv.getRepository(value, name).getParent();

        if (parent != null) {
          // get fork of parent repository
          forks = githubRepoSrv.getForks(parent);
          for (org.eclipse.egit.github.core.Repository fork : forks) {
            org.eclipse.egit.github.core.User user = fork.getOwner();
            aux.add(user.getLogin());
          }
        }

        if (aux.isEmpty()) {
          // add forks of repository
          forks = githubRepoSrv.getForks(new RepositoryId(value, name));
          for (org.eclipse.egit.github.core.Repository fork : forks) {
            org.eclipse.egit.github.core.User user = fork.getOwner();
            aux.add(user.getLogin());
          }
        }
        aux.add(0, value);
      } catch (Exception ex) {
      }

      try {
        // try to use global githubLogin, find repository and add forks
        forks = githubRepoSrv.getForks(new RepositoryId(this.githubLogin, name));
        for (org.eclipse.egit.github.core.Repository fork : forks) {
          org.eclipse.egit.github.core.User user = fork.getOwner();
          if (!aux.contains(user.getLogin())) {
            aux.add(user.getLogin());
          }
        }
      } catch (Exception ex) {
      }

    } catch (Exception ex) {
      // TODO: handle exception
    }
    Collections.sort(aux);
    return this.forkItems = aux;
  }
  /** Fills combobox with repository names of organization */
  public ComboBoxModel doFillNameItems(@QueryParameter String fork) {
    ComboBoxModel aux = new ComboBoxModel();

    if (this.githubClient.getUser() == null) {
      setGithubConfig();
    }

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

    try {
      RepositoryService githubRepoSrv = new RepositoryService(githubClient);
      List<org.eclipse.egit.github.core.Repository> repos = githubRepoSrv.getRepositories(fork);
      for (org.eclipse.egit.github.core.Repository repo : repos) {
        if (!aux.contains(repo.getName())) aux.add(0, repo.getName());
      }
    } catch (IOException ex) {
      // TODO: handle exception
    }
    Collections.sort(aux);
    return this.repoNameItems = aux;
  }