Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit 25d426f

Browse files
committed
Bug fix based on tests
1 parent 9d91ebc commit 25d426f

3 files changed

Lines changed: 75 additions & 2 deletions

File tree

src/main/java/org/kohsuke/github/GHGist.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public String getCommentsUrl() {
115115
}
116116

117117
String getApiTailUrl(String tail) {
118-
return "/gist/" + id + '/' + tail;
118+
return "/gists/" + id + '/' + tail;
119119
}
120120

121121
public void star() throws IOException {
@@ -159,6 +159,20 @@ protected void wrapUp(GHGist[] page) {
159159
* Deletes this gist.
160160
*/
161161
public void delete() throws IOException {
162-
new Requester(root).method("DELETE").to("/gist/" + id);
162+
new Requester(root).method("DELETE").to("/gists/" + id);
163+
}
164+
165+
@Override
166+
public boolean equals(Object o) {
167+
if (this == o) return true;
168+
if (o == null || getClass() != o.getClass()) return false;
169+
GHGist ghGist = (GHGist) o;
170+
return id.equals(ghGist.id);
171+
172+
}
173+
174+
@Override
175+
public int hashCode() {
176+
return id.hashCode();
163177
}
164178
}

src/main/java/org/kohsuke/github/GHGistBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public GHGistBuilder file(String fileName, String content) {
4242
* Creates a Gist based on the parameters specified thus far.
4343
*/
4444
public GHGist create() throws IOException {
45+
req._with("files",files);
4546
return req.to("/gists",GHGist.class).wrapUp(root);
4647
}
4748
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.kohsuke.github;
2+
3+
import org.junit.Test;
4+
5+
/**
6+
* @author Kohsuke Kawaguchi
7+
*/
8+
public class GistTest extends AbstractGitHubApiTestBase {
9+
/**
10+
* CRUD operation.
11+
*/
12+
@Test
13+
public void lifecycleTest() throws Exception {
14+
GHGist gist = gitHub.createGist()
15+
.public_(false)
16+
.description("Test Gist")
17+
.file("abc.txt","abc")
18+
.file("def.txt","def")
19+
.create();
20+
21+
assertNotNull(gist.getCreatedAt());
22+
assertNotNull(gist.getUpdatedAt());
23+
24+
assertNotNull(gist.getCommentsUrl());
25+
assertNotNull(gist.getCommitsUrl());
26+
assertNotNull(gist.getGitPullUrl());
27+
assertNotNull(gist.getGitPushUrl());
28+
assertNotNull(gist.getHtmlUrl());
29+
30+
gist.delete();
31+
}
32+
33+
@Test
34+
public void starTest() throws Exception {
35+
GHGist gist = gitHub.getGist("9903708");
36+
assertEquals("rtyler",gist.getOwner().getLogin());
37+
38+
gist.star();
39+
assertTrue(gist.isStarred());
40+
gist.unstar();
41+
assertFalse(gist.isStarred());
42+
43+
GHGist newGist = gist.fork();
44+
45+
try {
46+
for (GHGist g : gist.listForks()) {
47+
if (g.equals(newGist)) {
48+
// expected to find it in the clone list
49+
return;
50+
}
51+
}
52+
53+
fail("Expected to find a newly cloned gist");
54+
} finally {
55+
newGist.delete();
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)