mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-22 00:11:26 +00:00
116 lines
3.3 KiB
Java
116 lines
3.3 KiB
Java
package org.kohsuke.github;
|
|
|
|
import org.junit.Test;
|
|
import org.kohsuke.github.GHRepository.Contributor;
|
|
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
|
|
/**
|
|
* @author Kohsuke Kawaguchi
|
|
*/
|
|
public class RepositoryTest extends AbstractGitHubApiTestBase {
|
|
@Test
|
|
public void subscription() throws Exception {
|
|
GHRepository r = getRepository();
|
|
assertNull(r.getSubscription());
|
|
|
|
GHSubscription s = r.subscribe(true, false);
|
|
assertEquals(s.getRepository(), r);
|
|
|
|
s.delete();
|
|
|
|
assertNull(r.getSubscription());
|
|
}
|
|
|
|
@Test
|
|
public void listContributors() throws IOException {
|
|
GHRepository r = gitHub.getOrganization("stapler").getRepository("stapler");
|
|
int i=0;
|
|
boolean kohsuke = false;
|
|
|
|
for (Contributor c : r.listContributors()) {
|
|
System.out.println(c.getName());
|
|
assertTrue(c.getContributions()>0);
|
|
if (c.getLogin().equals("kohsuke"))
|
|
kohsuke = true;
|
|
if (i++ > 5)
|
|
break;
|
|
}
|
|
|
|
assertTrue(kohsuke);
|
|
}
|
|
|
|
@Test
|
|
public void getPermission() throws Exception {
|
|
kohsuke();
|
|
GHRepository r = gitHub.getRepository("github-api-test-org/test-permission");
|
|
assertEquals(GHPermissionType.ADMIN, r.getPermission("kohsuke"));
|
|
assertEquals(GHPermissionType.READ, r.getPermission("dude"));
|
|
r = gitHub.getOrganization("apache").getRepository("groovy");
|
|
try {
|
|
r.getPermission("jglick");
|
|
fail();
|
|
} catch (HttpException x) {
|
|
x.printStackTrace(); // good
|
|
assertEquals(403, x.getResponseCode());
|
|
}
|
|
|
|
if (false) {
|
|
// can't easily test this; there's no private repository visible to the test user
|
|
r = gitHub.getOrganization("cloudbees").getRepository("private-repo-not-writable-by-me");
|
|
try {
|
|
r.getPermission("jglick");
|
|
fail();
|
|
} catch (FileNotFoundException x) {
|
|
x.printStackTrace(); // good
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
public void LatestRepositoryExist() {
|
|
try {
|
|
// add the repository that have latest release
|
|
GHRelease release = gitHub.getRepository("kamontat/CheckIDNumber").getLatestRelease();
|
|
assertEquals("v3.0", release.getTagName());
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
fail();
|
|
}
|
|
}
|
|
|
|
@Test
|
|
public void LatestRepositoryNotExist() {
|
|
try {
|
|
// add the repository that `NOT` have latest release
|
|
GHRelease release = gitHub.getRepository("kamontat/Java8Example").getLatestRelease();
|
|
assertNull(release);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
fail();
|
|
}
|
|
}
|
|
|
|
private GHRepository getRepository() throws IOException {
|
|
return gitHub.getOrganization("github-api-test-org").getRepository("jenkins");
|
|
}
|
|
|
|
@Test
|
|
public void listLanguages() throws IOException {
|
|
GHRepository r = gitHub.getRepository("kohsuke/github-api");
|
|
String mainLanguage = r.getLanguage();
|
|
assertTrue(r.listLanguages().containsKey(mainLanguage));
|
|
}
|
|
|
|
@Test // Issue #261
|
|
public void listEmptyContributors() throws IOException {
|
|
GitHub gh = GitHub.connect();
|
|
for (Contributor c : gh.getRepository("github-api-test-org/empty").listContributors()) {
|
|
System.out.println(c);
|
|
}
|
|
}
|
|
}
|