use of org.jetbrains.plugins.github.api.requests.GithubGistRequest.FileContent in project intellij-community by JetBrains.
the class GithubCreateGistAction method getContentFromFile.
@NotNull
private static List<FileContent> getContentFromFile(@NotNull final VirtualFile file, @NotNull Project project, @Nullable String prefix) {
if (file.isDirectory()) {
return getContentFromDirectory(file, project, prefix);
}
if (file.getFileType().isBinary()) {
GithubNotifications.showWarning(project, FAILED_TO_CREATE_GIST, "Can't upload binary file: " + file);
return Collections.emptyList();
}
String content = ReadAction.compute(() -> {
try {
Document document = FileDocumentManager.getInstance().getDocument(file);
if (document != null) {
return document.getText();
} else {
return new String(file.contentsToByteArray(), file.getCharset());
}
} catch (IOException e) {
LOG.info("Couldn't read contents of the file " + file, e);
return null;
}
});
if (content == null) {
GithubNotifications.showWarning(project, FAILED_TO_CREATE_GIST, "Couldn't read the contents of the file " + file);
return Collections.emptyList();
}
if (StringUtil.isEmptyOrSpaces(content)) {
return Collections.emptyList();
}
String filename = addPrefix(file.getName(), prefix, false);
return Collections.singletonList(new FileContent(filename, content));
}
use of org.jetbrains.plugins.github.api.requests.GithubGistRequest.FileContent in project intellij-community by JetBrains.
the class GithubCreateGistContentTest method testCreateFromEmptyDirectory.
public void testCreateFromEmptyDirectory() throws Throwable {
List<FileContent> expected = new ArrayList<>();
VirtualFile file = myProjectRoot.findFileByRelativePath("folder/empty_folder");
assertNotNull(file);
List<FileContent> actual = GithubCreateGistAction.collectContents(myProject, null, file, null);
checkEquals(expected, actual);
}
use of org.jetbrains.plugins.github.api.requests.GithubGistRequest.FileContent in project intellij-community by JetBrains.
the class GithubCreateGistContentTest method testCreateFromEmptyFile.
public void testCreateFromEmptyFile() throws Throwable {
List<FileContent> expected = new ArrayList<>();
VirtualFile file = myProjectRoot.findFileByRelativePath("folder/empty_file");
assertNotNull(file);
List<FileContent> actual = GithubCreateGistAction.collectContents(myProject, null, file, null);
checkEquals(expected, actual);
}
use of org.jetbrains.plugins.github.api.requests.GithubGistRequest.FileContent in project intellij-community by JetBrains.
the class GithubCreateGistContentTest method testCreateFromDirectory.
public void testCreateFromDirectory() throws Throwable {
List<FileContent> expected = new ArrayList<>();
expected.add(new FileContent("folder_file1", "file1 content"));
expected.add(new FileContent("folder_file2", "file2 content"));
expected.add(new FileContent("folder_dir_file3", "file3 content"));
VirtualFile file = myProjectRoot.findFileByRelativePath("folder");
assertNotNull(file);
List<FileContent> actual = GithubCreateGistAction.collectContents(myProject, null, file, null);
checkEquals(expected, actual);
}
use of org.jetbrains.plugins.github.api.requests.GithubGistRequest.FileContent in project intellij-community by JetBrains.
the class GithubCreateGistTest method testAnonymous.
public void testAnonymous() throws Throwable {
List<FileContent> expected = createContent();
String url = GithubCreateGistAction.createGist(myProject, new GithubAuthDataHolder(GithubAuthData.createAnonymous(myHost)), myIndicator, expected, true, GIST_DESCRIPTION, null);
assertNotNull(url);
GIST_ID = url.substring(url.lastIndexOf('/') + 1);
checkGistExists();
checkGistAnonymous();
checkGistPrivate();
checkGistDescription(GIST_DESCRIPTION);
checkGistContent(expected);
// anonymous gists - undeletable
GIST_ID = null;
GIST = null;
}
Aggregations