Search in sources :

Example 11 with FileContent

use of org.jetbrains.plugins.github.api.requests.GithubGistRequest.FileContent in project intellij-community by JetBrains.

the class GithubCreateGistTestBase method createContent.

@NotNull
protected static List<FileContent> createContent() {
    List<FileContent> content = new ArrayList<>();
    content.add(new FileContent("file1", "file1 content"));
    content.add(new FileContent("file2", "file2 content"));
    content.add(new FileContent("dir_file3", "file3 content"));
    return content;
}
Also used : FileContent(org.jetbrains.plugins.github.api.requests.GithubGistRequest.FileContent) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with FileContent

use of org.jetbrains.plugins.github.api.requests.GithubGistRequest.FileContent in project intellij-community by JetBrains.

the class GithubCreateGistTestBase method checkGistContent.

protected void checkGistContent(@NotNull List<FileContent> expected) {
    GithubGist result = getGist();
    List<FileContent> files = new ArrayList<>();
    for (GithubGist.GistFile file : result.getFiles()) {
        files.add(new FileContent(file.getFilename(), file.getContent()));
    }
    assertTrue("Gist content differs from sample", Comparing.haveEqualElements(files, expected));
}
Also used : FileContent(org.jetbrains.plugins.github.api.requests.GithubGistRequest.FileContent) GithubGist(org.jetbrains.plugins.github.api.data.GithubGist) ArrayList(java.util.ArrayList)

Example 13 with FileContent

use of org.jetbrains.plugins.github.api.requests.GithubGistRequest.FileContent in project intellij-community by JetBrains.

the class GithubCreateGistAction method createGist.

@Nullable
static String createGist(@NotNull Project project, @NotNull GithubAuthDataHolder auth, @NotNull ProgressIndicator indicator, @NotNull List<FileContent> contents, final boolean isPrivate, @NotNull final String description, @Nullable String filename) {
    if (contents.isEmpty()) {
        GithubNotifications.showWarning(project, FAILED_TO_CREATE_GIST, "Can't create empty gist");
        return null;
    }
    if (contents.size() == 1 && filename != null) {
        FileContent entry = contents.iterator().next();
        contents = Collections.singletonList(new FileContent(filename, entry.getContent()));
    }
    try {
        final List<FileContent> finalContents = contents;
        return GithubUtil.runTask(project, auth, indicator, AuthLevel.ANY, connection -> GithubApiUtil.createGist(connection, finalContents, description, isPrivate)).getHtmlUrl();
    } catch (IOException e) {
        GithubNotifications.showError(project, FAILED_TO_CREATE_GIST, e);
        return null;
    }
}
Also used : FileContent(org.jetbrains.plugins.github.api.requests.GithubGistRequest.FileContent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) org.jetbrains.plugins.github.util(org.jetbrains.plugins.github.util) ReadAction(com.intellij.openapi.application.ReadAction) ArrayList(java.util.ArrayList) GithubApiUtil(org.jetbrains.plugins.github.api.GithubApiUtil) Task(com.intellij.openapi.progress.Task) Project(com.intellij.openapi.project.Project) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) Logger(com.intellij.openapi.diagnostic.Logger) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) StringUtil(com.intellij.openapi.util.text.StringUtil) GithubCreateGistDialog(org.jetbrains.plugins.github.ui.GithubCreateGistDialog) BrowserUtil(com.intellij.ide.BrowserUtil) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) IOException(java.io.IOException) Editor(com.intellij.openapi.editor.Editor) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) List(java.util.List) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) NotNull(org.jetbrains.annotations.NotNull) FileContent(org.jetbrains.plugins.github.api.requests.GithubGistRequest.FileContent) Ref(com.intellij.openapi.util.Ref) Collections(java.util.Collections) GithubIcons(icons.GithubIcons) IOException(java.io.IOException) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with FileContent

use of org.jetbrains.plugins.github.api.requests.GithubGistRequest.FileContent in project intellij-community by JetBrains.

the class GithubCreateGistAction method getContentFromDirectory.

@NotNull
private static List<FileContent> getContentFromDirectory(@NotNull VirtualFile dir, @NotNull Project project, @Nullable String prefix) {
    List<FileContent> contents = new ArrayList<>();
    for (VirtualFile file : dir.getChildren()) {
        if (!isFileIgnored(file, project)) {
            String pref = addPrefix(dir.getName(), prefix, true);
            contents.addAll(getContentFromFile(file, project, pref));
        }
    }
    return contents;
}
Also used : FileContent(org.jetbrains.plugins.github.api.requests.GithubGistRequest.FileContent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FileContent (org.jetbrains.plugins.github.api.requests.GithubGistRequest.FileContent)14 ArrayList (java.util.ArrayList)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 Document (com.intellij.openapi.editor.Document)4 NotNull (org.jetbrains.annotations.NotNull)4 IOException (java.io.IOException)2 BrowserUtil (com.intellij.ide.BrowserUtil)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)1 ReadAction (com.intellij.openapi.application.ReadAction)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Editor (com.intellij.openapi.editor.Editor)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 FileTypeManager (com.intellij.openapi.fileTypes.FileTypeManager)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)1 Project (com.intellij.openapi.project.Project)1 Ref (com.intellij.openapi.util.Ref)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1