Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions GitGitGadget/github-api-request-as-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const gitHubAPIRequestAsApp = async (context, requestMethod, requestPath, body)
body,
{
Authorization: `Bearer ${token}`,
'X-GitHub-Api-Version': '2026-03-10',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is only used in two places but could it be environment controlled? An env var could set the supported api version without a code change. Would that require more changes when a level set is needed?

Since the api change has been addressed, is version locking needed? Should we wait for the next break given the api usage is so basic?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it would be a good idea to have this controlled by the environment because any API version change will require code changes. For example, the return_run_details attribute to trigger workflow dispatches. That is no longer supported by this new API version. So if we just allow the API version to be overridden, the code might have wrong assumptions about what it can and cannot do.

}
)
}
Expand Down
5 changes: 4 additions & 1 deletion GitGitGadget/github-api-request.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion GitGitGadget/https-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion GitGitGadget/trigger-workflow-dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions __tests__/https-request.test.js
Original file line number Diff line number Diff line change
@@ -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()
}
})
8 changes: 3 additions & 5 deletions __tests__/trigger-workflow-dispatch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
})
})

Expand All @@ -79,13 +78,12 @@ 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 }
})
})

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)
})
})
Loading