question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot create new Gist File

See original GitHub issue

So far, I’ve been able to do the following:

Authenticate with a user token.

GitHub gitHub = GitHub.connectUsingOAuth(token);
boolean authenticated = gitHub.isCredentialValid();

Once authenticated I’ve been able to…

Pull list of users gists:

gitHub.getMyself().listGists()

Create NEW Gists with a file included:

gitHub.createGist()
     .file(filename,contents)
     .description(description)
     .public_(isPublic)
     .create();

Delete Gists:

gitHub.getGist(gistId).delete();

Get a list of files within a given gist:

GHGist gist = gitHub.getGist(gistId);
List<String> fileNameList = new ArrayList<>();
for (String filename : gist.getFiles().keySet()) {
     fileNameList.add(filename);
}

Though I cannot get the contents of a file this way, I have to pull the files’ URL and then get the contents of the file like this:

String fileContents = "";
GHGistFile file = gitHub.getGist(gistId).getFile(fileName);
try {
     HttpURLConnection conn = gitHub.getConnector().connect(new URL(file.getRawUrl()));
     conn.setRequestMethod("GET");
     InputStream is = conn.getInputStream();
     fileContents = IOUtils.toString(is, StandardCharsets.UTF_8);
     is.close();
     }
catch (IOException e) {e.printStackTrace();}
return fileContents;

THOSE are the things I CAN do … what I CAN’T seem to do with the API is anything at the gist file level where I need to delete a file, add a file, or update the contents of a file. For example, this code DOES NOT GENERATE ANY ERRORS, yet it simply does not work, meaning that the file is never created inside the gist:

public static void addFileToGist(String filename, String contents, String gistId) {
     GHGist gist = getGist(gistId);
     try{
          gist.update().addFile(filename,contents);
          CustomAlert.showInfo("File Added");
     }
     catch (IOException e) {e.printStackTrace();}
}

Am I doing something wrong? Or is there a way to do what I need to do but I just can’t seem to figure it out? Such as - do I need to create new gist files and update them etc. via the HTTPConnector? If so, can someone who me an example of how to do that?

Mike

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
EasyG0ing1commented, Nov 25, 2021

@bitwiseman - YES, 1.300 gets me connected with the HttpClientGitHubConnector.

You guys work fast over there - Thank you!

😃

1reaction
EasyG0ing1commented, Nov 3, 2021

@bitwiseman - You certainly won’t get any arguments from me on that statement!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating gists - GitHub Docs
Create a public gist if you're ready to share your ideas with the world or a secret ... After creating a gist, you...
Read more >
Cant create file inside existing Gist with java org.kohsuke ...
I've been working with the org.kohsuke.github Java library for a few days now. My only need for it is to do all things...
Read more >
Share code with GitHub gists | WebStorm Documentation
Gists let you share code snippets, entire files, or even applications. ... Once you have created a gist, you cannot convert it from...
Read more >
Raycast Store: GitHub Gist
Add new action for Search Gist command, you can use ⌘+N to create a new gist. Fix text error. Fix the bug that...
Read more >
What is a GIST on GitHub? - YouTube
Gists are similar to your normal GitHub repositories, but primarily focused on scenaios where you only have one (or a few files )...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found