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

Implement workflow job event payload #1331

Copy link
Copy link
Closed
@Typraeurion

Description

@Typraeurion
Issue body actions

Describe the bug
#1316 added WORKFLOW_JOB to the GHEvent enum, but receiving workflow_job events is still not fully supported because it can’t be mapped to any GHEventPayload subclass. An attempt to map it to the GHEventPayload superclass results in:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of org.kohsuke.github.GHEventPayload (no Creators, like default constructor, exist)

I’ve captured the request body for a workflow_job event in order to check its structure, and it looks like implementing this is very straightforward. I used the WorkflowRun subclass as a model.

diff --git a/src/main/java/org/kohsuke/github/GHEventPayload.java b/src/main/java/org/kohsuke/github/GHEventPayload.java
index 4d47264aa..ca3b75036 100644
--- a/src/main/java/org/kohsuke/github/GHEventPayload.java
+++ b/src/main/java/org/kohsuke/github/GHEventPayload.java
@@ -1446,6 +1446,42 @@ public abstract class GHEventPayload extends GitHubInteractiveObject {
         }
     }
 
+    /**
+     * 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.
      *

I’ve tested this locally by posting a copy of the workflow_job event to my application’s webhook endpoint, where the application is doing:

        Class<? extends GHEventPayload> eventClass;
        switch (eventName.toLowerCase()) {

            …

            case "workflow_job":
                eventClass = GHEventPayload.WorkflowJob.class; break;

            default:
                throw new UnsupportedOperationException(
                        "Event \"" + eventName + "\" is not handled");

        }

        GHEventPayload eventPayload = GitHub.offline().parseEventPayload(
                new StringReader(payload), eventClass);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

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