Skip to content

Commit

Permalink
Merge branch 'main' into public-keys-maddymanu
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Jun 21, 2022
2 parents b1e2222 + 38918c4 commit 1fa164c
Show file tree
Hide file tree
Showing 22 changed files with 1,526 additions and 21 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Expand Up @@ -46,7 +46,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -57,7 +57,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -71,4 +71,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
4 changes: 2 additions & 2 deletions .github/workflows/maven-build.yml
Expand Up @@ -74,15 +74,15 @@ jobs:
- name: Maven Install with Code Coverage
run: mvn -B clean install -D enable-ci -Djapicmp.skip --file pom.xml
- name: Codecov Report
uses: codecov/codecov-action@v3.0.0
uses: codecov/codecov-action@v3.1.0
test:
name: test (${{ matrix.os }}, Java ${{ matrix.java }})
runs-on: ${{ matrix.os }}-latest
strategy:
fail-fast: false
matrix:
os: [ ubuntu, windows ]
java: [ 11.0.3, 11, 17 ]
java: [ 11, 17 ]
steps:
- uses: actions/checkout@v3
- name: Set up JDK
Expand Down
14 changes: 7 additions & 7 deletions pom.xml
Expand Up @@ -44,7 +44,7 @@
<jacoco.coverage.target.class.method>0.50</jacoco.coverage.target.class.method>
<!-- For non-ci builds we'd like the build to still complete if jacoco metrics aren't met. -->
<jacoco.haltOnFailure>false</jacoco.haltOnFailure>
<jjwt.suite.version>0.11.2</jjwt.suite.version>
<jjwt.suite.version>0.11.5</jjwt.suite.version>

<jacoco.surefire.argLine />
<surefire.argLine />
Expand All @@ -55,12 +55,12 @@
<extension>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-gitexe</artifactId>
<version>1.12.2</version>
<version>1.13.0</version>
</extension>
<extension>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-manager-plexus</artifactId>
<version>1.12.2</version>
<version>1.13.0</version>
</extension>
<!-- Doing site publishing manually for now -->
<!--
Expand Down Expand Up @@ -278,7 +278,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.2.2</version>
<version>3.3.0</version>
<dependencies>
<dependency>
<groupId>org.apache.bcel</groupId>
Expand Down Expand Up @@ -333,7 +333,7 @@
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.22.1</version>
<version>2.22.5</version>
<executions>
<execution>
<id>spotless-check</id>
Expand Down Expand Up @@ -468,7 +468,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.2.2</version>
<version>2.13.3</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
Expand Down Expand Up @@ -567,7 +567,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.5.1</version>
<version>4.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/org/kohsuke/github/GHEventPayload.java
Expand Up @@ -1506,6 +1506,43 @@ void lateBind() {
}
}

/**
* A workflow job has been queued, is in progress, or has been completed.
*
* @see <a href=
* "https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_job">
* workflow job event</a>
* @see <a href="https://docs.github.com/en/rest/reference/actions#workflow-jobs">Actions Workflow Jobs</a>
*/
public static class WorkflowJob extends GHEventPayload {

private GHWorkflowJob workflowJob;

/**
* Gets the workflow job.
*
* @return the workflow job
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected")
public GHWorkflowJob getWorkflowJob() {
return workflowJob;
}

@Override
void lateBind() {
if (workflowJob == null) {
throw new IllegalStateException(
"Expected workflow_job payload, but got something else. Maybe we've got another type of event?");
}
super.lateBind();
GHRepository repository = getRepository();
if (repository == null) {
throw new IllegalStateException("Repository must not be null");
}
workflowJob.wrapUp(repository);
}
}

/**
* A label was created, edited or deleted.
*
Expand Down Expand Up @@ -1572,4 +1609,25 @@ public GHLabel getLabel() {
return label;
}
}

/**
* A star was created or deleted on a repository.
*
* @see <a href=
* "https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#star">star
* event</a>
*/
public static class Star extends GHEventPayload {

private String starredAt;

/**
* Gets the date when the star is added. Is null when the star is deleted.
*
* @return the date when the star is added
*/
public Date getStarredAt() {
return GitHubClient.parseDate(starredAt);
}
}
}
11 changes: 10 additions & 1 deletion src/main/java/org/kohsuke/github/GHRepository.java
Expand Up @@ -94,7 +94,7 @@ public class GHRepository extends GHObject {

private GHUser owner; // not fully populated. beware.

private boolean has_issues, has_wiki, fork, has_downloads, has_pages, archived, has_projects;
private boolean has_issues, has_wiki, fork, has_downloads, has_pages, archived, disabled, has_projects;

private boolean allow_squash_merge;

Expand Down Expand Up @@ -660,6 +660,15 @@ public boolean isArchived() {
return archived;
}

/**
* Is disabled boolean.
*
* @return the boolean
*/
public boolean isDisabled() {
return disabled;
}

/**
* Is allow squash merge boolean.
*
Expand Down
68 changes: 67 additions & 1 deletion src/main/java/org/kohsuke/github/GHWorkflowJob.java
Expand Up @@ -9,7 +9,11 @@

import java.io.IOException;
import java.net.URL;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Objects;

import static java.util.Objects.requireNonNull;

Expand All @@ -35,12 +39,20 @@ public class GHWorkflowJob extends GHObject {
private String conclusion;

private long runId;
private int runAttempt;

private String htmlUrl;
private String checkRunUrl;

private int runnerId;
private String runnerName;
private int runnerGroupId;
private String runnerGroupName;

private List<Step> steps = new ArrayList<>();

private List<String> labels = new ArrayList<>();

/**
* The name of the job.
*
Expand Down Expand Up @@ -108,6 +120,15 @@ public long getRunId() {
return runId;
}

/**
* Attempt number of the associated workflow run, 1 for first attempt and higher if the workflow was re-run.
*
* @return attempt number
*/
public int getRunAttempt() {
return runAttempt;
}

@Override
public URL getHtmlUrl() {
return GitHubClient.parseURL(htmlUrl);
Expand All @@ -131,6 +152,51 @@ public List<Step> getSteps() {
return Collections.unmodifiableList(steps);
}

/**
* Gets the labels of the job.
*
* @return the labels
*/
public List<String> getLabels() {
return Collections.unmodifiableList(labels);
}

/**
* the runner id.
*
* @return runnerId
*/
public int getRunnerId() {
return runnerId;
}

/**
* the runner name.
*
* @return runnerName
*/
public String getRunnerName() {
return runnerName;
}

/**
* the runner group id.
*
* @return runnerGroupId
*/
public int getRunnerGroupId() {
return runnerGroupId;
}

/**
* the runner group name.
*
* @return runnerGroupName
*/
public String getRunnerGroupName() {
return runnerGroupName;
}

/**
* Repository to which the job belongs.
*
Expand Down
59 changes: 57 additions & 2 deletions src/test/java/org/kohsuke/github/GHEventPayloadTest.java
Expand Up @@ -11,7 +11,18 @@
import java.util.List;
import java.util.TimeZone;

import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.aMapWithSize;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.hasToString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.sameInstance;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertThrows;

public class GHEventPayloadTest extends AbstractGitHubWireMockTest {
Expand Down Expand Up @@ -876,7 +887,6 @@ public void workflow_run_pull_request() throws Exception {
GHPullRequest pullRequest = pullRequests.get(0);
assertThat(pullRequest.getId(), is(599098265L));
assertThat(pullRequest.getRepository(), sameInstance(workflowRunPayload.getRepository()));

}

@Test
Expand All @@ -892,6 +902,40 @@ public void workflow_run_other_repository() throws Exception {
assertThat(workflowRunPayload.getWorkflow().getRepository(), sameInstance(workflowRunPayload.getRepository()));
}

@Test
public void workflow_job() throws Exception {
final GHEventPayload.WorkflowJob workflowJobPayload = GitHub.offline()
.parseEventPayload(payload.asReader(), GHEventPayload.WorkflowJob.class);

assertThat(workflowJobPayload.getAction(), is("completed"));
assertThat(workflowJobPayload.getRepository().getFullName(), is("gsmet/quarkus-bot-java-playground"));
assertThat(workflowJobPayload.getSender().getLogin(), is("gsmet"));

GHWorkflowJob workflowJob = workflowJobPayload.getWorkflowJob();
assertThat(workflowJob.getId(), is(6653410527L));
assertThat(workflowJob.getRunId(), is(2408553341L));
assertThat(workflowJob.getRunAttempt(), is(1));
assertThat(workflowJob.getUrl().toString(),
is("https://api.github.com/repos/gsmet/quarkus-bot-java-playground/actions/jobs/6653410527"));
assertThat(workflowJob.getHtmlUrl().toString(),
is("https://github.com/gsmet/quarkus-bot-java-playground/runs/6653410527?check_suite_focus=true"));
assertThat(workflowJob.getNodeId(), is("CR_kwDOEq3cwc8AAAABjJL83w"));
assertThat(workflowJob.getHeadSha(), is("5dd2dadfbdc2a722c08a8ad42ae4e26e3e731042"));
assertThat(workflowJob.getStatus(), is(GHWorkflowRun.Status.COMPLETED));
assertThat(workflowJob.getConclusion(), is(GHWorkflowRun.Conclusion.FAILURE));
assertThat(workflowJob.getStartedAt().getTime(), is(1653908125000L));
assertThat(workflowJob.getCompletedAt().getTime(), is(1653908157000L));
assertThat(workflowJob.getName(), is("JVM Tests - JDK JDK16"));
assertThat(workflowJob.getSteps(),
contains(hasProperty("name", is("Set up job")),
hasProperty("name", is("Run actions/checkout@v2")),
hasProperty("name", is("Build with Maven")),
hasProperty("name", is("Post Run actions/checkout@v2")),
hasProperty("name", is("Complete job"))));
assertThat(workflowJob.getCheckRunUrl().toString(),
is("https://api.github.com/repos/gsmet/quarkus-bot-java-playground/check-runs/6653410527"));
}

@Test
public void label_created() throws Exception {
final GHEventPayload.Label labelPayload = GitHub.offline()
Expand Down Expand Up @@ -1097,4 +1141,15 @@ public void discussion_labeled() throws Exception {
assertThat(label.isDefault(), is(false));
assertThat(label.getDescription(), is(nullValue()));
}

@Test
public void starred() throws Exception {
final GHEventPayload.Star starPayload = GitHub.offline()
.parseEventPayload(payload.asReader(), GHEventPayload.Star.class);

assertThat(starPayload.getAction(), is("created"));
assertThat(starPayload.getRepository().getFullName(), is("gsmet/quarkus-bot-java-playground"));
assertThat(starPayload.getSender().getLogin(), is("gsmet"));
assertThat(starPayload.getStarredAt().getTime(), is(1654017876000L));
}
}

0 comments on commit 1fa164c

Please sign in to comment.