Skip to content

Commit 2ee0bcc

Browse files
authored
Merge branch 'main' into main
2 parents cf715ec + ee450b6 commit 2ee0bcc

File tree

113 files changed

+43262
-35
lines changed

Some content is hidden

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

113 files changed

+43262
-35
lines changed

.github/workflows/maven-build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
env:
3636
MAVEN_OPTS: ${{ env.JAVA_11_PLUS_MAVEN_OPTS }}
3737
run: mvn -B clean install -DskipTests --file pom.xml
38-
- uses: actions/upload-artifact@v3
38+
- uses: actions/upload-artifact@v4
3939
with:
4040
name: maven-target-directory
4141
path: target/
@@ -86,15 +86,15 @@ jobs:
8686
run: mvn -B clean install -D enable-ci --file pom.xml "-Dsurefire.argLine=--add-opens java.base/java.net=ALL-UNNAMED"
8787
- name: Codecov Report
8888
if: matrix.os == 'ubuntu' && matrix.java == '17'
89-
uses: codecov/codecov-action@v3.1.4
89+
uses: codecov/codecov-action@v4.1.0
9090

9191
test-java-8:
9292
name: test Java 8 (no-build)
9393
needs: build
9494
runs-on: ubuntu-latest
9595
steps:
9696
- uses: actions/checkout@v4
97-
- uses: actions/download-artifact@v3
97+
- uses: actions/download-artifact@v4
9898
with:
9999
name: maven-target-directory
100100
path: target

.github/workflows/publish_release_branch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
MAVEN_OPTS: ${{ env.JAVA_11_PLUS_MAVEN_OPTS }}
3030
run: mvn -B clean install site -D enable-ci --file pom.xml "-Dsurefire.argLine=--add-opens java.base/java.net=ALL-UNNAMED"
3131

32-
- uses: actions/upload-artifact@v3
32+
- uses: actions/upload-artifact@v4
3333
with:
3434
name: maven-target-directory
3535
path: target/

.github/workflows/release-drafter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- name: Release Drafter
20-
uses: release-drafter/release-drafter@v5
20+
uses: release-drafter/release-drafter@v6
2121
env:
2222
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

pom.xml

Lines changed: 4 additions & 4 deletions
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.319-SNAPSHOT</version>
5+
<version>1.320-SNAPSHOT</version>
66
<name>GitHub API for Java</name>
77
<url>https://github-api.kohsuke.org/</url>
88
<description>GitHub API for Java</description>
@@ -38,7 +38,7 @@
3838
<spotbugs-maven-plugin.failOnError>true</spotbugs-maven-plugin.failOnError>
3939
<hamcrest.version>2.2</hamcrest.version>
4040
<okhttp3.version>4.9.2</okhttp3.version>
41-
<okio.version>3.5.0</okio.version>
41+
<okio.version>3.7.0</okio.version>
4242
<!-- Using this as the minimum bar for code coverage. Adding methods without covering them will fail this. -->
4343
<jacoco.coverage.target.bundle.method>0.70</jacoco.coverage.target.bundle.method>
4444
<jacoco.coverage.target.class.method>0.50</jacoco.coverage.target.class.method>
@@ -296,7 +296,7 @@
296296
<dependency>
297297
<groupId>org.apache.bcel</groupId>
298298
<artifactId>bcel</artifactId>
299-
<version>6.8.0</version>
299+
<version>6.8.2</version>
300300
</dependency>
301301
</dependencies>
302302
</plugin>
@@ -379,7 +379,7 @@
379379
<plugin>
380380
<groupId>com.diffplug.spotless</groupId>
381381
<artifactId>spotless-maven-plugin</artifactId>
382-
<version>2.27.2</version>
382+
<version>2.43.0</version>
383383
<executions>
384384
<execution>
385385
<id>spotless-check</id>

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,23 @@ private GHCheckRunBuilder(GHRepository repo, Requester requester) {
102102
.withUrlPath(repo.getApiTailUrl("check-runs/" + checkId)));
103103
}
104104

105+
/**
106+
* With name.
107+
*
108+
* @param name
109+
* the name
110+
* @param oldName
111+
* the old name
112+
* @return the GH check run builder
113+
*/
114+
public @NonNull GHCheckRunBuilder withName(@CheckForNull String name, String oldName) {
115+
if (oldName == null) {
116+
throw new GHException("Can not update uncreated check run");
117+
}
118+
requester.with("name", name);
119+
return this;
120+
}
121+
105122
/**
106123
* With details URL.
107124
*

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
2828
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2929
import org.apache.commons.lang3.StringUtils;
30+
import org.kohsuke.github.internal.EnumUtils;
3031

3132
import java.io.IOException;
3233
import java.net.URL;
@@ -35,8 +36,10 @@
3536
import java.util.Collection;
3637
import java.util.Collections;
3738
import java.util.Date;
39+
import java.util.HashMap;
3840
import java.util.List;
3941
import java.util.Locale;
42+
import java.util.Map;
4043
import java.util.Objects;
4144

4245
import static org.kohsuke.github.internal.Previews.SQUIRREL_GIRL;
@@ -67,6 +70,9 @@ public class GHIssue extends GHObject implements Reactable {
6770
/** The state. */
6871
protected String state;
6972

73+
/** The state reason. */
74+
protected String state_reason;
75+
7076
/** The number. */
7177
protected int number;
7278

@@ -198,6 +204,15 @@ public GHIssueState getState() {
198204
return Enum.valueOf(GHIssueState.class, state.toUpperCase(Locale.ENGLISH));
199205
}
200206

207+
/**
208+
* Gets state reason.
209+
*
210+
* @return the state reason
211+
*/
212+
public GHIssueStateReason getStateReason() {
213+
return EnumUtils.getNullableEnumOrDefault(GHIssueStateReason.class, state_reason, GHIssueStateReason.UNKNOWN);
214+
}
215+
201216
/**
202217
* Gets labels.
203218
*
@@ -273,6 +288,10 @@ private void edit(String key, Object value) throws IOException {
273288
root().createRequest().with(key, value).method("PATCH").withUrlPath(getApiRoute()).send();
274289
}
275290

291+
private void edit(Map<String, Object> map) throws IOException {
292+
root().createRequest().with(map).method("PATCH").withUrlPath(getApiRoute()).send();
293+
}
294+
276295
/**
277296
* Identical to edit(), but allows null for the value.
278297
*/
@@ -294,6 +313,21 @@ public void close() throws IOException {
294313
edit("state", "closed");
295314
}
296315

316+
/**
317+
* Closes this issue.
318+
*
319+
* @param reason
320+
* the reason the issue was closed
321+
* @throws IOException
322+
* the io exception
323+
*/
324+
public void close(GHIssueStateReason reason) throws IOException {
325+
Map<String, Object> map = new HashMap<>();
326+
map.put("state", "closed");
327+
map.put("state_reason", reason.name().toLowerCase(Locale.ENGLISH));
328+
edit(map);
329+
}
330+
297331
/**
298332
* Reopens this issue.
299333
*
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.kohsuke.github;
2+
3+
/**
4+
* The enum GHIssueStateReason.
5+
*/
6+
public enum GHIssueStateReason {
7+
8+
/** Completed **/
9+
COMPLETED,
10+
11+
/** Closed as not planned **/
12+
NOT_PLANNED,
13+
14+
/** Uknown **/
15+
UNKNOWN
16+
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ protected String getApiRoute() {
100100
if (owner == null) {
101101
// Issues returned from search to do not have an owner. Attempt to use url.
102102
final URL url = Objects.requireNonNull(getUrl(), "Missing instance URL!");
103-
return StringUtils.prependIfMissing(url.toString().replace(root().getApiUrl(), ""), "/");
103+
// The url sourced above is of the form '/repos/<owner>/<reponame>/issues/', which
104+
// subsequently issues requests against the `/issues/` handler, causing a 404 when
105+
// asking for, say, a list of commits associated with a PR. Replace the `/issues/`
106+
// with `/pulls/` to avoid that.
107+
return StringUtils.prependIfMissing(url.toString().replace(root().getApiUrl(), ""), "/")
108+
.replace("/issues/", "/pulls/");
104109
}
105110
return "/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/pulls/" + number;
106111
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,10 @@ public GHAsset uploadAsset(String filename, InputStream stream, String contentTy
274274
Requester builder = owner.root().createRequest().method("POST");
275275
String url = getUploadUrl();
276276
// strip the helpful garbage from the url
277-
url = url.substring(0, url.indexOf('{'));
277+
int endIndex = url.indexOf('{');
278+
if (endIndex != -1) {
279+
url = url.substring(0, endIndex);
280+
}
278281
url += "?name=" + URLEncoder.encode(filename, "UTF-8");
279282
return builder.contentType(contentType).with(stream).withUrlPath(url).fetch(GHAsset.class).wrap(this);
280283
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1508,7 +1508,7 @@ public void delete() throws IOException {
15081508
} catch (FileNotFoundException x) {
15091509
throw (FileNotFoundException) new FileNotFoundException("Failed to delete " + getOwnerName() + "/" + name
15101510
+ "; might not exist, or you might need the delete_repo scope in your token: http://stackoverflow.com/a/19327004/12916")
1511-
.initCause(x);
1511+
.initCause(x);
15121512
}
15131513
}
15141514

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,34 @@ public GHWorkflowRunQueryBuilder conclusion(Conclusion conclusion) {
110110
return this;
111111
}
112112

113+
/**
114+
* Created workflow run query builder.
115+
*
116+
* @param created
117+
* a range following the Query for dates syntax
118+
*
119+
* @return the gh workflow run query builder
120+
* @see <a href=
121+
* "https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax#query-for-dates">Query
122+
* for dates</a>
123+
*/
124+
public GHWorkflowRunQueryBuilder created(String created) {
125+
req.with("created", created);
126+
return this;
127+
}
128+
129+
/**
130+
* Head sha workflow run query builder.
131+
*
132+
* @param headSha
133+
* the head sha
134+
* @return the gh workflow run query builder
135+
*/
136+
public GHWorkflowRunQueryBuilder headSha(String headSha) {
137+
req.with("head_sha", headSha);
138+
return this;
139+
}
140+
113141
/**
114142
* List.
115143
*

src/main/java/org/kohsuke/github/authorization/AuthorizationProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public interface AuthorizationProvider {
2323
*
2424
* <pre>
2525
* {@code
26-
* &#64;Override
27-
* public String getEncodedAuthorization() {
28-
* return "Bearer myBearerToken";
29-
* }
26+
* &#64;Override
27+
* public String getEncodedAuthorization() {
28+
* return "Bearer myBearerToken";
29+
* }
3030
* }
3131
* </pre>
3232
*

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

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
package org.kohsuke.github;
2626

27+
import org.junit.Assert;
2728
import org.junit.Test;
2829
import org.kohsuke.github.GHCheckRun.Status;
2930

@@ -73,7 +74,7 @@ public void createCheckRun() throws Exception {
7374
"hello to you too").withTitle("Look here"))
7475
.add(new GHCheckRunBuilder.Image("Unikitty",
7576
"https://i.pinimg.com/474x/9e/65/c0/9e65c0972294f1e10f648c9780a79fab.jpg")
76-
.withCaption("Princess Unikitty")))
77+
.withCaption("Princess Unikitty")))
7778
.add(new GHCheckRunBuilder.Action("Help", "what I need help with", "doit"))
7879
.create();
7980
assertThat(checkRun.getStatus(), equalTo(Status.COMPLETED));
@@ -195,4 +196,60 @@ public void updateCheckRun() throws Exception {
195196
assertThat(checkRun.getOutput().getAnnotationsCount(), equalTo(1));
196197
}
197198

199+
/**
200+
* Update check run with name.
201+
*
202+
* @throws Exception
203+
* the exception
204+
*/
205+
@Test
206+
public void updateCheckRunWithName() throws Exception {
207+
GHCheckRun checkRun = getInstallationGithub().getRepository("hub4j-test-org/test-checks")
208+
.createCheckRun("foo", "89a9ae301e35e667756034fdc933b1fc94f63fc1")
209+
.withStatus(GHCheckRun.Status.IN_PROGRESS)
210+
.withStartedAt(new Date(999_999_000))
211+
.add(new GHCheckRunBuilder.Output("Some Title", "what happened…")
212+
.add(new GHCheckRunBuilder.Annotation("stuff.txt",
213+
1,
214+
GHCheckRun.AnnotationLevel.NOTICE,
215+
"hello to you too").withTitle("Look here")))
216+
.create();
217+
GHCheckRun updated = checkRun.update()
218+
.withStatus(GHCheckRun.Status.COMPLETED)
219+
.withConclusion(GHCheckRun.Conclusion.SUCCESS)
220+
.withCompletedAt(new Date(999_999_999))
221+
.withName("bar", checkRun.getName())
222+
.create();
223+
assertThat(new Date(999_999_000), equalTo(updated.getStartedAt()));
224+
assertThat("bar", equalTo(updated.getName()));
225+
assertThat(checkRun.getOutput().getAnnotationsCount(), equalTo(1));
226+
}
227+
228+
/**
229+
* Update the check run with name exception.
230+
*
231+
* @throws Exception
232+
* the exception
233+
*/
234+
@Test
235+
public void updateCheckRunWithNameException() throws Exception {
236+
snapshotNotAllowed();
237+
GHCheckRun checkRun = getInstallationGithub().getRepository("hub4j-test-org/test-checks")
238+
.createCheckRun("foo", "89a9ae301e35e667756034fdc933b1fc94f63fc1")
239+
.withStatus(GHCheckRun.Status.IN_PROGRESS)
240+
.withStartedAt(new Date(999_999_000))
241+
.add(new GHCheckRunBuilder.Output("Some Title", "what happened…")
242+
.add(new GHCheckRunBuilder.Annotation("stuff.txt",
243+
1,
244+
GHCheckRun.AnnotationLevel.NOTICE,
245+
"hello to you too").withTitle("Look here")))
246+
.create();
247+
Assert.assertThrows(GHException.class,
248+
() -> checkRun.update()
249+
.withStatus(GHCheckRun.Status.COMPLETED)
250+
.withConclusion(GHCheckRun.Conclusion.SUCCESS)
251+
.withCompletedAt(new Date(999_999_999))
252+
.withName("bar", null)
253+
.create());
254+
}
198255
}

0 commit comments

Comments
 (0)