Skip to content

Commit b355091

Browse files
committed
Enable part of AppTest in CI
1 parent d096aa2 commit b355091

230 files changed

Lines changed: 17246 additions & 2998 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ public GitHubBuilder() {
3636
}
3737

3838
/**
39-
* First check if the credentials are configured using the ~/.github properties file.
40-
*
41-
* If no user is specified it means there is no configuration present so check the environment instead.
39+
* First check if the credentials are configured in the environment.
40+
* We use environment first because users are not likely to give required (full) permissions to their default key.
4241
*
42+
* If no user is specified it means there is no configuration present, so try using the ~/.github properties file.
43+
**
4344
* If there is still no user it means there are no credentials defined and throw an IOException.
4445
*
4546
* @return the configured Builder from credentials defined on the system or in the environment. Otherwise returns null.
@@ -50,6 +51,11 @@ static GitHubBuilder fromCredentials() throws IOException {
5051
Exception cause = null;
5152
GitHubBuilder builder = null;
5253

54+
builder = fromEnvironment();
55+
56+
if (builder.oauthToken != null || builder.user != null)
57+
return builder;
58+
5359
try {
5460
builder = fromPropertyFile();
5561

@@ -59,13 +65,7 @@ static GitHubBuilder fromCredentials() throws IOException {
5965
// fall through
6066
cause = e;
6167
}
62-
63-
builder = fromEnvironment();
64-
65-
if (builder.oauthToken != null || builder.user != null)
66-
return builder;
67-
else
68-
throw (IOException)new IOException("Failed to resolve credentials from ~/.github or the environment.").initCause(cause);
68+
throw (IOException)new IOException("Failed to resolve credentials from ~/.github or the environment.").initCause(cause);
6969
}
7070

7171
/**

src/test/java/org/kohsuke/HookApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static void main(String[] args) throws Exception {
2626
public void doIndex(StaplerRequest req) throws IOException {
2727
String str = req.getParameter("payload");
2828
System.out.println(str);
29-
GHEventPayload.PullRequest o = GitHub.connect().parseEventPayload(new StringReader(str),GHEventPayload.PullRequest.class);
29+
GHEventPayload.PullRequest o = GitHub.connect().parseEventPayload(new StringReader(str), GHEventPayload.PullRequest.class);
3030
System.out.println(o);
3131
}
3232
}

src/test/java/org/kohsuke/github/AbstractGitHubApiTestBase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.FileInputStream;
44
import java.util.Properties;
5+
56
import org.apache.commons.io.IOUtils;
67
import org.junit.Assert;
78
import org.junit.Assume;
@@ -20,7 +21,7 @@ public abstract class AbstractGitHubApiTestBase extends AbstractGitHubApiWireMoc
2021

2122
@Before
2223
public void setUp() throws Exception {
23-
assumeTrue( "All tests inheriting from this class are not guaranteed to work without proxy", githubApi.isUseProxy());
24+
assumeTrue("All tests inheriting from this class are not guaranteed to work without proxy", githubApi.isUseProxy());
2425
}
2526

2627
protected GHUser getUser() {

src/test/java/org/kohsuke/github/AbstractGitHubApiWireMockTest.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import static com.github.tomakehurst.wiremock.client.WireMock.*;
2525
import static org.junit.Assume.assumeFalse;
26+
import static org.junit.Assume.assumeTrue;
2627

2728
/**
2829
* @author Liam Newman
@@ -67,7 +68,9 @@ protected WireMockConfiguration getWireMockOptions() {
6768
return WireMockConfiguration.options()
6869
.dynamicPort()
6970
.usingFilesUnderDirectory(baseRecordPath);
70-
};
71+
}
72+
73+
;
7174

7275

7376
private static GitHubBuilder createGitHubBuilder() {
@@ -89,6 +92,9 @@ private static GitHubBuilder createGitHubBuilder() {
8992
// to clutter their event stream.
9093
builder = GitHubBuilder.fromProperties(props);
9194
} else {
95+
96+
builder = GitHubBuilder.fromEnvironment();
97+
9298
builder = GitHubBuilder.fromCredentials();
9399
}
94100
} catch (IOException e) {
@@ -133,4 +139,25 @@ protected void snapshotNotAllowed() {
133139
assumeFalse("Test contains hand written mappings. Only valid when not taking a snapshot.", githubApi.isTakeSnapshot());
134140
}
135141

142+
protected GHUser getUser() {
143+
return getUser(gitHub);
144+
}
145+
146+
protected static GHUser getUser(GitHub gitHub) {
147+
try {
148+
return gitHub.getMyself();
149+
} catch (IOException e) {
150+
throw new RuntimeException(e.getMessage(), e);
151+
}
152+
}
153+
154+
protected void kohsuke() {
155+
// No-op for now
156+
// Generally this means the test is doing something that requires additional access rights
157+
// Not always clear which ones.
158+
// TODO: Add helpers that assert the expected rights using gitHubBeforeAfter and only when proxy is enabled
159+
// String login = getUserTest().getLogin();
160+
// assumeTrue(login.equals("kohsuke") || login.equals("kohsuke2"));
161+
}
162+
136163
}

0 commit comments

Comments
 (0)