Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman authored Mar 8, 2024
2 parents cf715ec + ee450b6 commit 2ee0bcc
Show file tree
Hide file tree
Showing 113 changed files with 43,262 additions and 35 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
env:
MAVEN_OPTS: ${{ env.JAVA_11_PLUS_MAVEN_OPTS }}
run: mvn -B clean install -DskipTests --file pom.xml
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: maven-target-directory
path: target/
Expand Down Expand Up @@ -86,15 +86,15 @@ jobs:
run: mvn -B clean install -D enable-ci --file pom.xml "-Dsurefire.argLine=--add-opens java.base/java.net=ALL-UNNAMED"
- name: Codecov Report
if: matrix.os == 'ubuntu' && matrix.java == '17'
uses: codecov/codecov-action@v3.1.4
uses: codecov/codecov-action@v4.1.0

test-java-8:
name: test Java 8 (no-build)
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: maven-target-directory
path: target
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_release_branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
MAVEN_OPTS: ${{ env.JAVA_11_PLUS_MAVEN_OPTS }}
run: mvn -B clean install site -D enable-ci --file pom.xml "-Dsurefire.argLine=--add-opens java.base/java.net=ALL-UNNAMED"

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: maven-target-directory
path: target/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Release Drafter
uses: release-drafter/release-drafter@v5
uses: release-drafter/release-drafter@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.kohsuke</groupId>
<artifactId>github-api</artifactId>
<version>1.319-SNAPSHOT</version>
<version>1.320-SNAPSHOT</version>
<name>GitHub API for Java</name>
<url>https://github-api.kohsuke.org/</url>
<description>GitHub API for Java</description>
Expand Down Expand Up @@ -38,7 +38,7 @@
<spotbugs-maven-plugin.failOnError>true</spotbugs-maven-plugin.failOnError>
<hamcrest.version>2.2</hamcrest.version>
<okhttp3.version>4.9.2</okhttp3.version>
<okio.version>3.5.0</okio.version>
<okio.version>3.7.0</okio.version>
<!-- Using this as the minimum bar for code coverage. Adding methods without covering them will fail this. -->
<jacoco.coverage.target.bundle.method>0.70</jacoco.coverage.target.bundle.method>
<jacoco.coverage.target.class.method>0.50</jacoco.coverage.target.class.method>
Expand Down Expand Up @@ -296,7 +296,7 @@
<dependency>
<groupId>org.apache.bcel</groupId>
<artifactId>bcel</artifactId>
<version>6.8.0</version>
<version>6.8.2</version>
</dependency>
</dependencies>
</plugin>
Expand Down Expand Up @@ -379,7 +379,7 @@
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.27.2</version>
<version>2.43.0</version>
<executions>
<execution>
<id>spotless-check</id>
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/org/kohsuke/github/GHCheckRunBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,23 @@ private GHCheckRunBuilder(GHRepository repo, Requester requester) {
.withUrlPath(repo.getApiTailUrl("check-runs/" + checkId)));
}

/**
* With name.
*
* @param name
* the name
* @param oldName
* the old name
* @return the GH check run builder
*/
public @NonNull GHCheckRunBuilder withName(@CheckForNull String name, String oldName) {
if (oldName == null) {
throw new GHException("Can not update uncreated check run");
}
requester.with("name", name);
return this;
}

/**
* With details URL.
*
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/org/kohsuke/github/GHIssue.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.lang3.StringUtils;
import org.kohsuke.github.internal.EnumUtils;

import java.io.IOException;
import java.net.URL;
Expand All @@ -35,8 +36,10 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

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

/** The state reason. */
protected String state_reason;

/** The number. */
protected int number;

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

/**
* Gets state reason.
*
* @return the state reason
*/
public GHIssueStateReason getStateReason() {
return EnumUtils.getNullableEnumOrDefault(GHIssueStateReason.class, state_reason, GHIssueStateReason.UNKNOWN);
}

/**
* Gets labels.
*
Expand Down Expand Up @@ -273,6 +288,10 @@ private void edit(String key, Object value) throws IOException {
root().createRequest().with(key, value).method("PATCH").withUrlPath(getApiRoute()).send();
}

private void edit(Map<String, Object> map) throws IOException {
root().createRequest().with(map).method("PATCH").withUrlPath(getApiRoute()).send();
}

/**
* Identical to edit(), but allows null for the value.
*/
Expand All @@ -294,6 +313,21 @@ public void close() throws IOException {
edit("state", "closed");
}

/**
* Closes this issue.
*
* @param reason
* the reason the issue was closed
* @throws IOException
* the io exception
*/
public void close(GHIssueStateReason reason) throws IOException {
Map<String, Object> map = new HashMap<>();
map.put("state", "closed");
map.put("state_reason", reason.name().toLowerCase(Locale.ENGLISH));
edit(map);
}

/**
* Reopens this issue.
*
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/kohsuke/github/GHIssueStateReason.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.kohsuke.github;

/**
* The enum GHIssueStateReason.
*/
public enum GHIssueStateReason {

/** Completed **/
COMPLETED,

/** Closed as not planned **/
NOT_PLANNED,

/** Uknown **/
UNKNOWN
}
7 changes: 6 additions & 1 deletion src/main/java/org/kohsuke/github/GHPullRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ protected String getApiRoute() {
if (owner == null) {
// Issues returned from search to do not have an owner. Attempt to use url.
final URL url = Objects.requireNonNull(getUrl(), "Missing instance URL!");
return StringUtils.prependIfMissing(url.toString().replace(root().getApiUrl(), ""), "/");
// The url sourced above is of the form '/repos/<owner>/<reponame>/issues/', which
// subsequently issues requests against the `/issues/` handler, causing a 404 when
// asking for, say, a list of commits associated with a PR. Replace the `/issues/`
// with `/pulls/` to avoid that.
return StringUtils.prependIfMissing(url.toString().replace(root().getApiUrl(), ""), "/")
.replace("/issues/", "/pulls/");
}
return "/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/pulls/" + number;
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/kohsuke/github/GHRelease.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ public GHAsset uploadAsset(String filename, InputStream stream, String contentTy
Requester builder = owner.root().createRequest().method("POST");
String url = getUploadUrl();
// strip the helpful garbage from the url
url = url.substring(0, url.indexOf('{'));
int endIndex = url.indexOf('{');
if (endIndex != -1) {
url = url.substring(0, endIndex);
}
url += "?name=" + URLEncoder.encode(filename, "UTF-8");
return builder.contentType(contentType).with(stream).withUrlPath(url).fetch(GHAsset.class).wrap(this);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@ public void delete() throws IOException {
} catch (FileNotFoundException x) {
throw (FileNotFoundException) new FileNotFoundException("Failed to delete " + getOwnerName() + "/" + name
+ "; might not exist, or you might need the delete_repo scope in your token: http://stackoverflow.com/a/19327004/12916")
.initCause(x);
.initCause(x);
}
}

Expand Down
28 changes: 28 additions & 0 deletions src/main/java/org/kohsuke/github/GHWorkflowRunQueryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,34 @@ public GHWorkflowRunQueryBuilder conclusion(Conclusion conclusion) {
return this;
}

/**
* Created workflow run query builder.
*
* @param created
* a range following the Query for dates syntax
*
* @return the gh workflow run query builder
* @see <a href=
* "https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax#query-for-dates">Query
* for dates</a>
*/
public GHWorkflowRunQueryBuilder created(String created) {
req.with("created", created);
return this;
}

/**
* Head sha workflow run query builder.
*
* @param headSha
* the head sha
* @return the gh workflow run query builder
*/
public GHWorkflowRunQueryBuilder headSha(String headSha) {
req.with("head_sha", headSha);
return this;
}

/**
* List.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public interface AuthorizationProvider {
*
* <pre>
* {@code
* &#64;Override
* public String getEncodedAuthorization() {
* return "Bearer myBearerToken";
* }
* &#64;Override
* public String getEncodedAuthorization() {
* return "Bearer myBearerToken";
* }
* }
* </pre>
*
Expand Down
59 changes: 58 additions & 1 deletion src/test/java/org/kohsuke/github/GHCheckRunBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package org.kohsuke.github;

import org.junit.Assert;
import org.junit.Test;
import org.kohsuke.github.GHCheckRun.Status;

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

/**
* Update check run with name.
*
* @throws Exception
* the exception
*/
@Test
public void updateCheckRunWithName() throws Exception {
GHCheckRun checkRun = getInstallationGithub().getRepository("hub4j-test-org/test-checks")
.createCheckRun("foo", "89a9ae301e35e667756034fdc933b1fc94f63fc1")
.withStatus(GHCheckRun.Status.IN_PROGRESS)
.withStartedAt(new Date(999_999_000))
.add(new GHCheckRunBuilder.Output("Some Title", "what happened…")
.add(new GHCheckRunBuilder.Annotation("stuff.txt",
1,
GHCheckRun.AnnotationLevel.NOTICE,
"hello to you too").withTitle("Look here")))
.create();
GHCheckRun updated = checkRun.update()
.withStatus(GHCheckRun.Status.COMPLETED)
.withConclusion(GHCheckRun.Conclusion.SUCCESS)
.withCompletedAt(new Date(999_999_999))
.withName("bar", checkRun.getName())
.create();
assertThat(new Date(999_999_000), equalTo(updated.getStartedAt()));
assertThat("bar", equalTo(updated.getName()));
assertThat(checkRun.getOutput().getAnnotationsCount(), equalTo(1));
}

/**
* Update the check run with name exception.
*
* @throws Exception
* the exception
*/
@Test
public void updateCheckRunWithNameException() throws Exception {
snapshotNotAllowed();
GHCheckRun checkRun = getInstallationGithub().getRepository("hub4j-test-org/test-checks")
.createCheckRun("foo", "89a9ae301e35e667756034fdc933b1fc94f63fc1")
.withStatus(GHCheckRun.Status.IN_PROGRESS)
.withStartedAt(new Date(999_999_000))
.add(new GHCheckRunBuilder.Output("Some Title", "what happened…")
.add(new GHCheckRunBuilder.Annotation("stuff.txt",
1,
GHCheckRun.AnnotationLevel.NOTICE,
"hello to you too").withTitle("Look here")))
.create();
Assert.assertThrows(GHException.class,
() -> checkRun.update()
.withStatus(GHCheckRun.Status.COMPLETED)
.withConclusion(GHCheckRun.Conclusion.SUCCESS)
.withCompletedAt(new Date(999_999_999))
.withName("bar", null)
.create());
}
}
Loading

0 comments on commit 2ee0bcc

Please sign in to comment.