/** {@inheritDoc } */
  @Override
  public GitData retrieveGitData(String username) {
    GitData gitData = new GitData();
    List<Repository> repositories;
    User user;

    try {
      RepositoryService repositoryService = new RepositoryService();
      UserService userService = new UserService();
      repositories = repositoryService.getRepositories(username);
      user = userService.getUser(username);
      prepareData(gitData, repositories, user);
    } catch (RequestException rq) {
      gitData.setInErrorState(true);
      gitData.setError("The user doesn't exist!");
      LOG.debug("The user doesn't exist!");
    } catch (IOException io) {
      gitData.setInErrorState(true);
      gitData.setError("Something went wrong while trying to interact with the GitHub service!");
      LOG.debug("Something went wrong while trying to interact with the GitHub service!");
      io.printStackTrace();
    }

    return gitData;
  }
Beispiel #2
0
  @Bean
  public UserService userService() {

    UserService userService = new UserService();
    userService
        .getClient()
        .setCredentials(
            env.getRequiredProperty(USUARIO_GIT), env.getRequiredProperty(PASSWORD_GIT));
    return userService;
  }
  /** 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();
    }
  }
  @Override
  protected User run(final Account account) throws Exception {
    service.follow(login);

    return null;
  }
 @Override
 protected Boolean run(final Account account) throws Exception {
   return service.isFollowing(login);
 }