GHWorkflow.dispatch does not throw an exception on a 422 HTTP status
Describe the bug
I’ve been tracing the code to see why my application apparently succeeds in sending a workflow dispatch request yet the workflow never starts. Eventually I found that after sending a POST request to /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches (no body, because I had passed null as the ref), GitHub responds with error 422 Unprocessable Entity. GitHubClient isn’t throwing an exception for this code; instead, the GitHubClient.sendRequest method returns a GitHubResponse,Requester.fetchHttpStatusCode returns 422, and GHWorkflow.dispatch ignores it, so my application thinks the request succeeded when it actually failed.
To Reproduce Steps to reproduce the behavior:
// authToken, organization, repository, and workflowId are set;
// branch = null; inputs = Collections.emptyMap();
GHWorkflow workflow = getConnection(authToken).getRepository(
String.format("%s/%s", organization, repository))
.getWorkflow(workflowId);
workflow.dispatch(branch, Optional.ofNullable(inputs)
.orElse(Collections.emptyMap()));
Expected behavior
The method should either have thrown a GHIOException (or appropriate subclass for HTTP status 422), or should see that branch is null and throw an IllegalArgumentException.
Desktop (please complete the following information):
- OS: MacOS 11.4
- Java: 1.8.0_162
- github-api Version: 1.133
- okhttp Version: 4.9.2
Additional context
Per https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event, a ref parameter in the request body is required.
@Typraeurion
The problem is in the dispatch method as you would expect:
https://github.com/hub4j/github-api/blob/a28a726b9c78b007a2b45e60a1bc73a6a3bf1804/src/main/java/org/kohsuke/github/GHWorkflow.java#L126-L136
Either than method should throw when it gets null for the ref, or the last line should be changed to call send() instead of fetchStatusCode().