use of org.jetbrains.plugins.github.api.data.GithubRepo in project intellij-community by JetBrains.
the class GithubCheckoutProvider method doCheckout.
@Override
public void doCheckout(@NotNull final Project project, @Nullable final Listener listener) {
if (!GithubUtil.testGitExecutable(project)) {
return;
}
BasicAction.saveAll();
List<GithubRepo> availableRepos;
try {
availableRepos = GithubUtil.computeValueInModalIO(project, "Access to GitHub", indicator -> GithubUtil.runTask(project, GithubAuthDataHolder.createFromSettings(), indicator, connection -> GithubApiUtil.getAvailableRepos(connection)));
} catch (IOException e) {
GithubNotifications.showError(project, "Couldn't get the list of GitHub repositories", e);
return;
}
Collections.sort(availableRepos, (r1, r2) -> {
final int comparedOwners = r1.getUserName().compareTo(r2.getUserName());
return comparedOwners != 0 ? comparedOwners : r1.getName().compareTo(r2.getName());
});
final GitCloneDialog dialog = new GitCloneDialog(project);
// Add predefined repositories to history
dialog.prependToHistory("-----------------------------------------------");
for (int i = availableRepos.size() - 1; i >= 0; i--) {
dialog.prependToHistory(GithubUrlUtil.getCloneUrl(availableRepos.get(i).getFullPath()));
}
if (!dialog.showAndGet()) {
return;
}
dialog.rememberSettings();
final VirtualFile destinationParent = LocalFileSystem.getInstance().findFileByIoFile(new File(dialog.getParentDirectory()));
if (destinationParent == null) {
return;
}
final String sourceRepositoryURL = dialog.getSourceRepositoryURL();
final String directoryName = dialog.getDirectoryName();
final String parentDirectory = dialog.getParentDirectory();
Git git = ServiceManager.getService(Git.class);
GitCheckoutProvider.clone(project, git, listener, destinationParent, sourceRepositoryURL, directoryName, parentDirectory);
}
use of org.jetbrains.plugins.github.api.data.GithubRepo in project intellij-community by JetBrains.
the class GithubRequestQueringTest method testOwnRepos.
public void testOwnRepos() throws Throwable {
List<GithubRepo> result = GithubApiUtil.getUserRepos(new GithubConnection(myAuth));
assertTrue(ContainerUtil.exists(result, (it) -> it.getName().equals("example")));
assertTrue(ContainerUtil.exists(result, (it) -> it.getName().equals("PullRequestTest")));
assertFalse(ContainerUtil.exists(result, (it) -> it.getName().equals("org_repo")));
}
use of org.jetbrains.plugins.github.api.data.GithubRepo in project intellij-community by JetBrains.
the class GithubRequestQueringTest method testPagination.
public void testPagination() throws Throwable {
GithubConnection connection = new GithubConnection(myGitHubSettings.getAuthData(), true);
try {
List<GithubRepo> availableRepos = GithubApiUtil.getUserRepos(connection, myLogin2);
List<String> realData = new ArrayList<>();
for (GithubRepo info : availableRepos) {
realData.add(info.getName());
}
List<String> expectedData = new ArrayList<>();
for (int i = 1; i <= 251; i++) {
expectedData.add(String.valueOf(i));
}
assertContainsElements(realData, expectedData);
} finally {
connection.close();
}
}
use of org.jetbrains.plugins.github.api.data.GithubRepo in project intellij-community by JetBrains.
the class GithubRequestQueringTest method testAllRepos.
public void testAllRepos() throws Throwable {
List<GithubRepo> result = GithubApiUtil.getUserRepos(new GithubConnection(myAuth), true);
assertTrue(ContainerUtil.exists(result, (it) -> it.getName().equals("example")));
assertTrue(ContainerUtil.exists(result, (it) -> it.getName().equals("PullRequestTest")));
assertTrue(ContainerUtil.exists(result, (it) -> it.getName().equals("org_repo")));
}
use of org.jetbrains.plugins.github.api.data.GithubRepo in project intellij-community by JetBrains.
the class GithubShareAction method loadGithubInfoWithModal.
@Nullable
private static GithubInfo loadGithubInfoWithModal(@NotNull final GithubAuthDataHolder authHolder, @NotNull final Project project) {
try {
return GithubUtil.computeValueInModalIO(project, "Access to GitHub", indicator -> {
return GithubUtil.runTask(project, authHolder, indicator, connection -> {
GithubUserDetailed userInfo = GithubApiUtil.getCurrentUser(connection);
HashSet<String> names = new HashSet<>();
for (GithubRepo info : GithubApiUtil.getUserRepos(connection)) {
names.add(info.getName());
}
return new GithubInfo(userInfo, names);
});
});
} catch (IOException e) {
GithubNotifications.showErrorDialog(project, "Failed to Connect to GitHub", e);
return null;
}
}
Aggregations