Merge remote-tracking branch 'github-api/master' into BranchMissing

This commit is contained in:
Liam Newman
2019-11-15 15:36:24 -08:00
72 changed files with 1126 additions and 489 deletions

View File

@@ -165,9 +165,12 @@ public abstract class AbstractGitHubWireMockTest extends Assert {
if (mockGitHub.isUseProxy()) {
cleanupRepository(fullName);
GHRepository repository = gitHubBeforeAfter.getOrganization(GITHUB_API_TEST_ORG).createRepository(name)
GHRepository repository = gitHubBeforeAfter.getOrganization(GITHUB_API_TEST_ORG)
.createRepository(name)
.description("A test repository for testing the github-api project: " + name)
.homepage("http://github-api.kohsuke.org/").autoInit(true).create();
.homepage("http://github-api.kohsuke.org/")
.autoInit(true)
.create();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {

View File

@@ -34,8 +34,10 @@ public class AppTest extends AbstractGitHubWireMockTest {
cleanupUserRepository("github-api-test-rename");
cleanupUserRepository(targetName);
GHRepository r = gitHub.createRepository("github-api-test-rename", "a test repository",
"http://github-api.kohsuke.org/", true);
GHRepository r = gitHub.createRepository("github-api-test-rename",
"a test repository",
"http://github-api.kohsuke.org/",
true);
assertThat(r.hasIssues(), is(true));
r.enableIssueTracker(false);
@@ -49,8 +51,11 @@ public class AppTest extends AbstractGitHubWireMockTest {
public void testRepositoryWithAutoInitializationCRUD() throws Exception {
String name = "github-api-test-autoinit";
cleanupUserRepository(name);
GHRepository r = gitHub.createRepository(name).description("a test repository for auto init")
.homepage("http://github-api.kohsuke.org/").autoInit(true).create();
GHRepository r = gitHub.createRepository(name)
.description("a test repository for auto init")
.homepage("http://github-api.kohsuke.org/")
.autoInit(true)
.create();
r.enableIssueTracker(false);
r.enableDownloads(false);
r.enableWiki(false);
@@ -91,8 +96,13 @@ public class AppTest extends AbstractGitHubWireMockTest {
GHUser u = getUser();
GHRepository repository = getTestRepository();
GHMilestone milestone = repository.createMilestone("Test Milestone Title3", "Test Milestone");
GHIssue o = repository.createIssue("testing").body("this is body").assignee(u).label("bug").label("question")
.milestone(milestone).create();
GHIssue o = repository.createIssue("testing")
.body("this is body")
.assignee(u)
.label("bug")
.label("question")
.milestone(milestone)
.create();
assertNotNull(o);
o.close();
}
@@ -101,7 +111,9 @@ public class AppTest extends AbstractGitHubWireMockTest {
public void testCreateAndListDeployments() throws IOException {
GHRepository repository = getTestRepository();
GHDeployment deployment = repository.createDeployment("master")
.payload("{\"user\":\"atmos\",\"room_id\":123456}").description("question").environment("unittest")
.payload("{\"user\":\"atmos\",\"room_id\":123456}")
.description("question")
.environment("unittest")
.create();
assertNotNull(deployment.getCreator());
assertNotNull(deployment.getId());
@@ -117,10 +129,14 @@ public class AppTest extends AbstractGitHubWireMockTest {
@Test
public void testGetDeploymentStatuses() throws IOException {
GHRepository repository = getTestRepository();
GHDeployment deployment = repository.createDeployment("master").description("question")
.payload("{\"user\":\"atmos\",\"room_id\":123456}").create();
GHDeployment deployment = repository.createDeployment("master")
.description("question")
.payload("{\"user\":\"atmos\",\"room_id\":123456}")
.create();
GHDeploymentStatus ghDeploymentStatus = deployment.createStatus(GHDeploymentState.SUCCESS)
.description("success").targetUrl("http://www.github.com").create();
.description("success")
.targetUrl("http://www.github.com")
.create();
Iterable<GHDeploymentStatus> deploymentStatuses = deployment.listStatuses();
assertNotNull(deploymentStatuses);
assertEquals(1, Iterables.size(deploymentStatuses));
@@ -129,7 +145,8 @@ public class AppTest extends AbstractGitHubWireMockTest {
@Test
public void testGetIssues() throws Exception {
List<GHIssue> closedIssues = gitHub.getOrganization("github-api").getRepository("github-api")
List<GHIssue> closedIssues = gitHub.getOrganization("github-api")
.getRepository("github-api")
.getIssues(GHIssueState.CLOSED);
// prior to using PagedIterable GHRepository.getIssues(GHIssueState) would only retrieve 30 issues
assertTrue(closedIssues.size() > 150);
@@ -150,11 +167,20 @@ public class AppTest extends AbstractGitHubWireMockTest {
GHIssue unhomed = null;
GHIssue homed = null;
try {
unhomed = repository.createIssue("testing").body("this is body").assignee(u).label("bug").label("question")
unhomed = repository.createIssue("testing")
.body("this is body")
.assignee(u)
.label("bug")
.label("question")
.create();
assertEquals(unhomed.getNumber(), repository.getIssues(GHIssueState.OPEN, null).get(0).getNumber());
homed = repository.createIssue("testing").body("this is body").assignee(u).label("bug").label("question")
.milestone(milestone).create();
homed = repository.createIssue("testing")
.body("this is body")
.assignee(u)
.label("bug")
.label("question")
.milestone(milestone)
.create();
assertEquals(homed.getNumber(), repository.getIssues(GHIssueState.OPEN, milestone).get(0).getNumber());
} finally {
if (unhomed != null) {
@@ -306,7 +332,8 @@ public class AppTest extends AbstractGitHubWireMockTest {
@Test
public void testMembership() throws Exception {
Set<String> members = gitHub.getOrganization(GITHUB_API_TEST_ORG).getRepository("jenkins")
Set<String> members = gitHub.getOrganization(GITHUB_API_TEST_ORG)
.getRepository("jenkins")
.getCollaboratorNames();
// System.out.println(members.contains("kohsuke"));
}
@@ -344,7 +371,8 @@ public class AppTest extends AbstractGitHubWireMockTest {
@Test
public void testCommit() throws Exception {
GHCommit commit = gitHub.getUser("jenkinsci").getRepository("jenkins")
GHCommit commit = gitHub.getUser("jenkinsci")
.getRepository("jenkins")
.getCommit("08c1c9970af4d609ae754fbe803e06186e3206f7");
assertEquals(1, commit.getParents().size());
assertEquals(1, commit.getFiles().size());
@@ -374,8 +402,13 @@ public class AppTest extends AbstractGitHubWireMockTest {
public void testQueryCommits() throws Exception {
List<String> sha1 = new ArrayList<String>();
for (GHCommit c : gitHub.getUser("jenkinsci").getRepository("jenkins").queryCommits()
.since(new Date(1199174400000L)).until(1201852800000L).path("pom.xml").list()) {
for (GHCommit c : gitHub.getUser("jenkinsci")
.getRepository("jenkins")
.queryCommits()
.since(new Date(1199174400000L))
.until(1201852800000L)
.path("pom.xml")
.list()) {
// System.out.println(c.getSHA1());
sha1.add(c.getSHA1());
}
@@ -403,7 +436,8 @@ public class AppTest extends AbstractGitHubWireMockTest {
@Test
public void testCreateCommitComment() throws Exception {
GHCommit commit = gitHub.getUser("kohsuke").getRepository("sandbox-ant")
GHCommit commit = gitHub.getUser("kohsuke")
.getRepository("sandbox-ant")
.getCommit("8ae38db0ea5837313ab5f39d43a6f73de3bd9000");
GHCommitComment c = commit.createComment("[testing](http://kohsuse.org/)");
// System.out.println(c);
@@ -679,8 +713,8 @@ public class AppTest extends AbstractGitHubWireMockTest {
public void testCommitStatusContext() throws IOException {
GHRepository myRepository = getTestRepository();
GHRef masterRef = myRepository.getRef("heads/master");
GHCommitStatus commitStatus = myRepository.createCommitStatus(masterRef.getObject().getSha(),
GHCommitState.SUCCESS, "http://www.example.com", "test", "test/context");
GHCommitStatus commitStatus = myRepository.createCommitStatus(masterRef.getObject()
.getSha(), GHCommitState.SUCCESS, "http://www.example.com", "test", "test/context");
assertEquals("test/context", commitStatus.getContext());
}

View File

@@ -336,15 +336,18 @@ public class GHRateLimitTest extends AbstractGitHubWireMockTest {
rateLimit = gitHub.rateLimit();
assertThat(rateLimit, notNullValue());
assertThat("rateLimit() selects header instance when not expired, does not ask server", rateLimit,
assertThat("rateLimit() selects header instance when not expired, does not ask server",
rateLimit,
sameInstance(headerRateLimit));
// Nothing changes still valid
Thread.sleep(1000);
assertThat("rateLimit() selects header instance when not expired, does not ask server", gitHub.rateLimit(),
assertThat("rateLimit() selects header instance when not expired, does not ask server",
gitHub.rateLimit(),
sameInstance(headerRateLimit));
assertThat("rateLimit() selects header instance when not expired, does not ask server", gitHub.lastRateLimit(),
assertThat("rateLimit() selects header instance when not expired, does not ask server",
gitHub.lastRateLimit(),
sameInstance(headerRateLimit));
assertThat(mockGitHub.getRequestCount(), equalTo(1));
@@ -355,12 +358,15 @@ public class GHRateLimitTest extends AbstractGitHubWireMockTest {
assertThat("Header instance has expired", gitHub.lastRateLimit().isExpired(), is(true));
assertThat("rateLimit() will ask server when header instance expires and it has not called getRateLimit() yet",
gitHub.rateLimit(), not(sameInstance(rateLimit)));
gitHub.rateLimit(),
not(sameInstance(rateLimit)));
assertThat("lastRateLimit() (header instance) is populated as part of internal call to getRateLimit()",
gitHub.lastRateLimit(), not(sameInstance(rateLimit)));
gitHub.lastRateLimit(),
not(sameInstance(rateLimit)));
assertThat("After request, rateLimit() selects header instance since it has been refreshed", gitHub.rateLimit(),
assertThat("After request, rateLimit() selects header instance since it has been refreshed",
gitHub.rateLimit(),
sameInstance(gitHub.lastRateLimit()));
headerRateLimit = gitHub.lastRateLimit();
@@ -375,10 +381,12 @@ public class GHRateLimitTest extends AbstractGitHubWireMockTest {
// Using custom data to have a header instance that expires before the queried instance
assertThat(
"if header instance expires but queried instance is valid, ratelimit() uses it without asking server",
gitHub.rateLimit(), not(sameInstance(gitHub.lastRateLimit())));
gitHub.rateLimit(),
not(sameInstance(gitHub.lastRateLimit())));
assertThat("ratelimit() should almost never return a return a GHRateLimit that is already expired",
gitHub.rateLimit().isExpired(), is(false));
gitHub.rateLimit().isExpired(),
is(false));
assertThat("Header instance hasn't been reloaded", gitHub.lastRateLimit(), sameInstance(headerRateLimit));
assertThat("Header instance has expired", gitHub.lastRateLimit().isExpired(), is(true));
@@ -390,12 +398,15 @@ public class GHRateLimitTest extends AbstractGitHubWireMockTest {
headerRateLimit = gitHub.rateLimit();
assertThat("rateLimit() has asked server for new information", gitHub.rateLimit(),
assertThat("rateLimit() has asked server for new information",
gitHub.rateLimit(),
not(sameInstance(rateLimit)));
assertThat("rateLimit() has asked server for new information", gitHub.lastRateLimit(),
assertThat("rateLimit() has asked server for new information",
gitHub.lastRateLimit(),
not(sameInstance(rateLimit)));
assertThat("rateLimit() selects header instance when not expired, does not ask server", gitHub.rateLimit(),
assertThat("rateLimit() selects header instance when not expired, does not ask server",
gitHub.rateLimit(),
sameInstance((gitHub.lastRateLimit())));
assertThat(mockGitHub.getRequestCount(), equalTo(3));

View File

@@ -15,8 +15,12 @@ public class GistTest extends AbstractGitHubWireMockTest {
@Test
public void lifecycleTest() throws Exception {
// CRUD operation
GHGist gist = gitHub.createGist().public_(false).description("Test Gist").file("abc.txt", "abc")
.file("def.txt", "def").create();
GHGist gist = gitHub.createGist()
.public_(false)
.description("Test Gist")
.file("abc.txt", "abc")
.file("def.txt", "def")
.create();
assertThat(gist.getCreatedAt(), is(notNullValue()));

View File

@@ -78,8 +78,8 @@ public class GitHubConnectionTest extends AbstractGitHubWireMockTest {
setupEnvironment(props);
GitHubBuilder builder = GitHubBuilder.fromEnvironment("customLogin", "customPassword", "customOauth",
"customEndpoint");
GitHubBuilder builder = GitHubBuilder
.fromEnvironment("customLogin", "customPassword", "customOauth", "customEndpoint");
assertEquals("bogusLogin", builder.user);
assertEquals("bogusOauth", builder.oauthToken);

View File

@@ -98,7 +98,8 @@ public class GitHubStaticTest extends Assert {
assertThat("Unknown should not replace worst record", GitHub.shouldReplace(unknown1, recordWorst), is(false));
assertThat("Earlier record should replace later worst", GitHub.shouldReplace(record0, recordWorst), is(true));
assertThat("Later worst record should not replace earlier", GitHub.shouldReplace(recordWorst, record0),
assertThat("Later worst record should not replace earlier",
GitHub.shouldReplace(recordWorst, record0),
is(false));
assertThat("Equivalent record should not replace", GitHub.shouldReplace(record0, record00), is(false));
@@ -109,14 +110,17 @@ public class GitHubStaticTest extends Assert {
assertThat("Higher limit record should not replace lower", GitHub.shouldReplace(record1, record2), is(false));
assertThat("Higher limit record with later reset should replace lower", GitHub.shouldReplace(record3, record2),
assertThat("Higher limit record with later reset should replace lower",
GitHub.shouldReplace(record3, record2),
is(true));
assertThat("Lower limit record with later reset should replace higher", GitHub.shouldReplace(record4, record1),
assertThat("Lower limit record with later reset should replace higher",
GitHub.shouldReplace(record4, record1),
is(true));
assertThat("Lower limit record with earlier reset should not replace higher",
GitHub.shouldReplace(record2, record4), is(false));
GitHub.shouldReplace(record2, record4),
is(false));
}

View File

@@ -56,8 +56,12 @@ public class GitHubTest extends AbstractGitHubWireMockTest {
@Test
public void searchContent() throws Exception {
PagedSearchIterable<GHContent> r = gitHub.searchContent().q("addClass").in("file").language("js")
.repo("jquery/jquery").list();
PagedSearchIterable<GHContent> r = gitHub.searchContent()
.q("addClass")
.in("file")
.language("js")
.repo("jquery/jquery")
.list();
GHContent c = r.iterator().next();
// System.out.println(c.getName());
assertNotNull(c.getDownloadUrl());
@@ -87,13 +91,13 @@ public class GitHubTest extends AbstractGitHubWireMockTest {
assertEquals(19, meta.getWeb().size());
// Also test examples here
Class[] examples = new Class[] { ReadOnlyObjects.GHMetaPublic.class, ReadOnlyObjects.GHMetaPackage.class,
Class[] examples = new Class[]{ ReadOnlyObjects.GHMetaPublic.class, ReadOnlyObjects.GHMetaPackage.class,
ReadOnlyObjects.GHMetaGettersUnmodifiable.class, ReadOnlyObjects.GHMetaGettersFinal.class,
ReadOnlyObjects.GHMetaGettersFinalCreator.class, };
for (Class metaClass : examples) {
ReadOnlyObjects.GHMetaExample metaExample = gitHub.retrieve().to("/meta",
(Class<ReadOnlyObjects.GHMetaExample>) metaClass);
ReadOnlyObjects.GHMetaExample metaExample = gitHub.retrieve()
.to("/meta", (Class<ReadOnlyObjects.GHMetaExample>) metaClass);
assertTrue(metaExample.isVerifiablePasswordAuthentication());
assertEquals(19, metaExample.getApi().size());
assertEquals(19, metaExample.getGit().size());

View File

@@ -15,13 +15,13 @@ public class Github2faTest extends AbstractGitHubWireMockTest {
public void test2faToken() throws IOException {
assertFalse("Test only valid when not proxying", mockGitHub.isUseProxy());
List<String> asList = Arrays.asList("repo", "gist", "write:packages", "read:packages", "delete:packages",
"user", "delete_repo");
List<String> asList = Arrays
.asList("repo", "gist", "write:packages", "read:packages", "delete:packages", "user", "delete_repo");
String nameOfToken = "Test2faTokenCreate";// +timestamp;// use time stamp to ensure the token creations do not
// collide with older tokens
GHAuthorization token = gitHub.createToken(asList, nameOfToken, "this is a test token created by a unit test",
() -> {
GHAuthorization token = gitHub
.createToken(asList, nameOfToken, "this is a test token created by a unit test", () -> {
String data = "111878";
// TO UPDATE run this in debugger mode, put a breakpoint here, and enter the OTP you get into the
// value of Data

View File

@@ -104,7 +104,8 @@ public class OkHttpConnectorTest extends AbstractGitHubWireMockTest {
OkHttpClient client = createClient(false);
OkHttpConnector connector = new OkHttpConnector(new OkUrlFactory(client));
this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()).withConnector(connector)
this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl())
.withConnector(connector)
.build();
doTestActions();
@@ -129,7 +130,8 @@ public class OkHttpConnectorTest extends AbstractGitHubWireMockTest {
OkHttpClient client = createClient(true);
OkHttpConnector connector = new OkHttpConnector(new OkUrlFactory(client), -1);
this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()).withConnector(connector)
this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl())
.withConnector(connector)
.build();
doTestActions();
@@ -159,7 +161,8 @@ public class OkHttpConnectorTest extends AbstractGitHubWireMockTest {
OkHttpClient client = createClient(true);
OkHttpConnector connector = new OkHttpConnector(new OkUrlFactory(client), 3);
this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()).withConnector(connector)
this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl())
.withConnector(connector)
.build();
doTestActions();
@@ -184,7 +187,8 @@ public class OkHttpConnectorTest extends AbstractGitHubWireMockTest {
OkHttpClient client = createClient(true);
OkHttpConnector connector = new OkHttpConnector(new OkUrlFactory(client));
this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()).withConnector(connector)
this.gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl())
.withConnector(connector)
.build();
doTestActions();
@@ -204,7 +208,8 @@ public class OkHttpConnectorTest extends AbstractGitHubWireMockTest {
assertThat("Request Count", mockGitHub.getRequestCount(), is(networkRequestCount + userRequestCount));
// Rate limit must be under this value, but if it wiggles we don't care
assertThat("Rate Limit Change", rateLimitBefore.remaining - rateLimitAfter.remaining,
assertThat("Rate Limit Change",
rateLimitBefore.remaining - rateLimitAfter.remaining,
is(lessThanOrEqualTo(rateLimitUsed + userRequestCount)));
}