@Nullable private static GithubFullPath findRepositoryByUser( @NotNull Project project, @NotNull String user, @NotNull Set<GithubFullPath> forks, @NotNull GithubAuthData auth, @NotNull GithubRepo source) { for (GithubFullPath path : forks) { if (StringUtil.equalsIgnoreCase(user, path.getUser())) { return path; } } try { GithubRepoDetailed target = GithubApiUtil.getDetailedRepoInfo(auth, user, source.getName()); if (target.getSource() != null && StringUtil.equals(target.getSource().getUserName(), source.getUserName())) { return target.getFullPath(); } } catch (IOException ignore) { // such repo may not exist } try { GithubRepo fork = GithubApiUtil.findForkByUser(auth, source.getUserName(), source.getName(), user); if (fork != null) { return fork.getFullPath(); } } catch (IOException e) { GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, e); } return null; }
@Nullable private static RepositoryInfo getDetailedRepoInfo( @NotNull String url, @NotNull String login, @NotNull String password, @NotNull String owner, @NotNull String name) { try { final String request = "/repos/" + owner + "/" + name; JsonElement jsonObject = GithubApiUtil.getRequest(url, login, password, request); if (jsonObject == null) { LOG.info( String.format( "Information about repository is unavailable. Owner: %s, Name: %s", owner, name)); return null; } return parseSingleRepositoryInfo(jsonObject.getAsJsonObject()); } catch (IOException e) { LOG.info( String.format( "Exception was thrown when trying to retrieve information about repository. Owner: %s, Name: %s", owner, name)); return null; } }
@NotNull private static List<RepositoryInfo> getAvailableRepos( @NotNull String url, @NotNull String login, @NotNull String password) { final String request = "/user/repos"; try { JsonElement result = GithubApiUtil.getRequest(url, login, password, request); if (result == null) { return Collections.emptyList(); } return parseRepositoryInfos(result); } catch (IOException e) { LOG.error(e); return Collections.emptyList(); } }
@Nullable private static GithubPullRequest createPullRequest( @NotNull Project project, @NotNull GithubAuthData auth, @NotNull GithubFullPath targetRepo, @NotNull String title, @NotNull String description, @NotNull String head, @NotNull String base) { try { return GithubApiUtil.createPullRequest( auth, targetRepo.getUser(), targetRepo.getRepository(), title, description, head, base); } catch (IOException e) { GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, e); return null; } }
public static boolean isGithubUrl(@NotNull String url) { return url.contains(GithubApiUtil.removeProtocolPrefix(GithubSettings.getInstance().getHost())); }
@Nullable private static GithubUser retrieveCurrentUserInfo( @NotNull String url, @NotNull String login, @NotNull String password) throws IOException { JsonElement result = GithubApiUtil.getRequest(url, login, password, "/user"); return parseUserInfo(result); }