mirror of
https://github.com/jlengrand/github-api.git
synced 2026-04-05 00:11:22 +00:00
Enable automatic code formatter with CI validation
This may be controversial but it we're doing it. Having code formatting needs to be consistent and a non-issue during code review. I'm willing modify the configuration if people see a strong need, but formatting needs to be present and enforced.
This commit is contained in:
@@ -33,15 +33,13 @@ public abstract class AbstractGitHubWireMockTest extends Assert {
|
||||
protected final Set<String> tempGitHubRepositories = new HashSet<>();
|
||||
|
||||
/**
|
||||
* {@link GitHub} instance for use during test.
|
||||
* Traffic will be part of snapshot when taken.
|
||||
* {@link GitHub} instance for use during test. Traffic will be part of snapshot when taken.
|
||||
*/
|
||||
protected GitHub gitHub;
|
||||
|
||||
/**
|
||||
* {@link GitHub} instance for use before/after test.
|
||||
* Traffic will not be part of snapshot when taken.
|
||||
* Should only be used when isUseProxy() or isTakeSnapShot().
|
||||
* {@link GitHub} instance for use before/after test. Traffic will not be part of snapshot when taken. Should only
|
||||
* be used when isUseProxy() or isTakeSnapShot().
|
||||
*/
|
||||
protected GitHub gitHubBeforeAfter;
|
||||
|
||||
@@ -52,15 +50,11 @@ public abstract class AbstractGitHubWireMockTest extends Assert {
|
||||
public final GitHubWireMockRule mockGitHub;
|
||||
|
||||
public AbstractGitHubWireMockTest() {
|
||||
mockGitHub = new GitHubWireMockRule(
|
||||
this.getWireMockOptions()
|
||||
);
|
||||
mockGitHub = new GitHubWireMockRule(this.getWireMockOptions());
|
||||
}
|
||||
|
||||
protected WireMockConfiguration getWireMockOptions() {
|
||||
return WireMockConfiguration.options()
|
||||
.dynamicPort()
|
||||
.usingFilesUnderDirectory(baseRecordPath);
|
||||
return WireMockConfiguration.options().dynamicPort().usingFilesUnderDirectory(baseRecordPath);
|
||||
}
|
||||
|
||||
private static GitHubBuilder createGitHubBuilder() {
|
||||
@@ -109,29 +103,27 @@ public abstract class AbstractGitHubWireMockTest extends Assert {
|
||||
|
||||
@Before
|
||||
public void wireMockSetup() throws Exception {
|
||||
GitHubBuilder builder = getGitHubBuilder()
|
||||
.withEndpoint(mockGitHub.apiServer().baseUrl());
|
||||
GitHubBuilder builder = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl());
|
||||
|
||||
if (useDefaultGitHub) {
|
||||
gitHub = builder
|
||||
.build();
|
||||
gitHub = builder.build();
|
||||
}
|
||||
|
||||
if (mockGitHub.isUseProxy()) {
|
||||
gitHubBeforeAfter = getGitHubBuilder()
|
||||
.withEndpoint("https://api.github.com/")
|
||||
.build();
|
||||
gitHubBeforeAfter = getGitHubBuilder().withEndpoint("https://api.github.com/").build();
|
||||
} else {
|
||||
gitHubBeforeAfter = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void snapshotNotAllowed() {
|
||||
assumeFalse("Test contains hand written mappings. Only valid when not taking a snapshot.", mockGitHub.isTakeSnapshot());
|
||||
assumeFalse("Test contains hand written mappings. Only valid when not taking a snapshot.",
|
||||
mockGitHub.isTakeSnapshot());
|
||||
}
|
||||
|
||||
protected void requireProxy(String reason) {
|
||||
assumeTrue("Test only valid when proxying (-Dtest.github.useProxy to enable): " + reason, mockGitHub.isUseProxy());
|
||||
assumeTrue("Test only valid when proxying (-Dtest.github.useProxy to enable): " + reason,
|
||||
mockGitHub.isUseProxy());
|
||||
}
|
||||
|
||||
protected GHUser getUser() {
|
||||
@@ -149,7 +141,7 @@ public abstract class AbstractGitHubWireMockTest extends Assert {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected GHRepository getTempRepository() throws IOException{
|
||||
protected GHRepository getTempRepository() throws IOException {
|
||||
return getTempRepository("temp-" + this.mockGitHub.getMethodName());
|
||||
}
|
||||
|
||||
@@ -157,16 +149,13 @@ public abstract class AbstractGitHubWireMockTest extends Assert {
|
||||
* Creates
|
||||
*/
|
||||
protected GHRepository getTempRepository(String name) throws IOException {
|
||||
String fullName = GITHUB_API_TEST_ORG +'/' + name;
|
||||
String fullName = GITHUB_API_TEST_ORG + '/' + name;
|
||||
if (mockGitHub.isUseProxy()) {
|
||||
cleanupRepository(fullName);
|
||||
|
||||
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();
|
||||
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();
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
} catch (InterruptedException e) {
|
||||
@@ -189,7 +178,7 @@ public abstract class AbstractGitHubWireMockTest extends Assert {
|
||||
@After
|
||||
public void cleanupTempRepositories() throws IOException {
|
||||
if (mockGitHub.isUseProxy()) {
|
||||
for(String fullName : tempGitHubRepositories) {
|
||||
for (String fullName : tempGitHubRepositories) {
|
||||
cleanupRepository(fullName);
|
||||
}
|
||||
}
|
||||
@@ -215,8 +204,8 @@ public abstract class AbstractGitHubWireMockTest extends Assert {
|
||||
// Generally this means the test is doing something that requires additional access rights
|
||||
// Not always clear which ones.
|
||||
// TODO: Add helpers that assert the expected rights using gitHubBeforeAfter and only when proxy is enabled
|
||||
// String login = getUserTest().getLogin();
|
||||
// assumeTrue(login.equals("kohsuke") || login.equals("kohsuke2"));
|
||||
// String login = getUserTest().getLogin();
|
||||
// assumeTrue(login.equals("kohsuke") || login.equals("kohsuke2"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user