diff --git a/GitGitGadget/github-api-request-as-app.js b/GitGitGadget/github-api-request-as-app.js index df055c3..e3fa845 100644 --- a/GitGitGadget/github-api-request-as-app.js +++ b/GitGitGadget/github-api-request-as-app.js @@ -38,6 +38,7 @@ const gitHubAPIRequestAsApp = async (context, requestMethod, requestPath, body) body, { Authorization: `Bearer ${token}`, + 'X-GitHub-Api-Version': '2026-03-10', } ) } diff --git a/GitGitGadget/github-api-request.js b/GitGitGadget/github-api-request.js index 24f26e1..495a15c 100644 --- a/GitGitGadget/github-api-request.js +++ b/GitGitGadget/github-api-request.js @@ -1,6 +1,9 @@ const gitHubAPIRequest = async (context, token, method, requestPath, payload) => { const { httpsRequest } = require('./https-request') - const headers = token ? { Authorization: `Bearer ${token}` } : null + const headers = { + 'X-GitHub-Api-Version': '2026-03-10', + ...(token ? { Authorization: `Bearer ${token}` } : {}), + } const answer = await httpsRequest(context, null, method, requestPath, payload, headers) if (answer.error) throw answer.error return answer diff --git a/GitGitGadget/https-request.js b/GitGitGadget/https-request.js index f8094fc..876828c 100644 --- a/GitGitGadget/https-request.js +++ b/GitGitGadget/https-request.js @@ -9,7 +9,7 @@ const httpsRequest = async (context, hostname, method, requestPath, body, header if (body) { if (typeof body === 'object') body = JSON.stringify(body) headers['Content-Type'] = 'application/json' - headers['Content-Length'] = body.length + headers['Content-Length'] = Buffer.byteLength(body, 'utf8') } const options = { port: 443, diff --git a/GitGitGadget/trigger-workflow-dispatch.js b/GitGitGadget/trigger-workflow-dispatch.js index 6a023c5..0d2a74a 100644 --- a/GitGitGadget/trigger-workflow-dispatch.js +++ b/GitGitGadget/trigger-workflow-dispatch.js @@ -49,7 +49,7 @@ const triggerWorkflowDispatch = async (context, token, owner, repo, workflow_id, token, 'POST', `/repos/${owner}/${repo}/actions/workflows/${workflow_id}/dispatches`, - { ref, inputs, return_run_details: true } + { ref, inputs } ) if (response.workflow_run_id) return response diff --git a/__tests__/https-request.test.js b/__tests__/https-request.test.js new file mode 100644 index 0000000..e8f52bf --- /dev/null +++ b/__tests__/https-request.test.js @@ -0,0 +1,21 @@ +const https = require('https') +const { httpsRequest } = require('../GitGitGadget/https-request') + +test('send UTF-8 JSON with the correct byte length', async () => { + const request = { on: jest.fn(), write: jest.fn(), end: jest.fn() } + const mockRequest = jest.spyOn(https, 'request') + mockRequest.mockImplementation((_options, callback) => { + callback({ statusCode: 204, headers: {}, on: jest.fn() }) + return request + }) + const body = { ref: 'main', inputs: { message: 'Windows\u2019 launchers' } } + + try { + await httpsRequest({}, null, 'POST', '/dispatches', body) + expect(request.write).toHaveBeenCalledWith(JSON.stringify(body)) + expect(mockRequest.mock.calls[0][0].headers['Content-Length']) + .toBe(Buffer.from(request.write.mock.calls[0][0], 'utf8').length) + } finally { + mockRequest.mockRestore() + } +}) diff --git a/__tests__/trigger-workflow-dispatch.test.js b/__tests__/trigger-workflow-dispatch.test.js index 66ce0e4..5029f85 100644 --- a/__tests__/trigger-workflow-dispatch.test.js +++ b/__tests__/trigger-workflow-dispatch.test.js @@ -65,8 +65,7 @@ test('use workflow run details returned by the dispatch', async () => { expect(mockHTTPSRequest).toHaveBeenCalledTimes(1) expect(mockHTTPSRequest.mock.calls[0][4]).toEqual({ ref: 'HEAD', - inputs: { abc: 123 }, - return_run_details: true + inputs: { abc: 123 } }) }) @@ -79,8 +78,7 @@ test('fall back to waiting for the workflow run', async () => { }) expect(mockHTTPSRequest.mock.calls[0][4]).toEqual({ ref: 'HEAD', - inputs: { abc: 123 }, - return_run_details: true + inputs: { abc: 123 } }) }) @@ -88,4 +86,4 @@ test('list workflow runs', async () => { const context = {} const runs = await listWorkflowRuns(context, 'my-token', 'hello', 'world', 'the-workflow.yml', 'main', 'queued') expect(runs.length).toEqual(2) -}) \ No newline at end of file +})