Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3db7aac

Browse filesBrowse files
authored
Merge branch 'master' into AffiliationFilter
2 parents 3c56f1f + fdbbd2e commit 3db7aac
Copy full SHA for 3db7aac

File tree

Expand file treeCollapse file tree

84 files changed

+4191
-1186
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

84 files changed

+4191
-1186
lines changed

‎pom.xml

Copy file name to clipboardExpand all lines: pom.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>org.kohsuke</groupId>
44
<artifactId>github-api</artifactId>
5-
<version>1.117-SNAPSHOT</version>
5+
<version>1.118-SNAPSHOT</version>
66
<name>GitHub API for Java</name>
77
<url>https://github-api.kohsuke.org/</url>
88
<description>GitHub API for Java</description>

‎src/main/java/org/kohsuke/github/GHCheckRun.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHCheckRun.java
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.kohsuke.github;
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import edu.umd.cs.findbugs.annotations.NonNull;
45
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
56

67
import java.io.IOException;
@@ -292,4 +293,15 @@ public static enum AnnotationLevel {
292293
NOTICE, WARNING, FAILURE
293294
}
294295

296+
/**
297+
* Updates this check run.
298+
*
299+
* @return a builder which you should customize, then call {@link GHCheckRunBuilder#create}
300+
*/
301+
@Preview
302+
@Deprecated
303+
public @NonNull GHCheckRunBuilder update() {
304+
return new GHCheckRunBuilder(owner, getId());
305+
}
306+
295307
}

‎src/main/java/org/kohsuke/github/GHCheckRunBuilder.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHCheckRunBuilder.java
+25-10Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,45 @@
3737
import java.util.Locale;
3838

3939
/**
40-
* Drafts a check run.
40+
* Drafts or updates a check run.
4141
*
4242
* @see GHCheckRun
4343
* @see GHRepository#createCheckRun
4444
* @see <a href="https://developer.github.com/v3/checks/runs/#create-a-check-run">documentation</a>
45+
* @see GHCheckRun#update()
46+
* @see <a href="https://developer.github.com/v3/checks/runs/#update-a-check-run">documentation</a>
4547
*/
4648
@SuppressFBWarnings(value = "URF_UNREAD_FIELD", justification = "Jackson serializes these even without a getter")
4749
@Preview
4850
@Deprecated
4951
public final class GHCheckRunBuilder {
5052

51-
private final GHRepository repo;
52-
private final Requester requester;
53+
protected final GHRepository repo;
54+
protected final Requester requester;
5355
private Output output;
5456
private List<Action> actions;
5557

56-
GHCheckRunBuilder(GHRepository repo, String name, String headSHA) {
58+
private GHCheckRunBuilder(GHRepository repo, Requester requester) {
5759
this.repo = repo;
58-
requester = repo.root.createRequest()
59-
.withPreview(Previews.ANTIOPE)
60-
.method("POST")
61-
.with("name", name)
62-
.with("head_sha", headSHA)
63-
.withUrlPath(repo.getApiTailUrl("check-runs"));
60+
this.requester = requester;
61+
}
62+
63+
GHCheckRunBuilder(GHRepository repo, String name, String headSHA) {
64+
this(repo,
65+
repo.root.createRequest()
66+
.withPreview(Previews.ANTIOPE)
67+
.method("POST")
68+
.with("name", name)
69+
.with("head_sha", headSHA)
70+
.withUrlPath(repo.getApiTailUrl("check-runs")));
71+
}
72+
73+
GHCheckRunBuilder(GHRepository repo, long checkId) {
74+
this(repo,
75+
repo.root.createRequest()
76+
.withPreview(Previews.ANTIOPE)
77+
.method("PATCH")
78+
.withUrlPath(repo.getApiTailUrl("check-runs/" + checkId)));
6479
}
6580

6681
public @NonNull GHCheckRunBuilder withDetailsURL(@CheckForNull String detailsURL) {

‎src/main/java/org/kohsuke/github/GHEventPayload.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHEventPayload.java
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ public static class PullRequest extends GHEventPayload {
360360
private int number;
361361
private GHPullRequest pullRequest;
362362
private GHLabel label;
363+
private GHPullRequestChanges changes;
363364

364365
/**
365366
* Gets number.
@@ -389,6 +390,15 @@ public GHLabel getLabel() {
389390
return label;
390391
}
391392

393+
/**
394+
* Get changes (for action="edited")
395+
*
396+
* @return changes
397+
*/
398+
public GHPullRequestChanges getChanges() {
399+
return changes;
400+
}
401+
392402
@Override
393403
void wrapUp(GitHub root) {
394404
super.wrapUp(root);
+86Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package org.kohsuke.github;
2+
3+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4+
5+
/**
6+
* Wrapper to define changed fields on pull_request action="edited"
7+
*
8+
* @see GHEventPayload.PullRequest
9+
*/
10+
@SuppressFBWarnings("UWF_UNWRITTEN_FIELD")
11+
public class GHPullRequestChanges {
12+
13+
private GHCommitPointer base;
14+
private GHFrom title;
15+
private GHFrom body;
16+
17+
/**
18+
* Old target branch for pull request.
19+
*
20+
* @return old target branch info (or null if not changed)
21+
*/
22+
public GHCommitPointer getBase() {
23+
return base;
24+
}
25+
26+
/**
27+
* Old pull request title.
28+
*
29+
* @return old pull request title (or null if not changed)
30+
*/
31+
public GHFrom getTitle() {
32+
return title;
33+
}
34+
35+
/**
36+
* Old pull request body.
37+
*
38+
* @return old pull request body (or null if not changed)
39+
*/
40+
public GHFrom getBody() {
41+
return body;
42+
}
43+
44+
/**
45+
* @see org.kohsuke.github.GHCommitPointer
46+
*/
47+
public static class GHCommitPointer {
48+
private GHFrom ref;
49+
private GHFrom sha;
50+
51+
/**
52+
* Named ref to the commit. This (from value) appears to be a "short ref" that doesn't include "refs/heads/"
53+
* portion.
54+
*
55+
* @return the ref
56+
*/
57+
public GHFrom getRef() {
58+
return ref;
59+
}
60+
61+
/**
62+
* SHA1 of the commit.
63+
*
64+
* @return sha
65+
*/
66+
public GHFrom getSha() {
67+
return sha;
68+
}
69+
}
70+
71+
/**
72+
* Wrapper for changed values.
73+
*/
74+
public static class GHFrom {
75+
private String from;
76+
77+
/**
78+
* Previous value that was changed.
79+
*
80+
* @return previous value
81+
*/
82+
public String getFrom() {
83+
return from;
84+
}
85+
}
86+
}

‎src/main/java/org/kohsuke/github/GHRepository.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepository.java
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,6 +1995,19 @@ public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, Strin
19951995
return new GHCheckRunBuilder(this, name, headSHA);
19961996
}
19971997

1998+
/**
1999+
* Updates an existing check run.
2000+
*
2001+
* @param checkId
2002+
* the existing checkId
2003+
* @return a builder which you should customize, then call {@link GHCheckRunBuilder#create}
2004+
*/
2005+
@Preview
2006+
@Deprecated
2007+
public @NonNull GHCheckRunBuilder updateCheckRun(long checkId) {
2008+
return new GHCheckRunBuilder(this, checkId);
2009+
}
2010+
19982011
/**
19992012
* Lists repository events.
20002013
*
+77Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package org.kohsuke.github;
2+
3+
import io.jsonwebtoken.Jwts;
4+
import org.apache.commons.io.IOUtils;
5+
6+
import java.io.IOException;
7+
import java.security.KeyFactory;
8+
import java.security.PrivateKey;
9+
import java.security.spec.PKCS8EncodedKeySpec;
10+
import java.time.Instant;
11+
import java.time.temporal.ChronoUnit;
12+
import java.util.Base64;
13+
import java.util.Date;
14+
15+
public class AbstractGHAppInstallationTest extends AbstractGitHubWireMockTest {
16+
17+
private static String TEST_APP_ID_1 = "82994";
18+
private static String TEST_APP_ID_2 = "83009";
19+
private static String TEST_APP_ID_3 = "89368";
20+
private static String PRIVATE_KEY_FILE_APP_1 = "/ghapi-test-app-1.private-key.pem";
21+
private static String PRIVATE_KEY_FILE_APP_2 = "/ghapi-test-app-2.private-key.pem";
22+
private static String PRIVATE_KEY_FILE_APP_3 = "/ghapi-test-app-3.private-key.pem";
23+
24+
private String createJwtToken(String keyFileResouceName, String appId) {
25+
try {
26+
String keyPEM = IOUtils.toString(this.getClass().getResource(keyFileResouceName), "US-ASCII")
27+
.replaceAll("(?m)^--.*", "") // remove comments from PEM to allow decoding
28+
.replaceAll("\\s", "");
29+
30+
PKCS8EncodedKeySpec keySpecPKCS8 = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(keyPEM));
31+
PrivateKey privateKey = KeyFactory.getInstance("RSA").generatePrivate(keySpecPKCS8);
32+
33+
return Jwts.builder()
34+
.setIssuedAt(Date.from(Instant.now()))
35+
.setExpiration(Date.from(Instant.now().plus(5, ChronoUnit.MINUTES)))
36+
.setIssuer(appId)
37+
.signWith(privateKey)
38+
.compact();
39+
} catch (Exception e) {
40+
throw new RuntimeException("Error creating JWT token.", e);
41+
}
42+
}
43+
44+
private GHAppInstallation getAppInstallationWithToken(String jwtToken) throws IOException {
45+
GitHub gitHub = getGitHubBuilder().withJwtToken(jwtToken)
46+
.withEndpoint(mockGitHub.apiServer().baseUrl())
47+
.build();
48+
49+
GHAppInstallation appInstallation = gitHub.getApp()
50+
.listInstallations()
51+
.toList()
52+
.stream()
53+
.filter(it -> it.getAccount().login.equals("hub4j-test-org"))
54+
.findFirst()
55+
.get();
56+
57+
appInstallation
58+
.setRoot(getGitHubBuilder().withAppInstallationToken(appInstallation.createToken().create().getToken())
59+
.withEndpoint(mockGitHub.apiServer().baseUrl())
60+
.build());
61+
62+
return appInstallation;
63+
}
64+
65+
protected GHAppInstallation getAppInstallationWithTokenApp1() throws IOException {
66+
return getAppInstallationWithToken(createJwtToken(PRIVATE_KEY_FILE_APP_1, TEST_APP_ID_1));
67+
}
68+
69+
protected GHAppInstallation getAppInstallationWithTokenApp2() throws IOException {
70+
return getAppInstallationWithToken(createJwtToken(PRIVATE_KEY_FILE_APP_2, TEST_APP_ID_2));
71+
}
72+
73+
protected GHAppInstallation getAppInstallationWithTokenApp3() throws IOException {
74+
return getAppInstallationWithToken(createJwtToken(PRIVATE_KEY_FILE_APP_3, TEST_APP_ID_3));
75+
}
76+
77+
}

‎src/test/java/org/kohsuke/github/GHAppInstallationTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/GHAppInstallationTest.java
+2-63Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,11 @@
11
package org.kohsuke.github;
22

3-
import io.jsonwebtoken.Jwts;
4-
import org.apache.commons.io.IOUtils;
53
import org.junit.Test;
64

75
import java.io.IOException;
8-
import java.security.KeyFactory;
9-
import java.security.PrivateKey;
10-
import java.security.spec.PKCS8EncodedKeySpec;
11-
import java.time.Instant;
12-
import java.time.temporal.ChronoUnit;
13-
import java.util.*;
6+
import java.util.List;
147

15-
public class GHAppInstallationTest extends AbstractGitHubWireMockTest {
16-
17-
private static String TEST_APP_ID_1 = "82994";
18-
private static String TEST_APP_ID_2 = "83009";
19-
private static String PRIVATE_KEY_FILE_APP_1 = "/ghapi-test-app-1.private-key.pem";
20-
private static String PRIVATE_KEY_FILE_APP_2 = "/ghapi-test-app-2.private-key.pem";
21-
22-
private String createJwtToken(String keyFileResouceName, String appId) {
23-
try {
24-
String keyPEM = IOUtils.toString(this.getClass().getResource(keyFileResouceName), "US-ASCII")
25-
.replaceAll("(?m)^--.*", "") // remove comments from PEM to allow decoding
26-
.replaceAll("\\s", "");
27-
28-
PKCS8EncodedKeySpec keySpecPKCS8 = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(keyPEM));
29-
PrivateKey privateKey = KeyFactory.getInstance("RSA").generatePrivate(keySpecPKCS8);
30-
31-
return Jwts.builder()
32-
.setIssuedAt(Date.from(Instant.now()))
33-
.setExpiration(Date.from(Instant.now().plus(5, ChronoUnit.MINUTES)))
34-
.setIssuer(appId)
35-
.signWith(privateKey)
36-
.compact();
37-
} catch (Exception e) {
38-
throw new RuntimeException("Error creating JWT token.", e);
39-
}
40-
}
41-
42-
private GHAppInstallation getAppInstallationWithToken(String jwtToken) throws IOException {
43-
GitHub gitHub = getGitHubBuilder().withJwtToken(jwtToken)
44-
.withEndpoint(mockGitHub.apiServer().baseUrl())
45-
.build();
46-
47-
GHAppInstallation appInstallation = gitHub.getApp()
48-
.listInstallations()
49-
.toList()
50-
.stream()
51-
.filter(it -> it.getAccount().login.equals("hub4j-test-org"))
52-
.findFirst()
53-
.get();
54-
55-
appInstallation
56-
.setRoot(getGitHubBuilder().withAppInstallationToken(appInstallation.createToken().create().getToken())
57-
.withEndpoint(mockGitHub.apiServer().baseUrl())
58-
.build());
59-
60-
return appInstallation;
61-
}
62-
63-
private GHAppInstallation getAppInstallationWithTokenApp1() throws IOException {
64-
return getAppInstallationWithToken(createJwtToken(PRIVATE_KEY_FILE_APP_1, TEST_APP_ID_1));
65-
}
66-
67-
private GHAppInstallation getAppInstallationWithTokenApp2() throws IOException {
68-
return getAppInstallationWithToken(createJwtToken(PRIVATE_KEY_FILE_APP_2, TEST_APP_ID_2));
69-
}
8+
public class GHAppInstallationTest extends AbstractGHAppInstallationTest {
709

7110
@Test
7211
public void testListRepositoriesTwoRepos() throws IOException {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.