Skip to content

Commit b275e07

Browse files
authored
Merge pull request #371 from Codex-/fix_deprecated_api_warning
Fix deprecated api warning
2 parents aae7fff + 0702fd4 commit b275e07

5 files changed

Lines changed: 679 additions & 335 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ One of the following, depending on the token type:
5555

5656
- [Create a workflow dispatch event](https://docs.github.com/en/rest/actions/workflows#create-a-workflow-dispatch-event)
5757
- POST `/repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches`
58-
- Sent with `return_run_details: true`, so the response carries the new run's ID and URL
58+
- Sent with `X-GitHub-Api-Version: 2026-03-10`, so the response carries the new run's ID and URL
5959
- Requires github.com or GitHub Enterprise Server 3.21+, older servers cannot return the run details
6060

6161
For more information please see [api.ts](./src/api.ts).

dist/index.mjs

Lines changed: 586 additions & 265 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-lock.yaml

Lines changed: 57 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api.spec.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,16 @@ describe("API", () => {
100100
url: "https://github.com/owner/repo/actions/runs/123456",
101101
});
102102

103-
// The run details are opt-in, so the request must ask for them
104-
expect(dispatchedRequest?.return_run_details).toStrictEqual(true);
105-
// Only the caller's inputs are forwarded, nothing is injected
106-
expect(dispatchedRequest?.inputs).toStrictEqual({ testInput: "test" });
103+
// Only the pinned API version returns the run details, and only the
104+
// caller's inputs are forwarded
105+
expect(dispatchedRequest).toStrictEqual({
106+
owner: "owner",
107+
repo: "repo",
108+
workflow_id: "workflow",
109+
ref: "ref",
110+
inputs: { testInput: "test" },
111+
headers: { "x-github-api-version": "2026-03-10" },
112+
});
107113

108114
// Logging
109115
assertOnlyCalled(coreInfoLogMock);
@@ -119,7 +125,7 @@ describe("API", () => {
119125
`);
120126
});
121127

122-
it("should throw for an empty 204, as returned by servers without return_run_details support", async () => {
128+
it("should throw for an empty 204, as returned by servers that ignore the API version", async () => {
123129
vi.spyOn(
124130
mockOctokit.rest.actions,
125131
"createWorkflowDispatch",
@@ -147,11 +153,13 @@ describe("API", () => {
147153
);
148154
});
149155

150-
it("should restate the server requirement for a 400 rejecting the unknown field", async () => {
151-
// Servers predating `return_run_details` reject it outright rather than
152-
// ignoring it, so the empty 204 path is never reached.
156+
it("should restate the server requirement for a 400 rejecting the API version", async () => {
157+
// Servers predating the pinned version reject it outright rather than
158+
// falling back, so the empty 204 path is never reached.
153159
const requestError = Object.assign(
154-
new Error('Unknown request body field: "return_run_details"'),
160+
new Error(
161+
'The version you specified in the "X-GitHub-API-Version" request header, "2026-03-10", is not a supported version.',
162+
),
155163
{ status: 400 },
156164
);
157165
vi.spyOn(
@@ -165,7 +173,7 @@ describe("API", () => {
165173
);
166174
// The original message is retained for diagnosis
167175
await expect(dispatchWorkflow()).rejects.toThrow(
168-
'Unknown request body field: "return_run_details"',
176+
"is not a supported version",
169177
);
170178

171179
// Logging

src/api.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,20 @@ export function init(cfg?: ActionConfig): void {
1414
}
1515

1616
/**
17-
* The 200 response body of the workflow dispatch endpoint, returned when
18-
* `return_run_details` is requested.
17+
* The version that returns the created run. The default `2022-11-28` answers
18+
* 204 with no body and reports the endpoint as deprecated on every request.
1919
*
20-
* Declared locally because `@octokit/openapi-types` still describes this
21-
* endpoint as 204-only, so the response shape cannot be taken from the types
22-
* and is validated at runtime instead.
20+
* Served by github.com and GHES 3.21 or newer.
21+
*
22+
* See: https://docs.github.com/en/rest/about-the-rest-api/api-versions
23+
*/
24+
const API_VERSION = "2026-03-10";
25+
26+
/**
27+
* The 200 response body of the workflow dispatch endpoint.
28+
*
29+
* Declared locally because `@octokit/openapi-types` still types this endpoint
30+
* as 204-only, so the shape is validated at runtime instead.
2331
*
2432
* See: https://docs.github.com/en/rest/actions/workflows#create-a-workflow-dispatch-event--status-codes
2533
*/
@@ -55,14 +63,12 @@ const RUN_DETAILS_UNSUPPORTED =
5563
"Dispatch did not return the run details, this action requires github.com or GHES >=3.21";
5664

5765
/**
58-
* Servers predating `return_run_details` reject the unknown field with a 400
59-
* rather than ignoring it, so the empty 204 path is never reached on them.
60-
* Restate the requirement, keeping the original message for diagnosis.
66+
* Servers without `API_VERSION` reject the request with a 400 rather than
67+
* falling back, so the empty 204 path is never reached on them. Restate the
68+
* requirement, keeping the original message for diagnosis.
6169
*
6270
* Matching on the status alone is deliberate. The 400 message shape is
6371
* undocumented and may differ between GHES versions.
64-
*
65-
* https://github.com/cli/cli/issues/12672
6672
*/
6773
function asUnsupportedRunDetailsError(error: unknown): Error | undefined {
6874
if (!(error instanceof Error) || !("status" in error)) {
@@ -93,10 +99,7 @@ export async function dispatchWorkflow(): Promise<DispatchedWorkflowRun> {
9399
workflow_id: config.workflow,
94100
ref: config.ref,
95101
inputs: config.workflowInputs,
96-
// The docs omit `return_run_details`. It is specified only in the OpenAPI
97-
// description, which is what conditions the 200 and 204 responses on it.
98-
// see: https://github.com/github/rest-api-description/tree/main/descriptions/api.github.com
99-
return_run_details: true,
102+
headers: { "x-github-api-version": API_VERSION },
100103
});
101104

102105
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition

0 commit comments

Comments
 (0)