Skip to content

Commit

Permalink
Add support for editing Gists.
Browse files Browse the repository at this point in the history
Fixes issue hub4j#466

NOTE: I could not get the deleteFile() method to work. Possibly an
issue with the underlying API itself.
  • Loading branch information
martinvanzijl committed Dec 19, 2018
1 parent fad203a commit f497715
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/java/org/kohsuke/github/GHGist.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;

Expand Down Expand Up @@ -159,6 +160,27 @@ public void delete() throws IOException {
new Requester(root).method("DELETE").to("/gists/" + id);
}

private String getApiRoute() {
return "/gists/" + id;
}

private void edit(String key, Object value) throws IOException {
new Requester(root)._with(key, value).method("PATCH").to(getApiRoute());
}

public void setDescription(String value) throws IOException {
edit("description",value);
}

// NOTE: This does NOT work, even when using CURL!
// I suspect it's a bug in the API itself...
// I should raise a ticket with Gibhub...
public void deleteFile(String fileName) throws IOException {
LinkedHashMap<String,Object> files = new LinkedHashMap<String, Object>();
files.put(fileName, Collections.singletonMap("filename", null));
edit("files",files);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down

0 comments on commit f497715

Please sign in to comment.